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

31 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-05 18:53:42 +02:00
xrfragment.xrf.src = function(v, opts){
let { mesh, model, camera, scene, renderer, THREE} = opts
if( v.string[0] == "#" ){ // local
console.log(" └ instancing src")
2023-05-05 18:53:42 +02:00
let args = xrfragment.URI.parse(v.string)
// Get an instance of the original model
const modelInstance = new THREE.Group();
modelInstance.add(model.scene.clone());
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
// *TODO* move to a central location (pull-up)
for( var i in args ){
if( i == "scale" ){
console.log(" └ setting scale")
2023-05-05 18:53:42 +02:00
modelInstance.scale.x = args[i].x
modelInstance.scale.y = args[i].y
modelInstance.scale.z = args[i].z
}
}
// Add the instance to the scene
scene.add(modelInstance);
console.dir(model)
console.dir(modelInstance)
}
}