5static string ColorToHexString(
Color color)
7 const string hexChars =
"0123456789abcdef";
9 int value = color.PackToInt();
11 string hexString =
"#";
13 for (
int i = 7; i >= 0; i--) {
14 int hexDigit = (value >> i * 4) & 0xF;
15 hexString += hexChars[hexDigit];
22static Color HexStringToColor(
string hexString)
24 const string hexChars =
"0123456789abcdef";
26 int lookupTable[128] = {0};
28 for (
int i =
"0".ToAscii(); i <=
"9".ToAscii(); i++)
30 lookupTable[i] = i -
"0".ToAscii();
33 for (
int i =
"a".ToAscii(); i <=
"f".ToAscii(); i++)
35 lookupTable[i] = 10 + (i -
"a".ToAscii());
41 hexString = hexString.Substring(1, 8);
43 for (
int i = 0; i < 8; i++)
45 int c = hexString[i].ToAscii();
46 packedInt = (packedInt << 4) | lookupTable[c];
49 return Color.FromInt(packedInt);
57 ref map<string, int> intParams =
new map<string, int>;
58 ref map<string, float> floatParams =
new map<string, float>;
59 ref map<string, bool> boolParams =
new map<string, bool>;
60 ref map<string, Color> colorParams =
new map<string, Color>;
61 ref map<string, string> stringParams =
new map<string, string>;
63 void BlenderOperatorDescription(
string _moduleName =
"",
string _blIDName =
"")
65 moduleName = _moduleName;
69 void AddParam(
string paramName,
int value) { intParams.Insert(paramName, value); }
70 void AddParam(
string paramName,
float value) { floatParams.Insert(paramName, value); }
71 void AddParam(
string paramName,
bool value) { boolParams.Insert(paramName, value); }
72 void AddParam(
string paramName, Color value) { colorParams.Insert(paramName, value); }
73 void AddParam(
string paramName,
string value) { stringParams.Insert(paramName, value); }
77 StoreString(
"module_name", moduleName);
78 StoreString(
"bl_idname", blIDName);
80 StartObject(
"parameters");
82 foreach(
string paramName,
int value : intParams)
84 StoreInteger(paramName, value);
86 foreach(
string paramName,
float value : floatParams)
88 StoreFloat(paramName, value);
90 foreach(
string paramName,
bool value : boolParams)
92 StoreBoolean(paramName, value);
94 foreach(
string paramName, Color value : colorParams)
96 StoreString(paramName, ColorToHexString(value));
98 foreach(
string paramName,
string value : stringParams)
100 StoreString(paramName, value);
107static void StartBlenderWithOperator(BlenderOperatorDescription operatorDescription,
bool runInBackground =
false)
109 string pathToExecutable;
110 if (!EBTConfigPlugin.GetDefaultBlenderPath(pathToExecutable))
113 operatorDescription.Pack();
115 string runInBackgroundCommand =
"";
119 runInBackgroundCommand =
" \"-b\"";
123 string jsonString = operatorDescription.AsString();
125 jsonString.Replace(
"\"",
"\\*");
126 jsonString.Replace(
"*",
"\"");
128 string cmd =
string.Format(
"\"%1\" %2 --python-expr \"import bpy; bpy.ops.ebt.call_blender_function(description = '%3', check_signature = True)\"", pathToExecutable, runInBackgroundCommand, jsonString);
129 if (EBTConfigPlugin.CopyToClipboard())
130 System.ExportToClipboard(cmd);
131 Workbench.RunProcess(cmd);
134static void StartBlenderWithServer(
bool runInBackground =
true)
136 if (!runInBackground)
138 BlenderOperatorDescription operatorDescription =
new BlenderOperatorDescription(
"core");
139 operatorDescription.blIDName =
"ebt.http_server";
141 StartBlenderWithOperator(operatorDescription,
false);
145 string pathToExecutable;
146 if (!EBTConfigPlugin.GetDefaultBlenderPath(pathToExecutable))
149 string cmd =
string.Format(
"\"%1\" --background --python-expr \"import EnfusionBlenderTools.core.server as s; s.EBT_HTTP_Server.start(background_mode=True); s.EBT_HTTP_Server.background_loop()\"", pathToExecutable);
150 if (EBTConfigPlugin.CopyToClipboard())
151 System.ExportToClipboard(cmd);
152 Workbench.RunProcess(cmd);
base classes for filtering in server browser