Skip to content

Commit 4f9f52c

Browse files
committed
geometry - hasVertices method
1 parent cc02330 commit 4f9f52c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/ofbx.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ struct GeometryPartitionImpl {
11571157
};
11581158

11591159
struct GeometryDataImpl : GeometryData {
1160+
bool has_vertices = false;
11601161
Vec3AttributesImpl positions;
11611162
Vec3AttributesImpl normals;
11621163
Vec3AttributesImpl tangents;
@@ -1176,6 +1177,8 @@ struct GeometryDataImpl : GeometryData {
11761177
return res;
11771178
}
11781179

1180+
bool hasVertices() const override { return has_vertices; }
1181+
11791182
Vec3Attributes getPositions() const override { return positions; }
11801183
Vec3Attributes getNormals() const override { return patchAttributes<Vec3Attributes>(normals); }
11811184
Vec2Attributes getUVs(int index) const override { return patchAttributes<Vec2Attributes>(uvs[index]); }
@@ -3126,16 +3129,22 @@ static OptionalError<Object*> parseAnimationCurve(const Scene& scene, const Elem
31263129
return curve;
31273130
}
31283131

3129-
static OptionalError<Object*> parseGeometry(const Element& element, GeometryImpl& geom, std::vector<ParseDataJob> &jobs, bool ignore_geometry, Allocator& allocator) {
3132+
static OptionalError<Object*> parseGeometry(const Element& element, GeometryImpl& geom, std::vector<ParseDataJob> &jobs, u16 flags, Allocator& allocator) {
31303133
assert(element.first_property);
31313134

3132-
if (!parseGeometryMaterials(geom, element, jobs)) return Error("Invalid materials");
3135+
const bool ignore_geometry = (flags & (u16)LoadFlags::IGNORE_GEOMETRY) != 0;
3136+
const bool keep_matertial_map = (flags & (u16)LoadFlags::KEEP_MATERIAL_MAP) != 0;
3137+
3138+
if (keep_matertial_map || !ignore_geometry) {
3139+
if (!parseGeometryMaterials(geom, element, jobs)) return Error("Invalid materials");
3140+
}
31333141

31343142
const Element* vertices_element = findChild(element, "Vertices");
31353143
if (!vertices_element || !vertices_element->first_property) {
31363144
return &geom;
31373145
}
31383146

3147+
geom.has_vertices = true;
31393148
const Element* polys_element = findChild(element, "PolygonVertexIndex");
31403149
if (!polys_element || !polys_element->first_property) return Error("Indices missing");
31413150

@@ -3451,9 +3460,7 @@ static bool parseObjects(const Element& root, Scene& scene, u16 flags, Allocator
34513460
if (last_prop && last_prop->value == "Mesh")
34523461
{
34533462
GeometryImpl* geom = allocator.allocate<GeometryImpl>(scene, *iter.second.element);
3454-
if (!ignore_geometry || keep_matertial_map) {
3455-
parseGeometry(*iter.second.element, *geom, jobs, ignore_geometry, allocator);
3456-
}
3463+
parseGeometry(*iter.second.element, *geom, jobs, flags, allocator);
34573464
obj = geom;
34583465
scene.m_geometries.push_back(geom);
34593466
}

src/ofbx.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ struct GeometryPartition {
536536
const int triangles_count; // number of triangles after polygon triangulation, can be used for preallocation
537537
};
538538

539+
// if we use LoadFlags::IGNORE_GEOMETRY, values here are empty/invalid, with a few exceptions
539540
struct GeometryData {
540541
virtual ~GeometryData() {}
541542

@@ -544,10 +545,16 @@ struct GeometryData {
544545
virtual Vec2Attributes getUVs(int index = 0) const = 0;
545546
virtual Vec4Attributes getColors() const = 0;
546547
virtual Vec3Attributes getTangents() const = 0;
547-
virtual const int getMaterialMapSize() const = 0;
548-
virtual const int* getMaterialMap() const = 0;
549548
virtual int getPartitionCount() const = 0;
550549
virtual GeometryPartition getPartition(int partition_index) const = 0;
550+
551+
// if we use LoadFlags::KEEP_MATERIAL_MAP, following is valid even if we use IGNORE_GEOMETRY
552+
virtual const int getMaterialMapSize() const = 0;
553+
virtual const int* getMaterialMap() const = 0;
554+
555+
// returns true if there are vertices in the geometry
556+
// this has valid value even if we use LoadFlags::IGNORE_GEOMETRY
557+
virtual bool hasVertices() const = 0;
551558
};
552559

553560

0 commit comments

Comments
 (0)