simplified #pos.js and bugfixed envmapping.js

This commit is contained in:
Leon van Kammen 2024-10-14 11:54:14 +02:00
parent b7f3c91b7f
commit 0bd37a3b30
2 changed files with 3 additions and 5 deletions

View File

@ -9,9 +9,10 @@ xrf.addEventListener('navigateLoaded', (opts) => {
// Recursive function to traverse the graph // Recursive function to traverse the graph
function traverseAndSetEnvMap(node, closestAncestorMaterialMap = null) { function traverseAndSetEnvMap(node, closestAncestorMaterialMap = null) {
// Check if the current node has a material // Check if the current node has a material
if (node.isMesh && node.material) { if (node.isMesh && node.material ) {
if (node.material.map && closestAncestorMaterialMap) { if (node.material.map && closestAncestorMaterialMap) {
// If the node has a material map, set the closest ancestor material map // If the node has a material map, set the closest ancestor material map
node.material = node.material.clone() // dont affect objects which share same material
node.material.envMap = closestAncestorMaterialMap; node.material.envMap = closestAncestorMaterialMap;
} }
} }

View File

@ -6,10 +6,7 @@ xrf.frag.pos = function(v, opts){
if( pos.x == undefined ){ if( pos.x == undefined ){
let obj = scene.getObjectByName(v.string) let obj = scene.getObjectByName(v.string)
if( !obj ) return console.warn("#pos="+v.string+" not found") if( !obj ) return console.warn("#pos="+v.string+" not found")
let worldPos = new THREE.Vector3() obj.add(camera)
obj.getWorldPosition(worldPos)
camera.position.copy(worldPos)
obj.attach(camera) // instead of add() [keeps camera animations intact]
camera.position.set(0,0,0) camera.position.set(0,0,0)
let c = camera.rotation let c = camera.rotation
c.set( c.x, obj.rotation.y, c.z ) c.set( c.x, obj.rotation.y, c.z )