Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix primitive node picking non existant primitive and mesh indexes #195

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/render/coregraphics/meshloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class MeshLoader : public Resources::ResourceLoader

/// setup mesh from nvx3 file in memory
void SetupMeshFromNvx(const Ptr<IO::Stream>& stream, const MeshResourceId entry);

};

} // namespace CoreGraphics
17 changes: 14 additions & 3 deletions code/render/models/nodes/primitivenode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,23 @@ PrimitiveNode::Load(const Util::FourCC& fourcc, const Util::StringAtom& tag, con

// Load directly, since the model is already loaded on a thread, this is fine
//this->primitiveGroupIndex = 0;
this->res = Resources::CreateResource(meshName, tag, nullptr, nullptr, true);
this->res = Resources::CreateResource(
meshName,
tag,
[this](Resources::ResourceId)
{
this->loadSuccess = true;
},
nullptr,
true
);

}
else if (FourCC('MSHI') == fourcc)
{
CoreGraphics::MeshResourceId meshRes = this->res;
IndexT meshIndex = reader->ReadUInt();
uint index = reader->ReadUInt();
IndexT meshIndex = this->loadSuccess ? index : 0;
this->mesh = MeshResourceGetMesh(meshRes, meshIndex);

this->vbo = CoreGraphics::MeshGetVertexBuffer(this->mesh, 0);
Expand All @@ -66,7 +76,8 @@ PrimitiveNode::Load(const Util::FourCC& fourcc, const Util::StringAtom& tag, con
else if (FourCC('PGRI') == fourcc)
{
// primitive group index
this->primitiveGroupIndex = reader->ReadUInt();
uint index = reader->ReadUInt();
this->primitiveGroupIndex = this->loadSuccess ? index : 0;
this->primGroup = CoreGraphics::MeshGetPrimitiveGroups(this->mesh)[this->primitiveGroupIndex];
}
else
Expand Down
1 change: 1 addition & 0 deletions code/render/models/nodes/primitivenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PrimitiveNode : public ShaderStateNode
Resources::ResourceId res;
CoreGraphics::MeshId mesh;
uint16_t primitiveGroupIndex;
bool loadSuccess = false;

CoreGraphics::BufferId vbo, ibo;
IndexT baseVboOffset, attributesVboOffset, iboOffset;
Expand Down
2 changes: 1 addition & 1 deletion code/resource/resources/resourceloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ResourceLoader : public Core::RefCounted
Util::FixedArray<_PlaceholderResource> placeholders;

/// get placeholder based on resource name
virtual Resources::ResourceId GetPlaceholder(const Resources::ResourceName& name);
Resources::ResourceId GetPlaceholder(const Resources::ResourceName& name);

/// these types need to be properly initiated in a subclass Setup function
Util::StringAtom placeholderResourceName;
Expand Down
Loading