removed texture.js material.js (replaced with uvscroll)

This commit is contained in:
Leon van Kammen 2023-10-27 14:37:20 +02:00
parent 997173adb8
commit 5fa3e62627
5 changed files with 22 additions and 70 deletions

View file

@ -212,7 +212,7 @@ Supported popular compatible 3D fileformats: `.gltf`, `.obj`, `.fbx`, `.usdz`, `
> NOTE: XR Fragments are optional but also file- and protocol-agnostic, which means that programmatic 3D scene(nodes) can also use the mechanism/metadata. > NOTE: XR Fragments are optional but also file- and protocol-agnostic, which means that programmatic 3D scene(nodes) can also use the mechanism/metadata.
## Dynamic XR Fragments (databindings) ## Dynamic XR Fragments (+databindings)
These are automatic fragment-to-metadata mappings, which only trigger if the 3D scene metadata matches a specific identifier (`aliasname` e.g.) These are automatic fragment-to-metadata mappings, which only trigger if the 3D scene metadata matches a specific identifier (`aliasname` e.g.)
@ -221,11 +221,7 @@ These are automatic fragment-to-metadata mappings, which only trigger if the 3D
| `#<aliasname>` | string | `#cubes` | evaluate predefined views (`#cubes: #foo&bar` e.g.) | | `#<aliasname>` | string | `#cubes` | evaluate predefined views (`#cubes: #foo&bar` e.g.) |
| `#<tag_or_objectname>` | string | `#person` | focus object(s) with `tag: person` or name `person` by looking up XRWG | | `#<tag_or_objectname>` | string | `#person` | focus object(s) with `tag: person` or name `person` by looking up XRWG |
| `#<cameraname>` | string | `#cam01` | set camera as active camera | | `#<cameraname>` | string | `#cam01` | set camera as active camera |
| `#<objectname_with_src=x,x,x`| vector3 | `#person=1,1,0` | play src-metadata of object `person` using `#t=` timeline-value (see #t)| | `#<objectname>=x,y` | string | `#sky=0,0.5` | set scroll-position of object by offsetting (uv) coordinates (uv scrolling)|
| `#<animname>=x,x,x` | vector3 | `#myanim=1,1,0` | play (non-global) animation ID |
| `#<materialname>=<x,x,x|animationname>`| string | `horizon=fader` | animate o(pacity) of material `horizon` with `fader` obj (xyzw=o...) |
| `#<texturename>=<x,x,x|animationname>`| string | `page=scroller` | animate x/y/r(otation) of texture `page` with `scroller` object (xyz=xyr) |
| `#<varname>=<x,x,x|string>` | string|vector3 | `myvar=fader` | set/animate shaderuniform- or scene-specific vars with `fader` object (*) |
# Spatial Referencing 3D # Spatial Referencing 3D

View file

@ -1,32 +0,0 @@
xrf.addEventListener('dynamicKeyValue', (opts) => {
let {scene,match,v} = opts
let material = v.fragment
const setMaterial = (mesh,v) => {
let mat = mesh.material
mat.transparent = v.x < 1.0
mat.opacity = v.x
}
console.dir(v)
scene.traverse( (mesh) => {
if( mesh.material){
if( mesh.material && mesh.material.name == material ){
delete mesh.onBeforeRender
delete mesh.driver
let opacity = v.float || v.x
if( opacity != undefined ){
setMaterial( mesh, {x:opacity})
}else{
mesh.driver = xrf.scene.getObjectByName(v.string)
if( !mesh.driver ) return
mesh.onBeforeRender = function(){
let model = xrf.model
if( !model || !model.clock ) return
setMaterial( this, this.driver.position )
}
}
}
}
})
})

View file

@ -1,32 +0,0 @@
xrf.addEventListener('dynamicKeyValue', (opts) => {
let {scene,match,v} = opts
let texture = v.fragment
let found = false
scene.traverse( (mesh) => {
if( mesh.material && !found ){
if( mesh.material.map && mesh.material.map.name == texture ){
found = true
let mat = mesh.material
// remove render listener if any
if( mesh.material.map.removeListener ) mesh.material.map.removeListener()
if( v.x != undefined ){
delete mesh.onBeforeRender
mat.map.offset.x = v.x
mat.map.offset.y = v.y
mat.map.rotation = v.z
}else{
mesh.driver = xrf.model.animations.find( (a) => a.name == v.string )
if( !mesh.driver ) return
let everyFrame = (mesh) => () => {
let value = mesh.driver.action._propertyBindings[0].binding.resolvedProperty
mesh.material.map.offset.x = value.x
mesh.material.map.offset.y = value.y
mesh.material.map.rotation = value.z
}
mesh.material.map.removeListener = xrf.addEventListener('render', everyFrame(mesh) )
}
}
}
})
})

View file

@ -0,0 +1,16 @@
xrf.addEventListener('dynamicKeyValue', (opts) => {
let {scene,match,v} = opts
let objname = v.fragment
scene.traverse( (mesh) => {
if( mesh.name == objname ){
if( !mesh.geometry ) return console.warn(`mesh '${objname}' has no uvcoordinates to offset`)
let uv = mesh.geometry.getAttribute("uv")
if( !uv.old ) uv.old = uv.clone()
for( let i = 0; i < uv.count; i++ ){
uv.setXY(i, uv.old.getX(i) + v.x, uv.old.getY(i) + v.y )
}
uv.needsUpdate = true
}
})
})

View file

@ -60,6 +60,8 @@ xrf.frag.src.type['image/png'] = function(url,opts){
} }
let renderImage = (texture) => { let renderImage = (texture) => {
let img = {w: texture.source.data.width, h: texture.source.data.height}
// stretch image by pinning uv-coordinates to corners // stretch image by pinning uv-coordinates to corners
if( mesh.geometry ){ if( mesh.geometry ){
if( mesh.geometry.attributes.uv ){ // buffergeometries if( mesh.geometry.attributes.uv ){ // buffergeometries
@ -88,6 +90,8 @@ xrf.frag.src.type['image/png'] = function(url,opts){
let onLoad = (texture) => { let onLoad = (texture) => {
texture.colorSpace = THREE.SRGBColorSpace; texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
// detect equirectangular image // detect equirectangular image
if( texture && texture.source.data.height == texture.source.data.width/2 ){ if( texture && texture.source.data.height == texture.source.data.width/2 ){
renderEquirect(texture) renderEquirect(texture)