Izzimach / react-three-legacy

React bindings to create and control a 3D scene using three.js
Other
1.52k stars 128 forks source link

Example on using loaded models #81

Closed edzis closed 8 years ago

edzis commented 8 years ago

I need to load geometries dynamically (doing that using OBJLoader) and fail to understand how to get my resulting THREE.Group instances into the tree. Could you please share these insights?

Izzimach commented 8 years ago

There really isn't a good way to splice an already-built Object3D into the React-generated scene graph. The best I can do is suggest two possible hacks:

  1. If your loaded object is just a THREE.Mesh you can pull out the geometry and material and pass those into a <Mesh> component.
  2. React refs give you access to the native object, so you could manually call add on a node to add your nodes as children. You would render something like <Object3D ref='splicepoint'> and then reactinstance.refs['splicepoint'] would give you the THREE.Object3D that was created. This is done in the tests to examine underlying threejs objects.