Hello,
I am new, but I need a starter tip, how do you handle debugging in studio? I am writing a video shader, and some other custom components for the experience I am building.
But I have a hard time setting properties. and wanted to log. but console.log() is not working. please help.
import * as ecs from '@8thwall/ecs'
const {THREE, XR8} = window as any
let material = null
ecs.registerComponent({
name: 'video-shader',
schema: {
videoUrl: ecs.string,
},
schemaDefaults: {
videoUrl: 'what_is_on_the_edge.mp3',
},
data: {
time: ecs.f32,
},
add: (world, component) => {
ecs.Material.remove(world, component.eid)
const object = world.three.entityToObject.get(component.eid)
const videoUrl = 'blank'
// Create video element and texture
const video = document.createElement('video')
video.src = 'what_is_on_the_edge.mp3' // Replace with your video path
video.loop = true
video.muted = true
video.play()
const videoTexture = new THREE.VideoTexture(video)
videoTexture.minFilter = THREE.LinearFilter
videoTexture.magFilter = THREE.LinearFilter
videoTexture.format = THREE.RGBFormat
material = new THREE.ShaderMaterial({
uniforms: {
time: {value: 0},
videoTexture: {value: videoTexture},
},
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
}
`,
fragmentShader: `
uniform float time;
uniform sampler2D videoTexture;
varying vec2 vUv;
void main(void) {
vec4 videoColor = texture2D(videoTexture, vUv);
float brightness = 0.5 + 0.5 * sin(time);
gl_FragColor = vec4(videoColor.rgb * brightness, videoColor.a);
}
`,
})
object.material = material
object.traverse((node) => {
if (node.isMesh) {
node.material = material
}
})
window.addEventListener('click', XR8.XrController.recenter)
window.addEventListener('touchstart', XR8.XrController.recenter)
},
tick: (world, component) => {
material.uniforms.time.value = world.time.elapsed * 0.001
},
remove: (world, component) => {
// Cleanup logic if needed
},
})