Change InstancedMesh api signature to count, geom, mat
See original GitHub issueDescription of the problem
The current signature is unfortunate, since geom and mat have defaults (which means they should be last), but count has to be supplied (it should therefore be first). This causes us some headaches when we need to create an instancedmesh declaratively, like so:
<instancedMesh args={[null, null, count]}>
<sphereBufferGeometry attach="geometry />
<meshBasicMaterial attach="material" />
declarative use or not, this is also weird in the imperative way:
const m = new THREE.InstancedMesh(null, null, count)
m.geometry = ...
m.material = ...
the proposal would be:
new THREE.InstancedMesh(count)
new THREE.InstancedMesh(count, geom)
new THREE.InstancedMesh(count, geom, mat)
which i think is natural, in js and ts alike
(count: number, geom?: THREE.Geometry, mat?: THREE.Material)
examples:
https://codesandbox.io/s/three-fiber-useloader-pjcc1
https://codesandbox.io/s/react-three-fiber-gestures-xj31x?from-embed
The prototype is still very new and hasn’t even been documented. Can we fix this before it’s too late? @mrdoob
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (13 by maintainers)
Top Results From Across the Web
Change InstancedMesh api signature to count, geom, mat
The current signature is unfortunate, since geom and mat have defaults (which means they should be last), but count has to be supplied...
Read more >InstancedMesh#count – three.js docs
The count value passed into the constructor represents the maximum number of instances of this mesh. You can change the number of instances...
Read more >Troubleshooting InstancedMesh in Three.js | by Leanne Werner
According to the Three.js docs, you should use an instancedMesh when creating a lot of objects with the same geometry and material but...
Read more >Unity 2023.1.0a22
Graph Tool Foundation: Changed: Added an API to correctly compute the halo ... large vertex/index counts are rendered first due to batching.
Read more >Unreal Engine 4.14 Release Notes
Unreal Engine now automatically reduces the polygon count of your static meshes to ... widget in the Blueprint Editor, just like Instanced Mesh...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@drcmda for context, many threejs objects (Mesh, Line, LineLoop, LineSegments, Points, SkinnedMesh) share
geometry, material
as the first two arguments. While they aren’t technically required arguments, there are exceedingly few cases where the user would not provide them in the constructor. I think we’re hoping for a solution that maintains consistency with those method signatures.i think defaults coming last and required vars first is a standard? in typescript for instance:
but this is exactly what instancedmesh does, two optionals, followed by a required one. these little dings and dongs are just more visible when you put them into a declarative format.