Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
ResourceInfo.c
Go to the documentation of this file.
1/*
2 EXPORT
3*/
5{
6 None = 0,
10}
11
12enum Cull
13{
14 ccw = 0,
15 none = 1
16}
17
18enum GlobalMCRMode
19{
20 Overlay = 0,
21 Multiply = 1
22}
23
24enum CamoBlendMode
25{
26 Blend = 0,
27 Multiply = 1
28}
29
30// Copied over from TextureImportTool
31bool IsImage(string className)
32{
33 return
34 className == "PNGResourceClass" ||
35 className == "DDSResourceClass" ||
36 className == "TGAResourceClass" ||
37 className == "TIFFResourceClass" ||
38 className == "PNGResourceClass" ||
39 className == "HDRResourceClass" ||
40 className == "JPGResourceClass";
41}
42
43class ContainerJSONSerializer
44{
45 //----------------------------------------------------------------------------------------------
46 static string ResolveEnumValue(typename type, int enumValue)
47 {
48 switch (type)
49 {
50 case BlendMode:
51 {
52 return typename.EnumToString(BlendMode, enumValue);
53 }
54 case Cull:
55 {
56 return typename.EnumToString(Cull, enumValue);
57 }
58 case GlobalMCRMode:
59 {
60 return typename.EnumToString(GlobalMCRMode, enumValue);
61 }
62 case CamoBlendMode:
63 return typename.EnumToString(CamoBlendMode, enumValue);
64 }
65 return "";
66
67 }
68
69 static string ignoredFields[8] = {"userScript", "constructor", "destructor", "editorData", "RplLoad", "RplSave", "Preload", "OnTransformResetImpl"};
70
71 //----------------------------------------------------------------------------------------------
72 static void WriteVars(JsonApiStruct jsonStruct, BaseContainer container, bool expand = false)
73 {
74
75 int childrenCount = container.GetNumChildren();
76 if (childrenCount > 0)
77 jsonStruct.StoreInteger("ChildrenCount", childrenCount); // use data.get("ChildrenCount", 0) on the Python side
78
79 for (int i = 0; i < container.GetNumVars(); i++)
80 {
81 string varName = container.GetVarName(i);
82 /*
83 Effort to reduce the size of the JSON as we often exced the limit of 524320 bytes when trying to send information about the Prefab.
84 TODO: define fields we want for each resource type instead of ignore list. Last option would be to send data in chunks.
85 */
86 if (varName == "" || varName.StartsWith("_WB") || varName.StartsWith("EOn")) continue;
87
88 bool ignore;
89 foreach (auto field : ignoredFields)
90 {
91 if (varName == field)
92 {
93 ignore = true;
94 break;
95 }
96 }
97
98 if (ignore) continue;
99
100
101 DataVarType varType = container.GetDataVarType(i);
102
103 switch (varType)
104 {
105 case DataVarType.COLOR:
106 {
107 Color value;
108 container.Get(varName, value);
109 jsonStruct.StartArray(varName);
110 jsonStruct.ItemFloat(value.R());
111 jsonStruct.ItemFloat(value.G());
112 jsonStruct.ItemFloat(value.B());
113 jsonStruct.ItemFloat(value.A());
114 jsonStruct.EndArray();
115 break;
116 }
117 case DataVarType.STRING_ARRAY:
118 {
119 array<string> value;
120 container.Get(varName, value);
121 jsonStruct.StartArray(varName);
122 foreach (string item : value)
123 {
124 jsonStruct.ItemString(item);
125 }
126 jsonStruct.EndArray();
127
128 break;
129 }
130 case DataVarType.RESOURCE_NAME:
131 {
132 ResourceName value;
133 container.Get(varName, value);
134
135 if (value != "")
136 {
137 if (expand)
138 {
139 ResourceInfo resourceInfo = ResourceInfo.CreateFromResourceName(value, expand);
140 jsonStruct.StoreObject(varName, resourceInfo);
141 break;
142 }
143 }
144
145 jsonStruct.StoreString(varName, value);
146 break;
147 }
148 case DataVarType.RESOURCE_NAME_ARRAY:
149 {
150 array<ResourceName> value;
151
152 container.Get(varName, value);
153 jsonStruct.StartArray(varName);
154 foreach (ResourceName rName : value)
155 {
156 jsonStruct.ItemString(rName);
157 }
158 jsonStruct.EndArray();
159 break;
160 }
161 case DataVarType.STRING:
162 {
163 string value;
164 container.Get(varName, value);
165
166 jsonStruct.StoreString(varName, value);
167 break;
168 }
169 case DataVarType.TEXTURE:
170 {
171 string values;
172 container.Get(varName, values);
173
174 string value = "";
175
176 if (values != "" && values != " 0")
177 {
178 array<string> spltValue = new array<string>();
179 values.Split(" ", spltValue, true);
180
181 value = spltValue[0];
182 if (expand)
183 {
184 ResourceInfo resourceInfo = ResourceInfo.CreateFromResourceName(value, expand);
185 jsonStruct.StoreObject(varName, resourceInfo);
186 break;
187 }
188 }
189 jsonStruct.StoreString(varName, value);
190 break;
191 }
192 case DataVarType.SCALAR:
193 {
194 float value;
195 container.Get(varName, value);
196 jsonStruct.StoreFloat(varName, value);
197 break;
198 }
199 case DataVarType.SCALAR_ARRAY:
200 {
201 array<float> value;
202 container.Get(varName, value);
203 jsonStruct.StartArray(varName);
204 foreach (float item : value)
205 {
206 jsonStruct.ItemFloat(item);
207 }
208 jsonStruct.EndArray();
209 break;
210 }
211 case DataVarType.BOOLEAN:
212 {
213 bool value;
214 container.Get(varName, value);
215 jsonStruct.StoreBoolean(varName, value);
216 break;
217 }
218 case DataVarType.INTEGER:
219 {
220 int value;
221 container.Get(varName, value);
222
223 typename type = varName.ToType();
224
225 if (!type)
226 {
227 jsonStruct.StoreInteger(varName, value);
228 break;
229 }
230
231 string enumFieldName = ResolveEnumValue(type, value);
232 jsonStruct.StoreString(varName, enumFieldName);
233 break;
234 }
235 case DataVarType.VECTOR3:
236 {
237 vector value;
238 container.Get(varName, value);
239
240 jsonStruct.StartArray(varName);
241 jsonStruct.ItemFloat(value[0]);
242 jsonStruct.ItemFloat(value[1]);
243 jsonStruct.ItemFloat(value[2]);
244 jsonStruct.EndArray();
245 break;
246 }
247 case DataVarType.OBJECT:
248 {
249 BaseContainer object = container.GetObject(varName);
250 if (object)
251 {
252 jsonStruct.StoreObject(varName, new GenericJSONContainer(object, false, expand));
253 break;
254 }
255
256 jsonStruct.StartObject(varName);
257 jsonStruct.EndObject();
258 break;
259 }
260 case DataVarType.OBJECT_ARRAY:
261 {
262 BaseContainerList objects = container.GetObjectArray(varName);
263
264 jsonStruct.StartArray(varName);
265 for (int objIdx = 0; objIdx < objects.Count(); objIdx++)
266 {
267 jsonStruct.ItemObject(new GenericJSONContainer(objects.Get(objIdx), true, expand));
268 }
269 jsonStruct.EndArray();
270 break;
271 }
272 default:
273 {
274 //Print(string.Format("Unsupported DataVarType: \"%1\"", typename.EnumToString(DataVarType, varType)));
275 }
276 }
277 }
278
279 /*
280 Reduce size of JSON
281 */
282// int numChildren = container.GetNumChildren();
283//
284// if(numChildren)
285// {
286// jsonStruct.StartArray("Children");
287// for(int i = 0; i < numChildren; i++)
288// {
289// BaseContainer childContainer = container.GetChild(i);
290//
291// if(childContainer)
292// {
293// jsonStruct.ItemObject(new GenericJSONContainer(childContainer, true, expand));
294// }
295// }
296// jsonStruct.EndArray();
297// }
298
299 }
300}
301
302enum InfoStatus
303 {
304 OK,
305 ERROR,
306 }
307
311class GenericJSONContainer : JsonApiStruct
312{
313 BaseContainer m_Container;
314 bool m_bAsArrayItem = false;
315 bool m_bExpandResource = false;
316
317 //----------------------------------------------------------------------------------------------
318 void GenericJSONContainer(BaseContainer container, bool asArrayItem = false, bool expand = false)
319 {
320 m_Container = container;
321 m_bAsArrayItem = asArrayItem;
322 m_bExpandResource = expand;
323 }
324
325 //----------------------------------------------------------------------------------------------
326 override void OnPack()
327 {
328 string objectName = string.Format("%1", m_Container.GetClassName());
329 if (m_bAsArrayItem)
330 {
331 StoreString("ClassName", objectName);
332 StoreString("Name", m_Container.GetName());
333 ContainerJSONSerializer.WriteVars(this, m_Container, m_bExpandResource);
334 }
335 else
336 {
337 StartObject(objectName);
338 ContainerJSONSerializer.WriteVars(this, m_Container, m_bExpandResource);
339 EndObject();
340 }
341 }
342}
343
344class TextureResourceInfo : JsonApiStruct
345{
346 private string TextureSourcePath;
347 private string PostFix;
348 private string ColorSpace;
349 private string Conversion;
350 private bool ContainsMips;
351
352 //----------------------------------------------------------------------------------------------
353 void TextureResourceInfo(string textureSourcePath, string postFix, string colorSpace, string conversion, bool containMips)
354 {
355 TextureSourcePath = textureSourcePath;
356 PostFix = postFix;
357 ColorSpace = colorSpace;
358 Conversion = conversion;
359 ContainsMips = containMips;
360 RegAll();
361 }
362
363 protected static ref TextureTypes Types = new TextureTypes();
364
365 //----------------------------------------------------------------------------------------------
366 static string GetPostFix(string resourcePath)
367 {
368 return Types.FindTextureType(resourcePath).m_PostFix;
369 }
370 }
371
372class MaterialResourceInfo : JsonApiStruct
373{
374 private ResourceName m_ResourceName;
375 private bool m_bExpandResource = false;
376 private array<string> m_Fields;
377
378 //----------------------------------------------------------------------------------------------
379 void MaterialResourceInfo(ResourceName resourceName, bool expand = false)
380 {
381 m_ResourceName = resourceName;
382 m_bExpandResource = expand;
383 }
384
385 //----------------------------------------------------------------------------------------------
386 override void OnPack()
387 {
388 Resource resource = Resource.Load(m_ResourceName);
389
390 BaseContainer basecontainer = resource.GetResource().ToBaseContainer();
391 StoreString("ShaderClass", basecontainer.GetClassName());
392
393 ContainerJSONSerializer.WriteVars(this, basecontainer, m_bExpandResource);
394 }
395}
396
397class XOBResourceInfo : JsonApiStruct
398{
399 private string m_FBXSourcePath;
400 private BaseContainer m_ConfigurationContainer;
401 private bool m_bExpandResource = false;
402
403 //----------------------------------------------------------------------------------------------
404 void XOBResourceInfo(notnull BaseContainer configurationContainer, string fbxSourcePath, bool expand = false)
405 {
406 m_FBXSourcePath = fbxSourcePath;
407 m_ConfigurationContainer = configurationContainer;
408 m_bExpandResource = expand;
409 }
410
411 //----------------------------------------------------------------------------------------------
412 override void OnPack()
413 {
414 StoreString("FBXSourcePath", m_FBXSourcePath);
415 ContainerJSONSerializer.WriteVars(this, m_ConfigurationContainer, m_bExpandResource);
416 }
417}
418
419
420class GenericResourceInfo : JsonApiStruct
421{
422 private ResourceName m_ResourceName;
423 private bool m_bExpandResource = false;
424
425 //----------------------------------------------------------------------------------------------
426 void GenericResourceInfo(ResourceName resourceName, bool expand = false)
427 {
428 m_ResourceName = resourceName;
429 m_bExpandResource = expand;
430 }
431
432 //----------------------------------------------------------------------------------------------
433 override void OnPack()
434 {
435 Resource resource = Resource.Load(m_ResourceName);
436
437 BaseContainer basecontainer = resource.GetResource().ToBaseContainer();
438 StoreString("ClassName", basecontainer.GetClassName());
439
440 ContainerJSONSerializer.WriteVars(this, basecontainer, m_bExpandResource);
441 }
442}
443
444
445class ResourceInfo : JsonApiStruct
446{
447 private string status;
448 private string message;
449 private string resourceName;
450 private string absolutePath;
451 private ref JsonApiStruct data;
452
453 //----------------------------------------------------------------------------------------------
454 void ResourceInfo(InfoStatus _status, ResourceName _resourceName, string _absolute_path, string _message, JsonApiStruct _data)
455 {
456 status = typename.EnumToString(InfoStatus, _status);
457 resourceName = _resourceName;
458 message = _message;
459 data = _data;
460 absolutePath = _absolute_path;
461
462 RegAll();
463 if (data == null)
464 UnregV("data");
465 }
466
467 //----------------------------------------------------------------------------------------------
468 private static string CreateSourceFileNotFoundmessage(ResourceName _resourceName)
469 {
470 return string.Format("Source file not found for resource: %1", _resourceName);
471 }
472
473 //----------------------------------------------------------------------------------------------
477 static ResourceInfo CreateFromResourceName(ResourceName _resourceName, bool expand = false)
478 {
479 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
480 string resourcePath = _resourceName.GetPath();
481 MetaFile meta = resourceManager.GetMetaFile(resourcePath);
482
483 if (!meta)
484 {
485 return ResourceInfo(
486 InfoStatus.ERROR,
487 string.Empty,
488 string.Empty,
489 string.Format("Resource not found: %1", _resourceName),
490 null);
491 }
492
493 BaseContainer configurationContainer = meta.GetObjectArray("Configurations")[0];
494
495 if (!configurationContainer)
496 {
497 return ResourceInfo(
498 InfoStatus.ERROR,
499 _resourceName,
500 string.Empty,
501 string.Format("Invalid configuration container for resource: %1", _resourceName),
502 null);
503 }
504
505 string className = configurationContainer.GetClassName();
506
507 if (className == "FBXResourceClass")
508 {
509 string fbxSourcePath;
510 if (!Workbench.GetAbsolutePath(meta.GetSourceFilePath(), fbxSourcePath, true))
511 {
512 return ResourceInfo(
513 InfoStatus.ERROR,
514 _resourceName,
515 string.Empty,
516 CreateSourceFileNotFoundmessage(_resourceName),
517 null);
518 }
519
520 return ResourceInfo(InfoStatus.OK, _resourceName, fbxSourcePath, string.Empty, new XOBResourceInfo(configurationContainer, fbxSourcePath, expand));
521 }
522
523 if (className == "EMATResourceClass")
524 {
525 Resource resource = Resource.Load(_resourceName);
526
527 if (!resource.IsValid())
528 {
529 return ResourceInfo(
530 InfoStatus.ERROR,
531 _resourceName,
532 string.Empty,
533 string.Format("Resource could not be loaded: %1", _resourceName),
534 null);
535 }
536
537 string file_path = resource.GetResource().GetResourceName().GetPath();
538 string absolute_path;
539
540 bool result = Workbench.GetAbsolutePath(file_path, absolute_path, true);
541
542 if (!result){
543 absolute_path = string.Empty;
544 }
545
546
547 return ResourceInfo(InfoStatus.OK, _resourceName, absolute_path, string.Empty, new MaterialResourceInfo(_resourceName, expand));
548 }
549
550
551 if(className == "EntityTemplateResourceClass" || className == "GameMaterialResourceClass")
552 {
553 Resource resource = Resource.Load(_resourceName);
554
555 if (!resource.IsValid())
556 {
557 return ResourceInfo(
558 InfoStatus.ERROR,
559 _resourceName,
560 string.Empty,
561 string.Format("Resource could not be loaded: %1", _resourceName),
562 null);
563 }
564
565 if (className == "GameMaterialResourceClass") //Hack to prevent recursion
566 expand = false;
567
568 string file_path = resource.GetResource().GetResourceName().GetPath();
569 string absolute_path;
570
571 bool result = Workbench.GetAbsolutePath(file_path, absolute_path, true);
572
573 if (!result){
574 absolute_path = string.Empty;
575 }
576
577 return ResourceInfo(InfoStatus.OK, _resourceName, absolute_path, "", new GenericResourceInfo(_resourceName, expand));
578 }
579
580
581 if (IsImage(className))
582 {
583 string textureSourcePath;
584 if (!Workbench.GetAbsolutePath(meta.GetSourceFilePath(), textureSourcePath, true))
585 {
586 return ResourceInfo(
587 InfoStatus.ERROR,
588 _resourceName,
589 string.Empty,
590 CreateSourceFileNotFoundmessage(_resourceName),
591 null);
592 }
593
594 string postFix = TextureResourceInfo.GetPostFix(resourcePath);
595 int colorSpaceEnumValue;
596 int conversionEnumValue;
597 int containsMips;
598
599 configurationContainer.Get("ColorSpace", colorSpaceEnumValue);
600 configurationContainer.Get("Conversion", conversionEnumValue);
601 configurationContainer.Get("ContainsMips", containsMips);
602
603
604 string colorSpace = typename.EnumToString(MetaEddsColorSpaceConversion, colorSpaceEnumValue);
605 string conversion = typename.EnumToString(MetaEddsConversion, conversionEnumValue);
606
607 TextureResourceInfo textureProperty = new TextureResourceInfo(textureSourcePath, postFix, colorSpace, conversion, containsMips);
608
609 return ResourceInfo(InfoStatus.OK, _resourceName, textureSourcePath, string.Empty, textureProperty);
610 }
611
612 return ResourceInfo(
613 InfoStatus.ERROR,
614 _resourceName,
615 string.Empty,
616 string.Format("Unsuported resource type: %1 for resource: %2", className, _resourceName),
617 null);
618 }
619
620 //----------------------------------------------------------------------------------------------
621 static ResourceInfo CreateFromResourceAbsolutePath(string absPath, bool expand = false)
622 {
623 if (!FileIO.FileExists(absPath))
624 {
625 return ResourceInfo(
626 InfoStatus.ERROR,
627 string.Empty,
628 string.Empty,
629 string.Format("Resource with absolute path: %1 not found. ", absPath),
630 null);
631 }
632
633 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
634 MetaFile meta = resourceManager.GetMetaFile(absPath);
635
636 if (!meta)
637 {
638 return ResourceInfo(
639 InfoStatus.ERROR,
640 string.Empty,
641 string.Empty,
642 string.Format("Resource with absolute path: %1 is not registered with current runing project. ", absPath),
643 null);
644 }
645
646 return CreateFromResourceName(meta.GetResourceID(), expand);
647 }
648}
649
650class GetResourceInfoRequest : JsonApiStruct
651{
652 string path;
653 bool expandResource;
654
655 //----------------------------------------------------------------------------------------------
656 void GetResourceInfoRequest()
657 {
658 RegAll();
659 }
660}
661
662class GetResourceInfo : NetApiHandler
663{
664 //----------------------------------------------------------------------------------------------
665 override JsonApiStruct GetRequest()
666 {
667 return new GetResourceInfoRequest();
668 }
669
670 //----------------------------------------------------------------------------------------------
671 override JsonApiStruct GetResponse(JsonApiStruct request)
672 {
673 GetResourceInfoRequest req = GetResourceInfoRequest.Cast(request);
674
675 if (FilePath.IsAbsolutePath(req.path))
676 {
677 return ResourceInfo.CreateFromResourceAbsolutePath(req.path, req.expandResource);
678 }
679
680 return ResourceInfo.CreateFromResourceName(req.path, req.expandResource);
681 }
682}
683
684
685/*
686 PREFAB CHILD
687*/
688
689class GetPrefabChildRequest: JsonApiStruct
690{
691 ResourceName resourceName; //prefab resource name
692 ref array<int> childIdx = new array<int>;
693 bool expandResource;
694
695 //----------------------------------------------------------------------------------------------
696 void GetPrefabChildRequest()
697 {
698 RegAll();
699 }
700}
701
702class GetPrefabChildInfo: NetApiHandler
703{
704 //----------------------------------------------------------------------------------------------
705 override JsonApiStruct GetRequest()
706 {
707 return new GetPrefabChildRequest();
708 }
709
710 //----------------------------------------------------------------------------------------------
711 override JsonApiStruct GetResponse(JsonApiStruct request)
712 {
713 GetPrefabChildRequest req = GetPrefabChildRequest.Cast(request);
714
715 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
716 MetaFile meta = resourceManager.GetMetaFile(req.resourceName.GetPath());
717
718 if (!meta)
719 {
720 return ResourceInfo(
721 InfoStatus.ERROR,
722 req.resourceName,
723 string.Empty,
724 string.Format("Resource not found: %1", req.resourceName),
725 null);
726 }
727
728 Resource resource = Resource.Load(req.resourceName);
729 BaseContainer baseContainer = resource.GetResource().ToBaseContainer();
730
731 BaseContainer childContainer = baseContainer;
732
733 for (int i = 0; i < req.childIdx.Count(); i++)
734 {
735 childContainer = childContainer.GetChild(req.childIdx[i]);
736 }
737
738
739 if (!childContainer)
740 {
741 return ResourceInfo(
742 InfoStatus.ERROR,
743 req.resourceName,
744 string.Empty,
745 string.Format("Prefab doesn't have child with index: %1", req.childIdx),
746 null);
747 }
748
749 GenericJSONContainer data = new GenericJSONContainer(childContainer, false, req.expandResource);
750
751 return ResourceInfo(InfoStatus.OK, "", string.Empty, string.Empty, data);
752 }
753}
754
755/*
756 GAME MATERIALS
757*/
758
759class GetGameMaterialsResponse : JsonApiStruct
760{
761 ref array<ResourceName> data = new array<ResourceName>;
762
763 //----------------------------------------------------------------------------------------------
764 void GetGameMaterialsResponse()
765 {
766 RegAll();
767 }
768}
769
770class GetGameMaterials: NetApiHandler
771{
772 //----------------------------------------------------------------------------------------------
773 override JsonApiStruct GetRequest()
774 {
775 return null;
776 }
777
778 //----------------------------------------------------------------------------------------------
779 override JsonApiStruct GetResponse(JsonApiStruct request)
780 {
781 map<string, string> result = new map<string, string>();
782
783 GetGameMaterialsResponse response = new GetGameMaterialsResponse;
784
785 SearchResourcesFilter filter = new SearchResourcesFilter();
786 filter.fileExtensions = {"gamemat"};
787
788 ResourceDatabase.SearchResources(filter, response.data.Insert);
789
790 return response;
791 }
792}
793
794/*
795 IMPORT EMAT
796*/
797
798class MatUVTransformTemplate : JsonApiStruct
799{
800 float TilingU = 1;
801 float TilingV = 1;
802 float OffsetU = 0;
803 float OffsetV = 0;
804 float Rotation = 0;
805
806 //----------------------------------------------------------------------------------------------
807 void MatUVTransformTemplate()
808 {
809 RegAll();
810 }
811}
812
813class MatParam : JsonApiStruct
814{
815 string name;
816 string value;
817
818 //----------------------------------------------------------------------------------------------
819 void MatParam()
820 {
821 RegAll();
822 }
823}
824
825class DynMaterialTemplate : JsonApiStruct
826{
827 bool create = false;
828 ResourceName resourceName;
829 string resourcePath;
830 string type;
831 ref array<ref MatParam> data = {};
832
833 //----------------------------------------------------------------------------------------------
834 void DynMaterialTemplate()
835 {
836 RegAll();
837 }
838}
839
840class ExportMaterialResource : NetApiHandler
841{
842 //----------------------------------------------------------------------------------------------
843 override JsonApiStruct GetRequest()
844 {
845 return new DynMaterialTemplate();
846 }
847
848 //----------------------------------------------------------------------------------------------
849 static private void CopyParamsToEmatContainer(array<ref MatParam> data, notnull BaseContainer container)
850 {
851 foreach(MatParam param : data)
852 {
853 int index = container.GetVarIndex(param.name);
854
855 if (index == -1)
856 {
857 Print(string.Format("%1 field was not found in EMAT!!!", param.name));
858 continue;
859 }
860
861 if (param.value == "None" | param.value == string.Empty)
862 {
863 container.ClearVariable(param.name);
864 continue;
865 }
866
867 if(param.name.Contains("UVTransform"))
868 {
869 MatUVTransformTemplate transform = new MatUVTransformTemplate;
870 transform.ExpandFromRAW(param.value);
871
872 Resource matUVTransformResource;
873 BaseContainer matUVTransformContainer = container.GetObject(param.name);
874
875 if (!matUVTransformContainer)
876 {
877 matUVTransformResource = BaseContainerTools.CreateContainer("MatUVTransform");
878 matUVTransformContainer = matUVTransformResource.GetResource().ToBaseContainer();
879 }
880
881 BaseContainerTools.ReadFromInstance(transform, matUVTransformContainer);
882
883 int numOfDefaultValues = 0;
884 // Prevent serialization of values that equal to default value
885 for (int i = 0; i < matUVTransformContainer.GetNumVars(); i++)
886 {
887 string varName = matUVTransformContainer.GetVarName(i);
888 string defaultValue;
889 string currentValue;
890 matUVTransformContainer.GetDefaultAsString(varName, defaultValue);
891 matUVTransformContainer.Get(varName, currentValue);
892
893 if (defaultValue == currentValue)
894 {
895 matUVTransformContainer.ClearVariable(varName);
896 numOfDefaultValues += 1;
897 }
898 }
899
900 if (numOfDefaultValues == matUVTransformContainer.GetNumVars())
901 {
902 container.ClearVariable(param.name);
903 continue;
904 }
905
906 container.SetObject(param.name, matUVTransformContainer); //in case of new instance of MatUVTransform
907 continue;
908 }
909
910 container.Set(param.name, param.value);
911
912 // Prevent serialization of values that equal to default value
913 // We do it after setting so that values have correct format e.g 1 instead of 1.000 etc...
914 string defaultValue;
915 string currentValue;
916 container.GetDefaultAsString(param.name, defaultValue);
917 container.Get(param.name, currentValue);
918
919 if (defaultValue == currentValue)
920 {
921 container.ClearVariable(param.name);
922 }
923 }
924 }
925
926 //----------------------------------------------------------------------------------------------
927 override JsonApiStruct GetResponse(JsonApiStruct request)
928 {
929 DynMaterialTemplate req = DynMaterialTemplate.Cast(request);
930 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
931
932 string resourcePath;
933 Resource resource;
934 BaseContainer container;
935
936 if (req.create)
937 {
938 resource = BaseContainerTools.CreateContainer(req.type);
939 if (!resource)
940 {
941 return ResourceInfo(
942 InfoStatus.ERROR,
943 string.Empty,
944 string.Empty,
945 string.Format("Error creating BaseContainer with type: %1", req.type),
946 null);
947 }
948
949 container = resource.GetResource().ToBaseContainer();
950 resourcePath = req.resourcePath;
951 }
952 else
953 {
954 resourcePath = req.resourceName.GetPath();
955 MetaFile meta = resourceManager.GetMetaFile(resourcePath);
956
957 if (!meta)
958 {
959 return ResourceInfo(
960 InfoStatus.ERROR,
961 string.Empty,
962 string.Empty,
963 string.Format("Resource not found: %1", req.resourceName),
964 null);
965 }
966
967 resource = Resource.Load(req.resourceName);
968 container = resource.GetResource().ToBaseContainer();
969 }
970
971 CopyParamsToEmatContainer(req.data, container);
972
973 BaseContainerTools.SaveContainer(container, "", resourcePath);
974
975 if (req.create)
976 resourceManager.RegisterResourceFile(resourcePath, false);
977
978 return ResourceInfo.CreateFromResourceAbsolutePath(resourcePath);
979 }
980}
981
982/*
983 IMPORT FBX
984*/
985
986class MaterialOverride : JsonApiStruct
987{
988 string sourceMaterial;
989 string assignedMaterial;
990
991 //----------------------------------------------------------------------------------------------
992 void MaterialOverride()
993 {
994 RegAll();
995 }
996}
997
998class FBXImportRequest : JsonApiStruct
999{
1000 string resourcePath;
1001 bool exportMorphs;
1002 bool exportSceneHierarchy;
1003 bool exportSkinning;
1004 ref array<ref MaterialOverride> materialOverrides = new array<ref MaterialOverride>;
1005
1006 //----------------------------------------------------------------------------------------------
1007 void FBXImportRequest()
1008 {
1009 RegAll();
1010 }
1011}
1012
1013class ExportFBXResource : NetApiHandler
1014{
1015 //----------------------------------------------------------------------------------------------
1016 override JsonApiStruct GetRequest()
1017 {
1018 return new FBXImportRequest();
1019 }
1020
1021 //----------------------------------------------------------------------------------------------
1022 void SetWithClear(BaseContainer container, string varName, bool value)
1023 {
1024 string defaultValue, currentValue;
1025
1026 container.Set(varName, value);
1027 container.Get(varName, currentValue); // stores bool as '0' and '1'
1028 container.GetDefaultAsString(varName, defaultValue);
1029
1030 if (defaultValue == currentValue)
1031 container.ClearVariable(varName);
1032 }
1033
1034 //----------------------------------------------------------------------------------------------
1035 override JsonApiStruct GetResponse(JsonApiStruct request)
1036 {
1037 FBXImportRequest req = FBXImportRequest.Cast(request);
1038 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
1039 MetaFile meta = resourceManager.GetMetaFile(req.resourcePath);
1040
1041 if (!meta)
1042 {
1043 if (resourceManager.RegisterResourceFile(req.resourcePath, false))
1044 meta = resourceManager.GetMetaFile(req.resourcePath);
1045
1046 if (!meta)
1047 {
1048 return ResourceInfo(
1049 InfoStatus.ERROR,
1050 string.Empty,
1051 string.Empty,
1052 string.Format("Resource could not be registered: %1", req.resourcePath),
1053 null);
1054 }
1055 }
1056
1057 BaseContainer cfg = meta.GetObjectArray("Configurations").Get(0);
1058
1059 SetWithClear(cfg, "ExportMorphs", req.exportMorphs);
1060 SetWithClear(cfg, "ExportSceneHierarchy", req.exportSceneHierarchy);
1061 SetWithClear(cfg, "ExportSkinning", req.exportSkinning);
1062
1063 cfg.ClearVariable("GeometryParams");
1064
1065
1066 if (req.materialOverrides.Count() > 0)
1067 {
1068 BaseContainerList materialAssigns = cfg.SetObjectArray("MaterialAssigns");
1069
1070
1071 foreach(MaterialOverride oRide : req.materialOverrides)
1072 {
1073 bool materialSourceFound;
1074 for (int i = 0; i < materialAssigns.Count(); i++)
1075 {
1076 string sourceMaterial;
1077 materialAssigns[i].Get("SourceMaterial", sourceMaterial);
1078
1079 if (sourceMaterial == oRide.sourceMaterial)
1080 {
1081 materialAssigns[i].Set("AssignedMaterial", oRide.assignedMaterial);
1082 materialSourceFound = true;
1083 break;
1084 }
1085 }
1086
1087 if (materialSourceFound)
1088 continue;
1089
1090
1091 Resource materialAssign = BaseContainerTools.CreateContainer("MaterialAssignClass");
1092
1093 BaseContainer cont = materialAssign.GetResource().ToBaseContainer();
1094 cont.Set("SourceMaterial", oRide.sourceMaterial);
1095 cont.Set("AssignedMaterial", oRide.assignedMaterial);
1096
1097 materialAssigns.Insert(cont);
1098 }
1099
1100
1101 }
1102
1103 meta.Save();
1104
1105 resourceManager.RebuildResourceFile(req.resourcePath, "PC", false);
1106 return ResourceInfo.CreateFromResourceAbsolutePath(req.resourcePath);
1107 }
1108}
1109
1110/*
1111 IMPORT TEXTURE
1112*/
1113class ExportTextureResourceRequest : JsonApiStruct
1114{
1115 string sourcePath;
1116 string destinationPath;
1117
1118 //----------------------------------------------------------------------------------------------
1119 void ExportTextureResourceRequest()
1120 {
1121 RegAll();
1122 }
1123}
1124
1125class ExportTextureResource : NetApiHandler
1126{
1127 override JsonApiStruct GetRequest()
1128 {
1129 return new ExportTextureResourceRequest();
1130 }
1131
1132 override JsonApiStruct GetResponse(JsonApiStruct request)
1133 {
1134 ExportTextureResourceRequest req = ExportTextureResourceRequest.Cast(request);
1135 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
1136
1137 string resourcePath = "";
1138
1139 if (req.sourcePath == "")
1140 {
1141 return ResourceInfo(
1142 InfoStatus.ERROR,
1143 string.Empty,
1144 string.Empty,
1145 string.Format("Resource could not be registered (Missing source path!): %1", resourcePath),
1146 null);
1147 }
1148
1149 else if (req.destinationPath == "")
1150 {
1151 return ResourceInfo(
1152 InfoStatus.ERROR,
1153 string.Empty,
1154 string.Empty,
1155 string.Format("Resource could not be registered (Missing destination path!): %1", resourcePath),
1156 null);
1157 }
1158
1159 else if (req.sourcePath == req.destinationPath)
1160 {
1161 resourcePath = req.sourcePath;
1162 }
1163 else
1164 {
1165 FileIO.CopyFile(req.sourcePath, req.destinationPath);
1166 resourcePath = req.destinationPath;
1167 }
1168
1169 // TODO: check if path is in project
1170 // TODO: do not copy if destination is outside of project
1171
1172 MetaFile meta = resourceManager.GetMetaFile(resourcePath);
1173
1174 if (!meta)
1175 {
1176 if (resourceManager.RegisterResourceFile(resourcePath, false))
1177 meta = resourceManager.GetMetaFile(resourcePath);
1178
1179 if (!meta)
1180 {
1181 return ResourceInfo(
1182 InfoStatus.ERROR,
1183 string.Empty,
1184 string.Empty,
1185 string.Format("Resource could not be registered: %1", resourcePath),
1186 null);
1187 }
1188 }
1189
1190 TextureTypes textureTypes = new TextureTypes();
1191 textureTypes.DoChecks(TextureIssueOp.Fix, meta.GetResourceID(), meta);
1192 meta.Save();
1193
1194 resourceManager.RebuildResourceFile(resourcePath, "PC", false);
1195 return ResourceInfo.CreateFromResourceAbsolutePath(resourcePath);
1196 }
1197}
1198
1199/*
1200 GENERAL IMPORT
1201*/
1202
1203class RegisterResourceRequest : JsonApiStruct
1204{
1205 ref array<string> path = new array<string>;
1206
1207 void RegisterResourceRequest()
1208 {
1209 RegV("path");
1210 }
1211}
1212
1213class RegisterResourceResponse : JsonApiStruct
1214{
1215 bool Output;
1216
1217 void RegisterResourceResponse()
1218 {
1219 RegV("Output");
1220 }
1221}
1222
1223class RegisterResource : NetApiHandler
1224{
1225 //----------------------------------------------------------------------------------------------
1226 override JsonApiStruct GetRequest()
1227 {
1228 return new RegisterResourceRequest();
1229 }
1230
1231 bool Register(string absPath)
1232 {
1233 ResourceManager rm = Workbench.GetModule(ResourceManager);
1234 MetaFile meta = rm.GetMetaFile(absPath);
1235
1236 // check if meta doesnt exist already
1237 if (!meta)
1238 {
1239 // create if not
1240 if (rm.RegisterResourceFile(absPath, false))
1241 meta = rm.GetMetaFile(absPath);
1242
1243 // if creation was not succesful
1244 if (!meta)
1245 return false;
1246
1247 // build xob file if registration was successful
1248 rm.RebuildResourceFile(absPath, "PC", true);
1249 }
1250
1251 // Overwrite meta file configs
1252 BaseContainerList configurations = meta.GetObjectArray("Configurations");
1253 BaseContainer cfg = configurations.Get(0);
1254
1255 // For texture
1256 if (IsImage(configurations[0].GetClassName()))
1257 {
1258 TextureTypes textureTypes = new TextureTypes();
1259 textureTypes.DoChecks(TextureIssueOp.Fix, meta.GetResourceID(), meta);
1260 meta.Save();
1261 return true;
1262 }
1263
1264 return true;
1265 }
1266
1267 //----------------------------------------------------------------------------------------------
1268 override JsonApiStruct GetResponse(JsonApiStruct request)
1269 {
1270 RegisterResourceRequest req = RegisterResourceRequest.Cast(request);
1271 RegisterResourceResponse response = new RegisterResourceResponse();
1272
1273 // for each export path
1274 for (int i = 0; i < req.path.Count(); i++)
1275 {
1276 response.Output = Register(req.path[i]);
1277 }
1278 return response;
1279 }
1280}
string path
override JsonApiStruct GetResponse(JsonApiStruct request)
ExportTerrainRequest Output
PrefabImporterRequest status
string message
BlendMode
Definition ResourceInfo.c:5
@ Additive
Definition ResourceInfo.c:9
@ AlphaBlend
Definition ResourceInfo.c:8
@ ColorModulate
Definition ResourceInfo.c:7
enum BlendMode ccw
SCR_AICombatMoveRequestBase GetRequest()
ResourceName resourceName
Definition SCR_AIGroup.c:66
override void OnPack()
EDamageType type
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
SCR_RespawnComponentClass OK
Result code for request/assign response.
Definition EMoveError.c:14
MetaEddsConversion
TextureIssueOp
base classes for filtering in server browser
MineManagerComponentClass GenericComponentClass Register(notnull IEntity mine, IEntity mineSpawner)
Registers the given mine entity. The mine spawner will add it's awareness to it's faction of this min...
DataVarType
Definition DataVarType.c:18
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
@ ERROR
Same as DELETE, but global error count for OnAfterLoad is affected.
Definition LogLevel.c:20