MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / SaveToStream

Function SaveToStream

src/Nazara/Utility/Formats/OBJSaver.cpp:60–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 }
59
60 bool SaveToStream(const Mesh& mesh, const String& format, Stream& stream, const MeshParams& parameters)
61 {
62 NazaraUnused(parameters);
63
64 if (!mesh.IsValid())
65 {
66 NazaraError("Invalid mesh");
67 return false;
68 }
69
70 if (mesh.IsAnimable())
71 {
72 NazaraError("An animated mesh cannot be saved to " + format + " format");
73 return false;
74 }
75
76 UInt32 worstCacheVertexCount = mesh.GetVertexCount();
77 OBJParser objFormat;
78 objFormat.SetNormalCount(worstCacheVertexCount);
79 objFormat.SetPositionCount(worstCacheVertexCount);
80 objFormat.SetTexCoordCount(worstCacheVertexCount);
81
82 String mtlPath = stream.GetPath();
83 if (!mtlPath.IsEmpty())
84 {
85 mtlPath.Replace(".obj", ".mtl");
86 String fileName = mtlPath.SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true);
87 if (!fileName.IsEmpty())
88 objFormat.SetMtlLib(fileName);
89 }
90
91 VertexCache<Vector3f> normalCache(objFormat.GetNormals());
92 VertexCache<Vector4f> positionCache(objFormat.GetPositions());
93 VertexCache<Vector3f> texCoordsCache(objFormat.GetTexCoords());
94
95 // Materials
96 MTLParser mtlFormat;
97 std::unordered_set<String> registredMaterials;
98
99 UInt32 matCount = mesh.GetMaterialCount();
100 String* materialNames = objFormat.SetMaterialCount(matCount);
101 for (UInt32 i = 0; i < matCount; ++i)
102 {
103 const ParameterList& matData = mesh.GetMaterialData(i);
104
105 String name;
106 if (!matData.GetStringParameter(MaterialData::Name, &name))
107 name = "material_" + String::Number(i);
108
109 // Makes sure we only have one material of that name
110 while (registredMaterials.find(name) != registredMaterials.end())
111 name += '_';
112
113 registredMaterials.insert(name);
114 materialNames[i] = name;
115
116 MTLParser::Material* material = mtlFormat.AddMaterial(name);
117

Callers

nothing calls this directly

Calls 15

IsAnimableMethod · 0.80
IsEmptyMethod · 0.80
SubStringFromMethod · 0.80
GetMaterialCountMethod · 0.80
SetMaterialCountMethod · 0.80
GetStringParameterMethod · 0.80
GetColorParameterMethod · 0.80
GetDoubleParameterMethod · 0.80
GetSubMeshCountMethod · 0.80
GetSubMeshMethod · 0.80
GetMaterialIndexMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected