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.

sharing textures/materials/geometries

See original GitHub issue

Sorry 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
greggmancommented, Mar 27, 2019

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

2reactions
drcmdacommented, Mar 21, 2019

One idea i had would maybe allow them to call into a render child, if they detect one, so you could do

<meshBasicMaterial color={color}>
  {material => (
    <mesh material={material} />
    <mesh material={material} />
    <mesh material={material} />
  )}
</meshBasicMaterial>

That would solve it, and even take care of deeply nested re-use.

Read more comments on GitHub >

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

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