Skip to content

Conversation

@marklundin
Copy link
Member

@marklundin marklundin commented Oct 21, 2025

This PR introduces a declarative <MeshInstance/> component providing a React-level abstraction over the engines MeshInstance. It mirrors the underlying engine behaviour while fitting into the existing <Entity> / <Render>hierarchy.

This will be necessary to support a better API for loading assets.

Features

  • Lifecycle management – Creates and destroys a MeshInstance automatically when mounted or unmounted.
  • Parent integration – Attaches to the nearest component’s meshInstances array.
  • Morph targets – Supports morph weights via setWeight(index, value).
  • Skinning – Allows passing an existing pc.SkinInstance.
  • Instancing – Supports both:
    • pre-created VertexBuffer
    • raw Float32Array matrix data (with auto-created buffer)
  • Automatically cleans up GPU buffers created internally.
  • Validation – Uses the shared schema system for type-safe prop validation.
  • Test
  • Examples

Example

<Entity>
 <Render>
   <MeshInstance mesh={mesh} material={material} />
 </Render>
</Entity>

with instancing

const matrices = new Float32Array(count * 16);

<Entity>
  <Render>
    <MeshInstance mesh={mesh} material={material} instancing={{ matrices, count }} />
  </Render>
</Entity>

…ing support

- Refactored MeshInstance to include support for morph weights and skin instances.
- Added instancing capabilities with vertex buffer and matrix options.
- Improved validation schema for props, ensuring type safety and error messaging.
- Updated internal implementation to manage lifecycle and rendering more effectively.
…registration

- Removed the mesh instance registration logic and context provider from RenderComponent.
- Updated the component to directly use the props for rendering without additional state management.
- Retained the container rendering logic for asset types.
@marklundin marklundin self-assigned this Oct 21, 2025
@marklundin marklundin added enhancement New feature or request React labels Oct 21, 2025
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: 5c4072e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@playcanvas/react Minor
@playcanvas/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request React

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants