@@ -1182,7 +1182,10 @@ struct GeometryDataImpl : GeometryData {
11821182 Vec4Attributes getColors () const override { return patchAttributes<Vec4Attributes>(colors); }
11831183 Vec3Attributes getTangents () const override { return patchAttributes<Vec3Attributes>(tangents); }
11841184 int getPartitionCount () const override { return (int )partitions.size (); }
1185-
1185+
1186+ const int getMaterialMapSize () const override { return (int )materials.size (); }
1187+ const int * getMaterialMap () const override { return materials.empty () ? nullptr : &materials[0 ]; }
1188+
11861189 GeometryPartition getPartition (int index) const override {
11871190 if (index >= partitions.size ()) return {nullptr , 0 , 0 , 0 };
11881191 return {
@@ -3123,26 +3126,28 @@ static OptionalError<Object*> parseAnimationCurve(const Scene& scene, const Elem
31233126 return curve;
31243127}
31253128
3126- static OptionalError<Object*> parseGeometry (const Element& element, GeometryImpl& geom, std::vector<ParseDataJob> &jobs, Allocator& allocator) {
3129+ static OptionalError<Object*> parseGeometry (const Element& element, GeometryImpl& geom, std::vector<ParseDataJob> &jobs, bool ignore_geometry, Allocator& allocator) {
31273130 assert (element.first_property );
31283131
3132+ if (!parseGeometryMaterials (geom, element, jobs)) return Error (" Invalid materials" );
3133+
31293134 const Element* vertices_element = findChild (element, " Vertices" );
3130- if (!vertices_element || !vertices_element->first_property )
3131- {
3135+ if (!vertices_element || !vertices_element->first_property ) {
31323136 return &geom;
31333137 }
31343138
31353139 const Element* polys_element = findChild (element, " PolygonVertexIndex" );
31363140 if (!polys_element || !polys_element->first_property ) return Error (" Indices missing" );
31373141
3138- if (!pushJob (jobs, *vertices_element->first_property , geom.positions .values )) return Error (" Invalid vertices" );
3139- if (!pushJob (jobs, *polys_element->first_property , geom.positions .indices )) return Error (" Invalid vertices" );
3142+ if (!ignore_geometry) {
3143+ if (!pushJob (jobs, *vertices_element->first_property , geom.positions .values )) return Error (" Invalid vertices" );
3144+ if (!pushJob (jobs, *polys_element->first_property , geom.positions .indices )) return Error (" Invalid vertices" );
31403145
3141- if (!parseGeometryMaterials (geom, element, jobs)) return Error (" Invalid materials " );
3142- if (!parseGeometryUVs (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3143- if (!parseGeometryTangents (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3144- if (!parseGeometryColors (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3145- if (! parseGeometryNormals (geom, element, jobs)) return Error ( " Invalid vertex attributes " );
3146+ if (!parseGeometryUVs (geom, element, jobs)) return Error (" Invalid vertex attributes " );
3147+ if (!parseGeometryTangents (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3148+ if (!parseGeometryColors (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3149+ if (!parseGeometryNormals (geom, element, jobs)) return Error (" Invalid vertex attributes" );
3150+ }
31463151
31473152 return &geom;
31483153}
@@ -3406,6 +3411,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
34063411 const bool ignore_limbs = (flags & (u16 )LoadFlags::IGNORE_LIMBS) != 0 ;
34073412 const bool ignore_meshes = (flags & (u16 )LoadFlags::IGNORE_MESHES) != 0 ;
34083413 const bool ignore_models = (flags & (u16 )LoadFlags::IGNORE_MODELS) != 0 ;
3414+ const bool keep_matertial_map = (flags & (u16 )LoadFlags::KEEP_MATERIAL_MAP) != 0 ;
34093415
34103416 const Element* objs = findChild (root, " Objects" );
34113417 if (!objs) return true ;
@@ -3438,18 +3444,20 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
34383444
34393445 if (iter.second .object == scene.m_root ) continue ;
34403446
3441- if (iter.second .element ->id == " Geometry" && !ignore_geometry )
3447+ if (iter.second .element ->id == " Geometry" )
34423448 {
34433449 Property* last_prop = iter.second .element ->first_property ;
34443450 while (last_prop->next ) last_prop = last_prop->next ;
34453451 if (last_prop && last_prop->value == " Mesh" )
34463452 {
34473453 GeometryImpl* geom = allocator.allocate <GeometryImpl>(scene, *iter.second .element );
3448- parseGeometry (*iter.second .element , *geom, jobs, allocator);
3454+ if (!ignore_geometry || keep_matertial_map) {
3455+ parseGeometry (*iter.second .element , *geom, jobs, ignore_geometry, allocator);
3456+ }
34493457 obj = geom;
34503458 scene.m_geometries .push_back (geom);
34513459 }
3452- else if (last_prop && last_prop->value == " Shape" )
3460+ else if (last_prop && last_prop->value == " Shape" && !ignore_geometry )
34533461 {
34543462 obj = allocator.allocate <ShapeImpl>(scene, *iter.second .element );
34553463 }
0 commit comments