2023-05-12 22:06:21 +02:00
|
|
|
// *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
|
2023-05-08 14:21:28 +02:00
|
|
|
console.log(" └ instancing src")
|
2023-05-12 22:06:21 +02:00
|
|
|
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();
|
2023-05-12 22:06:21 +02:00
|
|
|
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
|
2023-05-12 22:06:21 +02:00
|
|
|
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
|
2023-05-12 22:06:21 +02:00
|
|
|
model.scene.add(modelInstance);
|
2023-05-05 18:53:42 +02:00
|
|
|
}
|
|
|
|
|
}
|