!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Sandbox / Plugins / LodGeneratorPlugin / Util / LodParameter.cpp
blob1919c014281b4bb0df32417a9a62205e6efd34e3
1 #include "StdAfx.h"
2 #include "LodParameter.h"
3 #include <CrySerialization/IArchive.h>
4 #include <CrySerialization/Callback.h>
5 #include <CrySerialization/Decorators/Range.h>
6 #include <CrySerialization/Color.h>
7 #include <CrySerialization/Enum.h>
8 #include <CrySerialization/Decorators/LocalFrame.h>
9 #include "Controls/PropertyItem.h"
10 #include "Util/Variable.h"
11 #include "../panel/GeneratorOptionsPanel.h"
13 using Serialization::Vec3AsColor;
14 void SLodParameter::Serialize(Serialization::IArchive& ar)
16 ar(m_ID, "m_id");
18 if (m_TODParamType == ELodParamType::eColorType)
20 ar(Vec3AsColor(m_Color), "color", "^");
21 if (m_CGeneratorOptionsPanel != NULL)
22 m_CGeneratorOptionsPanel->ParameterChanged(this);
24 else if (m_TODParamType == ELodParamType::eFloatType)
26 auto callback = [&](float v)
28 m_valueFloat = v;
30 if(m_CGeneratorOptionsPanel != NULL)
31 m_CGeneratorOptionsPanel->ParameterChanged(this);
34 ar(Serialization::Callback(m_valueFloat, callback), "Float", "^");
36 else if (m_TODParamType == ELodParamType::eIntType)
38 auto callback = [&](int v)
40 m_valueInt = v;
42 if(m_CGeneratorOptionsPanel != NULL)
43 m_CGeneratorOptionsPanel->ParameterChanged(this);
46 ar(Serialization::Callback(m_valueInt, callback), "I32", "^");
48 else if (m_TODParamType == ELodParamType::eBoolType)
50 auto callback = [&](bool v)
52 m_valueBool = v;
54 if(m_CGeneratorOptionsPanel != NULL)
55 m_CGeneratorOptionsPanel->ParameterChanged(this);
58 ar(Serialization::Callback(m_valueBool, callback), "bool", "^");
60 else if (m_TODParamType == ELodParamType::eStringType)
62 auto callback = [&](string v)
64 m_valueString = v;
66 if(m_CGeneratorOptionsPanel != NULL)
67 m_CGeneratorOptionsPanel->ParameterChanged(this);
70 ar(Serialization::Callback(m_valueString, callback), "string", "^");
72 else
74 //....
81 static struct {
82 int dataType;
83 const char *name;
84 PropertyType type;
85 int image;
86 } s_propertyTypeNames[] =
88 { IVariable::DT_SIMPLE,"Bool",PropertyType::ePropertyBool,2 },
89 { IVariable::DT_SIMPLE,"Int",PropertyType::ePropertyInt,0 },
90 { IVariable::DT_SIMPLE,"Float",PropertyType::ePropertyFloat,0 },
91 { IVariable::DT_SIMPLE,"Vector",PropertyType::ePropertyVector2,10 },
92 { IVariable::DT_SIMPLE,"Vector",PropertyType::ePropertyVector,10 },
93 { IVariable::DT_SIMPLE,"Vector",PropertyType::ePropertyVector4,10 },
94 { IVariable::DT_SIMPLE,"String",PropertyType::ePropertyString,3 },
95 { IVariable::DT_PERCENT,"Float",PropertyType::ePropertyInt,13 },
96 { IVariable::DT_BOOLEAN,"Boolean",PropertyType::ePropertyBool,2 },
97 { IVariable::DT_COLOR,"Color",PropertyType::ePropertyColor,1 },
98 { IVariable::DT_CURVE|IVariable::DT_PERCENT,"FloatCurve",PropertyType::ePropertyFloatCurve,13 },
99 { IVariable::DT_CURVE|IVariable::DT_COLOR,"ColorCurve",PropertyType::ePropertyColorCurve,1 },
100 { IVariable::DT_ANGLE,"Angle",PropertyType::ePropertyAngle,0 },
101 { IVariable::DT_FILE,"File",PropertyType::ePropertyFile,7 },
102 { IVariable::DT_TEXTURE,"Texture",PropertyType::ePropertyTexture,4 },
103 { IVariable::DT_ANIMATION,"Animation",PropertyType::ePropertyAnimation,-1 },
104 { IVariable::DT_OBJECT,"Model",PropertyType::ePropertyModel,5 },
105 { IVariable::DT_SIMPLE,"Selection",PropertyType::ePropertySelection,-1 },
106 { IVariable::DT_SIMPLE,"List",PropertyType::ePropertyList,-1 },
107 { IVariable::DT_SHADER,"Shader",PropertyType::ePropertyShader,9 },
108 { IVariable::DT_MATERIAL,"Material",PropertyType::ePropertyMaterial,14 },
109 { IVariable::DT_AI_BEHAVIOR,"AIBehavior",PropertyType::ePropertyAiBehavior,8 },
110 { IVariable::DT_AI_ANCHOR,"AIAnchor",PropertyType::ePropertyAiAnchor,8 },
111 #ifdef USE_DEPRECATED_AI_CHARACTER_SYSTEM
112 { IVariable::DT_AI_CHARACTER,"AICharacter",PropertyType::ePropertyAiCharacter,8 },
113 #endif
114 { IVariable::DT_AI_PFPROPERTIESLIST,"AgentTypeList",PropertyType::ePropertyAiPFPropertiesList,8 },
115 { IVariable::DT_AIENTITYCLASSES,"AI Entity Classes",PropertyType::ePropertyAiEntityClasses,8 },
116 { IVariable::DT_EQUIP,"Equip",PropertyType::ePropertyEquip,11 },
117 { IVariable::DT_REVERBPRESET,"ReverbPreset",PropertyType::ePropertyReverbPreset,11 },
118 { IVariable::DT_LOCAL_STRING,"LocalString",PropertyType::ePropertyLocalString,3 },
119 { IVariable::DT_SOCLASS,"Smart Object Class",PropertyType::ePropertySOClass,8 },
120 { IVariable::DT_SOCLASSES,"Smart Object Classes",PropertyType::ePropertySOClasses,8 },
121 { IVariable::DT_SOSTATE,"Smart Object State",PropertyType::ePropertySOState,8 },
122 { IVariable::DT_SOSTATES,"Smart Object States",PropertyType::ePropertySOStates,8 },
123 { IVariable::DT_SOSTATEPATTERN,"Smart Object State Pattern",PropertyType::ePropertySOStatePattern,8 },
124 { IVariable::DT_SOACTION,"AI Action",PropertyType::ePropertySOAction,8 },
125 { IVariable::DT_SOHELPER,"Smart Object Helper",PropertyType::ePropertySOHelper,8 },
126 { IVariable::DT_SONAVHELPER,"Smart Object Navigation Helper",PropertyType::ePropertySONavHelper,8 },
127 { IVariable::DT_SOANIMHELPER,"Smart Object Animation Helper",PropertyType::ePropertySOAnimHelper,8 },
128 { IVariable::DT_SOEVENT,"Smart Object Event",PropertyType::ePropertySOEvent,8 },
129 { IVariable::DT_SOTEMPLATE,"Smart Object Template",PropertyType::ePropertySOTemplate,8 },
130 { IVariable::DT_CUSTOMACTION,"Custom Action",PropertyType::ePropertyCustomAction,7 },
131 { IVariable::DT_VEEDHELPER,"Vehicle Helper",PropertyType::ePropertySelection,-1 },
132 { IVariable::DT_VEEDPART,"Vehicle Part",PropertyType::ePropertySelection,-1 },
133 { IVariable::DT_VEEDCOMP,"Vehicle Component",PropertyType::ePropertySelection,-1 },
134 { IVariable::DT_GAMETOKEN,"Game Token",PropertyType::ePropertyGameToken, -1 },
135 { IVariable::DT_SEQUENCE,"Sequence",PropertyType::ePropertySequence, -1 },
136 { IVariable::DT_MISSIONOBJ,"Mission Objective",PropertyType::ePropertyMissionObj, -1 },
137 { IVariable::DT_USERITEMCB,"User",PropertyType::ePropertyUser, -1 },
138 { IVariable::DT_AITERRITORY,"AITerritory",PropertyType::ePropertyAiTerritory,8 },
139 { IVariable::DT_AIWAVE,"AIWave",PropertyType::ePropertyAiWave,8 },
140 { IVariable::DT_SEQUENCE_ID,"SequenceId",PropertyType::ePropertySequenceId, -1 },
141 //{ IVariable::DT_LIGHT_ANIMATION,"LightAnimation",PropertyType::ePropertyLightAnimation, -1 },
142 { IVariable::DT_FLARE,"Flare",PropertyType::ePropertyFlare,7 },
143 { IVariable::DT_PARTICLE_EFFECT,"ParticleEffect",PropertyType::ePropertyParticleName, 3 },
144 { IVariable::DT_GEOM_CACHE,"Geometry Cache",PropertyType::ePropertyGeomCache,5 },
145 { IVariable::DT_AUDIO_TRIGGER,"Audio Trigger",PropertyType::ePropertyAudioTrigger,6 },
146 { IVariable::DT_AUDIO_SWITCH,"Audio Switch",PropertyType::ePropertyAudioSwitch,6 },
147 { IVariable::DT_AUDIO_SWITCH_STATE,"Audio Switch",PropertyType::ePropertyAudioSwitchState,6 },
148 { IVariable::DT_AUDIO_RTPC,"Audio Realtime Parameter Control",PropertyType::ePropertyAudioRTPC,6 },
149 { IVariable::DT_AUDIO_ENVIRONMENT,"Audio Environment",PropertyType::ePropertyAudioEnvironment,6 },
150 { IVariable::DT_AUDIO_PRELOAD_REQUEST,"Audio Preload Request",PropertyType::ePropertyAudioPreloadRequest,6 },
152 static int NumPropertyTypes = sizeof(s_propertyTypeNames)/sizeof(s_propertyTypeNames[0]);
154 void GetVariableParams( IVariable *var ,PropertyType& pType,float& fMin,float& fMax,float& fStep);
156 ELodParamType SLodParameter::GetLodParamType(IVariable* pCurVariable)
158 ELodParamType eLodParamType = eUNKownType;
159 PropertyType pType;
160 float fMin;
161 float fMax;
162 float fStep;
163 GetVariableParams(pCurVariable,pType,fMin,fMax,fStep);
165 switch (pType)
167 case ePropertyInvalid:
168 break;
169 case ePropertyTable:
170 break;
171 case ePropertyBool:
172 eLodParamType = eBoolType;
173 break;
174 case ePropertyInt:
175 eLodParamType = eIntType;
176 break;
177 case ePropertyFloat:
178 eLodParamType = eFloatType;
179 break;
180 case ePropertyVector2:
181 break;
182 case ePropertyVector:
183 break;
184 case ePropertyVector4:
185 break;
186 case ePropertyString:
187 eLodParamType = eStringType;
188 break;
189 case ePropertyColor:
190 eLodParamType = eColorType;
191 break;
192 case ePropertyAngle:
193 break;
194 case ePropertyFloatCurve:
195 break;
196 case ePropertyColorCurve:
197 break;
198 case ePropertyFile:
199 break;
200 case ePropertyTexture:
201 break;
202 case ePropertyAnimation:
203 break;
204 case ePropertyModel:
205 break;
206 case ePropertySelection:
207 break;
208 case ePropertyList:
209 break;
210 case ePropertyShader:
211 break;
212 case ePropertyMaterial:
213 break;
214 case ePropertyAiBehavior:
215 break;
216 case ePropertyAiAnchor:
217 break;
218 case ePropertyAiPFPropertiesList:
219 break;
220 case ePropertyAiEntityClasses:
221 break;
222 case ePropertyAiTerritory:
223 break;
224 case ePropertyAiWave:
225 break;
226 case ePropertyEquip:
227 break;
228 case ePropertyReverbPreset:
229 break;
230 case ePropertyLocalString:
231 break;
232 case ePropertySOClass:
233 break;
234 case ePropertySOClasses:
235 break;
236 case ePropertySOState:
237 break;
238 case ePropertySOStates:
239 break;
240 case ePropertySOStatePattern:
241 break;
242 case ePropertySOAction:
243 break;
244 case ePropertySOHelper:
245 break;
246 case ePropertySONavHelper:
247 break;
248 case ePropertySOAnimHelper:
249 break;
250 case ePropertySOEvent:
251 break;
252 case ePropertySOTemplate:
253 break;
254 case ePropertyCustomAction:
255 break;
256 case ePropertyGameToken:
257 break;
258 case ePropertySequence:
259 break;
260 case ePropertyMissionObj:
261 break;
262 case ePropertyUser:
263 break;
264 case ePropertySequenceId:
265 break;
266 /*case ePropertyLightAnimation:
267 break;*/
268 case ePropertyFlare:
269 break;
270 case ePropertyParticleName:
271 break;
272 case ePropertyGeomCache:
273 break;
274 case ePropertyAudioTrigger:
275 break;
276 case ePropertyAudioSwitch:
277 break;
278 case ePropertyAudioSwitchState:
279 break;
280 case ePropertyAudioRTPC:
281 break;
282 case ePropertyAudioEnvironment:
283 break;
284 case ePropertyAudioPreloadRequest:
285 break;
286 default:
287 break;
290 return eLodParamType;
293 void GetVariableParams( IVariable *var ,PropertyType& pType,float& fMin,float& fMax,float& fStep)
295 _smart_ptr<IVariable> pInputVar = var;
297 int dataType = var->GetDataType();
298 string m_name = var->GetHumanName();
299 pType = ePropertyInvalid;
300 int i;
302 if (dataType != IVariable::DT_SIMPLE)
304 for (i = 0; i < NumPropertyTypes; i++)
306 if (dataType == s_propertyTypeNames[i].dataType)
308 pType = s_propertyTypeNames[i].type;
309 break;
314 IVarEnumList* enumList = var->GetEnumList();
315 if (enumList != NULL)
317 pType = ePropertySelection;
320 if (pType == ePropertyInvalid)
322 switch(var->GetType())
324 case IVariable::INT:
325 pType = ePropertyInt;
326 break;
327 case IVariable::BOOL:
328 pType = ePropertyBool;
329 break;
330 case IVariable::FLOAT:
331 pType = ePropertyFloat;
332 break;
333 case IVariable::VECTOR2:
334 pType = ePropertyVector2;
335 break;
336 case IVariable::VECTOR4:
337 pType = ePropertyVector4;
338 break;
339 case IVariable::VECTOR:
340 pType = ePropertyVector;
341 break;
342 case IVariable::STRING:
343 pType = ePropertyString;
344 break;
348 float m_valueMultiplier = 1;
349 float m_rangeMin = 0;
350 float m_rangeMax = 100;
351 float m_step = 0.f;
352 bool m_bHardMin = false;
353 bool m_bHardMax = false;
354 // Get variable limits.
355 var->GetLimits( m_rangeMin, m_rangeMax, m_step, m_bHardMin, m_bHardMax );
357 // Check if value is percents.
358 if (dataType == IVariable::DT_PERCENT)
360 // Scale all values by 100.
361 m_valueMultiplier = 100;
363 else if (dataType == IVariable::DT_ANGLE)
365 // Scale radians to degrees.
366 m_valueMultiplier = RAD2DEG(1);
367 m_rangeMin = -360;
368 m_rangeMax = 360;
370 else if (dataType == IVariable::DT_UIENUM)
372 //CUIEnumsDatabase_SEnum* m_pEnumDBItem = GetIEditor()->GetUIEnumsDatabase()->FindEnum(m_name);
376 const bool useExplicitStep = (var->GetFlags() & IVariable::UI_EXPLICIT_STEP);
377 if (!useExplicitStep)
379 // Limit step size to 1000.
380 int nPrec = max(3 - int(log(m_rangeMax - m_rangeMin) / log(10.f)), 0);
381 m_step = max(m_step, powf(10.f, -nPrec));