xrfragment/src/3rd/three/xrf/src.js

25 lines
937 B
JavaScript
Raw Normal View History

// *TODO* use webgl instancing
xrf.frag.src = function(v, opts){
2023-05-05 18:53:42 +02:00
let { mesh, model, camera, scene, renderer, THREE} = opts
if( v.string[0] == "#" ){ // local
console.log(" └ instancing src")
let frag = xrfragment.URI.parse(v.string)
2023-05-05 18:53:42 +02:00
// Get an instance of the original model
const modelInstance = new THREE.Group();
let sceneInstance = model.scene.clone()
modelInstance.add(sceneInstance)
2023-05-09 17:42:29 +02:00
modelInstance.position.z = mesh.position.z
2023-05-05 18:53:42 +02:00
modelInstance.position.y = mesh.position.y
2023-05-09 17:42:29 +02:00
modelInstance.position.x = mesh.position.x
2023-05-05 18:53:42 +02:00
modelInstance.scale.z = mesh.scale.x
modelInstance.scale.y = mesh.scale.y
modelInstance.scale.x = mesh.scale.z
// now apply XR Fragments overrides from URI
for( var i in frag )
xrf.eval.fragment(i, Object.assign(opts,{frag, model:modelInstance,scene:sceneInstance}))
2023-05-05 18:53:42 +02:00
// Add the instance to the scene
model.scene.add(modelInstance);
2023-05-05 18:53:42 +02:00
}
}