public virtual bool check_key_or_debug_print(TypedAttribSet attributes, string sKey) { if (attributes.ContainsKey(sKey) == false) { emit_message("attribute " + sKey + " is missing"); return(false); } else { return(true); } }
public virtual SceneObject Build(FScene scene, SceneSerializer serializer, TypedAttribSet attributes) { message_prefix = "[UnitySOFactory.Build]"; if (attributes.ContainsKey(IOStrings.ASOType) == false) { emit_message("SO Type is missing"); return(null); } string typeIdentifier = attributes[IOStrings.ASOType] as string; message_prefix += " " + typeIdentifier; SceneObject so = BuildSOFromType(typeIdentifier, scene, serializer, attributes); if (so == null) { emit_message("builder not implemented!"); } return(so); }
public virtual DMesh3 RestoreDMesh(TypedAttribSet attributes) { bool is_compressed = false; TypedAttribSet meshAttr = find_struct(attributes, IOStrings.BinaryDMeshStruct); if (meshAttr == null) { meshAttr = find_struct(attributes, IOStrings.CompressedDMeshStruct); is_compressed = true; } if (meshAttr == null) { throw new Exception("SOFactory.RestoreDMesh: DMesh binary or compressed struct not found!"); } VectorArray3d v = null; VectorArray3f n = null, c = null; VectorArray2f uv = null; VectorArray3i t = null; int[] g = null; IndexArray4i e = null; short[] e_ref = null; var storageMode = IOStrings.MeshStorageMode.EdgeRefCounts; if (meshAttr.ContainsKey(IOStrings.AMeshStorageMode)) { storageMode = (IOStrings.MeshStorageMode)(int) meshAttr[IOStrings.AMeshStorageMode]; } if (is_compressed) { if (check_key_or_debug_print(meshAttr, IOStrings.AMeshVertices3Compressed)) { v = meshAttr[IOStrings.AMeshVertices3Compressed] as VectorArray3d; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshNormals3Compressed)) { n = meshAttr[IOStrings.AMeshNormals3Compressed] as VectorArray3f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshColors3Compressed)) { c = meshAttr[IOStrings.AMeshColors3Compressed] as VectorArray3f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshUVs2Compressed)) { uv = meshAttr[IOStrings.AMeshUVs2Compressed] as VectorArray2f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTrianglesCompressed)) { t = meshAttr[IOStrings.AMeshTrianglesCompressed] as VectorArray3i; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTriangleGroupsCompressed)) { g = meshAttr[IOStrings.AMeshTriangleGroupsCompressed] as int[]; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshEdgesCompressed)) { e = meshAttr[IOStrings.AMeshEdgesCompressed] as IndexArray4i; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshEdgeRefCountsCompressed)) { e_ref = meshAttr[IOStrings.AMeshEdgeRefCountsCompressed] as short[]; } } else { if (check_key_or_debug_print(meshAttr, IOStrings.AMeshVertices3Binary)) { v = meshAttr[IOStrings.AMeshVertices3Binary] as VectorArray3d; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshNormals3Binary)) { n = meshAttr[IOStrings.AMeshNormals3Binary] as VectorArray3f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshColors3Binary)) { c = meshAttr[IOStrings.AMeshColors3Binary] as VectorArray3f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshUVs2Binary)) { uv = meshAttr[IOStrings.AMeshUVs2Binary] as VectorArray2f; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTrianglesBinary)) { t = meshAttr[IOStrings.AMeshTrianglesBinary] as VectorArray3i; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshTriangleGroupsBinary)) { g = meshAttr[IOStrings.AMeshTriangleGroupsBinary] as int[]; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshEdgesBinary)) { e = meshAttr[IOStrings.AMeshEdgesBinary] as IndexArray4i; } if (check_key_or_debug_print(meshAttr, IOStrings.AMeshEdgeRefCountsBinary)) { e_ref = meshAttr[IOStrings.AMeshEdgeRefCountsBinary] as short[]; } } DMesh3 m = new DMesh3(); if (n != null) { m.EnableVertexNormals(Vector3f.Zero); } if (c != null) { m.EnableVertexColors(Vector3f.Zero); } if (uv != null) { m.EnableVertexUVs(Vector2f.Zero); } if (g != null) { m.EnableTriangleGroups(0); } if (storageMode == IOStrings.MeshStorageMode.EdgeRefCounts) { if (v == null || t == null || e == null || e_ref == null) { return(null); } m.VerticesBuffer = new DVector <double>(v); if (n != null) { m.NormalsBuffer = new DVector <float>(n); } if (c != null) { m.ColorsBuffer = new DVector <float>(c); } if (uv != null) { m.UVBuffer = new DVector <float>(uv); } m.TrianglesBuffer = new DVector <int>(t); if (g != null) { m.GroupsBuffer = new DVector <int>(g); } m.EdgesBuffer = new DVector <int>(e); m.EdgesRefCounts = new RefCountVector(e_ref); m.RebuildFromEdgeRefcounts(); } else if (storageMode == IOStrings.MeshStorageMode.Minimal) { if (v == null || t == null) { return(null); } int NV = v.Count; NewVertexInfo vinfo = new NewVertexInfo(); for (int k = 0; k < NV; ++k) { vinfo.v = v[k]; if (n != null) { vinfo.n = n[k]; } if (c != null) { vinfo.c = c[k]; } if (uv != null) { vinfo.uv = uv[k]; } m.AppendVertex(ref vinfo); } int NT = t.Count; for (int k = 0; k < NT; ++k) { Vector3i tri = t[k]; int setg = (g == null) ? -1 : g[k]; m.AppendTriangle(tri, setg); } } else { throw new Exception("SOFactory.RestoreDMesh: unsupported mesh storage mode"); } return(m); }