Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
CallBlenderFunction.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2
3
4// returns hex string in #ffffffff format
5static string ColorToHexString(Color color)
6{
7 const string hexChars = "0123456789abcdef";
8
9 int value = color.PackToInt();
10
11 string hexString = "#";
12
13 for (int i = 7; i >= 0; i--) {
14 int hexDigit = (value >> i * 4) & 0xF;
15 hexString += hexChars[hexDigit];
16 }
17
18 return hexString;
19};
20
21// returns color from given hex string
22static Color HexStringToColor(string hexString)
23{
24 const string hexChars = "0123456789abcdef";
25
26 int lookupTable[128] = {0}; // create hex digit lookup table from ascii table
27
28 for (int i = "0".ToAscii(); i <= "9".ToAscii(); i++)
29 {
30 lookupTable[i] = i - "0".ToAscii();
31 }
32
33 for (int i = "a".ToAscii(); i <= "f".ToAscii(); i++)
34 {
35 lookupTable[i] = 10 + (i - "a".ToAscii());
36 }
37
38 int packedInt = 0;
39
40 hexString.ToLower();
41 hexString = hexString.Substring(1, 8);
42
43 for (int i = 0; i < 8; i++)
44 {
45 int c = hexString[i].ToAscii();
46 packedInt = (packedInt << 4) | lookupTable[c];
47 }
48
49 return Color.FromInt(packedInt);
50}
51
52class BlenderOperatorDescription : JsonApiStruct
53{
54 string moduleName;
55 string blIDName;
56
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>;
62
63 void BlenderOperatorDescription(string _moduleName = "", string _blIDName = "")
64 {
65 moduleName = _moduleName;
66 blIDName = _blIDName;
67 }
68
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); }
74
75 override void OnPack()
76 {
77 StoreString("module_name", moduleName);
78 StoreString("bl_idname", blIDName);
79
80 StartObject("parameters");
81 {
82 foreach(string paramName, int value : intParams)
83 {
84 StoreInteger(paramName, value);
85 }
86 foreach(string paramName, float value : floatParams)
87 {
88 StoreFloat(paramName, value);
89 }
90 foreach(string paramName, bool value : boolParams)
91 {
92 StoreBoolean(paramName, value);
93 }
94 foreach(string paramName, Color value : colorParams)
95 {
96 StoreString(paramName, ColorToHexString(value));
97 }
98 foreach(string paramName, string value : stringParams)
99 {
100 StoreString(paramName, value);
101 }
102 }
103 EndObject();
104 }
105}
106
107static void StartBlenderWithOperator(BlenderOperatorDescription operatorDescription, bool runInBackground = false)
108{
109 string pathToExecutable;
110 if (!EBTConfigPlugin.GetDefaultBlenderPath(pathToExecutable))
111 return;
112
113 operatorDescription.Pack();
114
115 string runInBackgroundCommand = "";
116
117 if (runInBackground)
118 {
119 runInBackgroundCommand = " \"-b\"";
120 }
121
122
123 string jsonString = operatorDescription.AsString();
124
125 jsonString.Replace("\"", "\\*");
126 jsonString.Replace("*", "\"");
127
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);
132}
133
134static void StartBlenderWithServer(bool runInBackground = true)
135{
136 if (!runInBackground)
137 {
138 BlenderOperatorDescription operatorDescription = new BlenderOperatorDescription("core");
139 operatorDescription.blIDName = "ebt.http_server";
140
141 StartBlenderWithOperator(operatorDescription, false);
142 return;
143 }
144
145 string pathToExecutable;
146 if (!EBTConfigPlugin.GetDefaultBlenderPath(pathToExecutable))
147 return;
148
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);
153}
154
155#endif
override void OnPack()
Definition Color.c:13
base classes for filtering in server browser