#include <CoreAPI.h>
public:
AutoExport() {
TexRes = 4;
DesiredPolycount = 40000;
Enumerator* E = ENUM.Get("EXPPRESETS");
expPreset = E->Get("PBR+EXR-displacement");
ReductionPercent = 80;
DecimateFromAllVolumes = false;
pDecimateFromAllVolumes = false;
CurrentPolycount = vol.getPolycount();
EachVolumeToSeparateAsset = false;
ScanDepthPercent = 1.0;
CenterEachAssetAroundBoundBox = false;
EachAssetToOwnFolder = false;
DropToBlender = false;
UE5_optimized = false;
RegularExport = true;
SkipFilenamePreffix = true;
}
int TexRes;
int DesiredPolycount;
int expPreset;
float ReductionPercent;
int CurrentPolycount;
bool DecimateFromAllVolumes;
bool pDecimateFromAllVolumes;
bool EachVolumeToSeparateAsset;
bool CenterEachAssetAroundBoundBox;
bool EachAssetToOwnFolder;
float ScanDepthPercent;
bool DropToBlender;
bool UE5_optimized;
bool RegularExport;
bool SkipFilenamePreffix;
SERIALIZE() {
Enumerator* E = ENUM.Get("EXSIZE");
if (E->GetAmount() == 0) {
E->Add("#256x256");
E->Add("#512x512");
E->Add("#1024x1024");
E->Add("#2048x2048");
E->Add("#4096x4096");
E->Add("#8192x8192");
}
CHK_GROUP(1) REG_AUTO(RegularExport);
CHK_GROUP(1) REG_AUTO(DropToBlender);
CHK_GROUP(1) REG_AUTO(UE5_optimized);
DELIMITER;
REG_AUTO(EachVolumeToSeparateAsset);
REG_AUTO(CenterEachAssetAroundBoundBox);
if (!EachVolumeToSeparateAsset) {
REG_AUTO(DecimateFromAllVolumes);
}
else {
REG_AUTO(EachAssetToOwnFolder);
if (!EachAssetToOwnFolder) {
REG_AUTO(SkipFilenamePreffix);
}
}
if(UE5_optimized) {
FILEPATH(exportMesh, "exportMesh", "save:*.usdz,*.usd")
} else
if (DropToBlender) {
FILEPATH(exportMesh, "exportMesh", "save:*.fbx");
}
else {
FILEPATH(exportMesh, "exportMesh", meshes.ToCharPtr());
}
FILEPATH(texturesExportPath, "texturesExportPath", "folder");
REG_DROPLIST(TexRes, "TexRes", "EXSIZE");
if (RegularExport) {
REG_DROPLIST(expPreset, "expPreset", "EXPPRESETS");
}
DELIMITER;
REG_AUTO(CurrentPolycount, "^CurrentPolycount");
FSLIDER(ReductionPercent, "ReductionPercent", 0, 99, 1, false);
UI_LAYOUT("[] 6");
TEXTMSG2("{maticon arrow_forward}");
REG_AUTO(DesiredPolycount, "ReducedPolycount");
FSLIDER(ScanDepthPercent, "ScanDepthPercent", 0.01, 100, 1, 0);
}
if (CurrentPolycount > 0) {
ReductionPercent = 100.0f - DesiredPolycount * 100.0f / CurrentPolycount;
}
if (DecimateFromAllVolumes != pDecimateFromAllVolumes) {
pDecimateFromAllVolumes = DecimateFromAllVolumes;
if (DecimateFromAllVolumes) {
CurrentPolycount = 0;
root.iterateVisibleSubtree(
CurrentPolycount += e.Volume().getPolycount();
return false;
});
}
else {
CurrentPolycount = vol.getPolycount();
}
}
return false;
}
if(strstr(MembName, "ReductionPercent")) {
DesiredPolycount = CurrentPolycount * (100.0 - ReductionPercent) / 100.0;
}
return false;
}
};
void RemovePaintObjects() {
for (int k = 0; k < 10; k++) {
[&] {
})) {
}
}
}
EXPORT_COMMAND(DecimateAutoMapExport) {
AutoExport se;
se.ReadFromFile("UserPrefs/CoreAPI/auto_export.json");
}
if (
coat::dialog().ok().cancel().text(
"SimpSculptExportHint").caption(
"SimpSculptExportHintCap").params(&se).show() == 1) {
if (
coat::dialog().ok().cancel().text(
"RunBakeScriptInfo").caption(
"SimpSculptExportHintCap").dontShowAgainCheckbox().show() <= 1) {
if (se.DropToBlender) {
}
if (se.UE5_optimized) {
Enumerator* E = ENUM.Get("EXPPRESETS");
se.expPreset = E->Get("USD (PBR Standard)");
}
se.WriteToFile("UserPrefs/CoreAPI/auto_export.json");
auto_keep(se.DecimateFromAllVolumes);
if (se.EachVolumeToSeparateAsset) {
se.DecimateFromAllVolumes = false;
[&](auto el) -> bool {
volumes.Add(el.Volume());
return false;
});
}
else {
}
for (int i = 0; i < volumes.Count(); i++) {
auto vol = volumes[i];
if (se.EachVolumeToSeparateAsset)vol.inScene().selectOne();
comms::cBounds ab;
ab.SetEmpty();
if (!se.DecimateFromAllVolumes) {
ab = vol.calcWorldSpaceAABB();
}
else {
[&](auto el) -> bool {
ab.AddBounds(el.Volume().calcWorldSpaceAABB());
return false;
});
}
if (se.CenterEachAssetAroundBoundBox) {
if (!se.DecimateFromAllVolumes) {
vol.inScene().transform_single(t);
}
else {
[&](auto el) -> bool {
el.transform_single(t);
return false;
});
}
}
};
transform(coat::mat4::Translation(-center));
float d = ab.GetDiagonal() * se.ScanDepthPercent / 100.0;
int cp = vol.getPolycount();
if (cp > 0) {
float per = 100.0f - se.DesiredPolycount * 100.0f / float(cp);
if (per > 100.0f)per = 99.0f;
if (per < 0.0f)per = 0.0f;
Enumerator* E = ENUM.Get("EXPPRESETS");
RemovePaintObjects();
coat::ui::cmd(se.DecimateFromAllVolumes ?
"$DecimateAllToRetopo" :
"$DecimateToRetopo",
[&] {
coat::ui::setSliderValue("$DecimationParams::ReductionPercent", per);
coat::ui::cmd("$DialogButton#1");
});
coat::str texSize = coat::str::ToString(256 << se.TexRes);
});
if (se.EachVolumeToSeparateAsset) {
name.RemoveFileExtension();
if (se.EachAssetToOwnFolder) {
name += "/";
name += vol.inScene().name();
name += "/";
name += vol.inScene().name();
name += ".";
name += ext;
}
else {
if(se.SkipFilenamePreffix) {
name.RemoveFileName();
name.EnsureTrailingSlash();
} else name += "_";
name += vol.inScene().name();
name += ".";
name += ext;
}
}
if(se.UE5_optimized) {
cStr ext = name.
GetFileExtension();
if (ext.
IndexOf(
"usd") == -1) {
name.
RemoveFileExtension();
name += ".usdz";
}
}
if (se.DropToBlender) {
name.RemoveFileExtension();
name += ".fbx";
[&] {
});
}
else {
}
});
}
RemovePaintObjects();
}
transform(coat::mat4::Translation(center));
}
}
}
};
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition: BaseClass.h:90
virtual bool ProcessInEditor(BaseClass *Parent)
Editor will call next function always when it is visible in tree. Return true if overriden.
Definition: BaseClass.h:324
virtual bool OnChangeMember(BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
Editor will call it every time when member changes and editor is able to recognise it.
Definition: BaseClass.h:336
The scene element, like sculpt object or curve.
Definition: CoreAPI.h:380
bool iterateVisibleSubtree(const std::function< bool(SceneElement)> &fn) const
iterate over the visible subtree
static SceneElement current()
returns the current sculpt object
static SceneElement sculptRoot()
get the root of all sculpt objects
the rich dialog. You may customize it, show your custom parameters and custom buttons.
Definition: CoreAPI.h:1305
static bool & fadeDialogsBackground()
returns the reference to the global property - fade modal dialogs background (true) or not (false)
static void step(int count=1)
perform rendering cycles
static bool fileExists(const char *path)
check if file exists
static const char * supportedMeshesFormats()
returns the list of supported images formats
static bool setBoolValue(const char *id, bool value)
Set the value for the checkbox in UI.
static void toRoom(const char *name)
switch to the room
static void setFileForFileDialog(const char *filename)
Set the file for the next file dialog that will be triggered by user. If you will use coat::ui:cmd(....
static bool getBoolField(const char *id)
Get the bool field from the checkbox in UI.
static bool cmd(const char *id, std::function< void()> process_in_modal_dialog=0)
perform some command in UI.
static void hideDontShowAgainMessage(const char *id)
Hides the "Don't show again dialog" for the current session (not forever)
static bool setOption(const char *id, const char *value)
set the value to preferences
static bool setEditBoxValue(const char *id, const char *value)
set the edit box value
comms::cVec3 vec3
3D - float vector, see the cVec3
Definition: CoreAPI.h:16
comms::cMat4 mat4
4x4 float matrix, see the cMat4
Definition: CoreAPI.h:22
comms::cStr str
the string that is compatible with the 3DCoat engine, see the cStr
Definition: CoreAPI.h:28
comms::cList< X > list
the array template, see cList
Definition: CoreAPI.h:31