Hey.
Maybe someone can help me - I want to build something like here in this exapmle three.js examples
I just copy the source and try to add GLTFLoader my Logo what i have build in C4D and export as glb singel object file. So far so good. I see my object and also the shader but I can’t handle the update of the camera.position to the matrial camera positon - without that I don’t have the original effect like in the example. As you see in my added screenshot it does not look like in the example
Here is my code for loading the 3d model
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { ImprovedNoise } from 'three/addons/math/ImprovedNoise.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import WebGL from 'three/addons/capabilities/WebGL.js';
if (WebGL.isWebGL2Available() === false) {
document.body.appendChild(WebGL.getWebGL2ErrorMessage());
}
let renderer, scene, camera;
let mesh;
init();
function init() {
//REST like in example
mesh = new GLTFLoader();
mesh.load('public/Logo.glb', function (gltf) {
mesh = gltf.scene;
mesh.traverse(function (object) {
object.material = new THREE.RawShaderMaterial({
glslVersion: THREE.GLSL3,
uniforms: {
map: { value: texture },
cameraPos: { value: new THREE.Vector3() },
threshold: { value: 0.6 },
steps: { value: 200 }
},
vertexShader,
fragmentShader,
side: THREE.BackSide
});
if (object.isMesh) object.castShadow = true;
});
mesh.scale.set(0.01, 0.01, 0.01);
scene.add(mesh);
animate()
});
const parameters = { threshold: 0.6, steps: 200 };
function update() {
mesh.traverse(function (object) {
object.material.uniforms.threshold.value = parameters.threshold;
object.material.uniforms.steps.value = parameters.steps;
});
}
const gui = new GUI();
gui.add(parameters, 'threshold', 0, 1, 0.01).onChange(update);
gui.add(parameters, 'steps', 0, 300, 1).onChange(update);
window.addEventListener('resize', onWindowResize);
}
Also my animate() - Where i have some test code in it.
function animate() {
requestAnimationFrame(animate);
mesh.traverse(function (object) {
// object.material.uniforms.cameraPos.value.copy(camera.position);
// with that the model disappear nut no error in the dev tool
});
if (mesh.material && mesh.material.uniforms.cameraPos) {
mesh.material.uniforms.cameraPos.value.copy(camera.position);
}
// mesh.material.uniforms.cameraPos.value.copy(camera.position);
renderer.render(scene, camera);
}
Hope someone give me a hint