question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change InstancedMesh api signature to count, geom, mat

See original GitHub issue
Description 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:closed
  • Created 4 years ago
  • Comments:18 (13 by maintainers)

github_iconTop GitHub Comments

5reactions
donmccurdycommented, Oct 14, 2019

@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.

2reactions
drcmdacommented, Oct 11, 2019

i think defaults coming last and required vars first is a standard? in typescript for instance:

Screenshot 2019-10-11 at 23 29 11

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found