sharing textures/materials/geometries
See original GitHub issueSorry if this is noob question but how do I share textures, materials, and geometry?
In normal three.js I can do this
const texture = loader.load('someurl');
const material = new THREE.MeshBasicMaterial({map: texture});
const geometry = new THREE.BoxBufferGeometry(1, 1, 1);
const m1 = new THREE.Mesh(geometry, material);
const m2 = new THREE.Mesh(geometry, material);
const m3 = new THREE.Mesh(geometry, material);
const m4 = new THREE.Mesh(geometry, material);
m1.position.x = -2;
m2.position.x = -1;
m3.position.x = 1;
m4.position.x = 2;
scene.add(m1);
scene.add(m2);
scene.add(m3);
scene.add(m4);
What’s the equivalent here?
I get the
<group>
<mesh position=...>
<mesh position=...>
<mesh position=...>
<mesh position=...>
</group>
part but I’m not sure I get the rest.
in normal DOM React heavy resources are referred to by URLs and the browser magically manages them so
<div>
<img url="sameUrl" />
<img url="sameUrl" />
<img url="sameUrl" />
<img url="sameUrl" />
</div>
Only actually loads one image into the browser. The browser also knows when that image is safe to free.
It feels like texture, geometry, and materials are kind of the equivalent in three.js but here they’re being treated as DOM elements when in fact they are not part of the hierarchy. Like the actual bits of an image they are outside the hierarchy so it seems confusing to me to make them part of the hierarchy.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:17 (11 by maintainers)
Top Results From Across the Web
Can two SCNNodes with different te… - Apple Developer
At first glance the question seems trivial: Can two SCNNodes, which use geometries with materials using different textures, share the same shader?
Read more >Share Nodes between Geometry Nodes and Material - Reddit
I have a Voronoi texture and Noise texture i would like to use in both geometry nodes and Materials, i have tried making...
Read more >Custom Blocks Part 2: Geometry and Material Instances
Using Blockbench to design custom geometries and textures. Adding block geometries that are different shapes/sizes than 16x16x16.
Read more >How do I transfer an image texture from Geometry Nodes into ...
Is it possible to use an Image Texture inside Geometry Nodes as a texture for Materials? That'd be possible, I think what you're...
Read more >Applying multiple textures to same geometry - Stack Overflow
Mesh(geometry, materials); // Applying this one to faces that need certain material: // https://threejs.org/docs/#api/en/core/BufferGeometry ...
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 Free
Top 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

I get all of that. But it’s a basic tenet of good software design that you don’t mix things that are fundamentally different in the same tree of nodes. Yes, an audio tag might be a strange exception except really not. By default an audio node displays audio controls. An audio node not in the DOM tree is well known wart in the browser and in fact wouldn’t work in react, react will stick in in the tree even though you don’t want it in the tree unless you go to some crazy contortions to prevent it.
A geometry is not a child of a mesh. It’s not, period. It should not be represented as one
One idea i had would maybe allow them to call into a render child, if they detect one, so you could do
That would solve it, and even take care of deeply nested re-use.