Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
TRES.JS-¿Cómo puedo agregar sombras para mi modelo GLTF?

Soy nuevo en Three.js. Me preguntaba cómo puedo hacer que mi modelo GLTF proyecte una sombra sobre sí mismo. He estado probando cosas diferentes, sin embargo, no estoy seguro de si lo estoy haciendo bien. La luz es una PointLight y la cámara es Perspective IDK si es importante, por favor dígame. Aquí está el código. Por favor y gracias :)


 var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1000 ); //camera.rotation.x=-20*Math.PI/180; var renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); renderer.shadowMap.enabled = true; document.body.appendChild(renderer.domElement); window.addEventListener('resize', () => { renderer.setSize(window.innerWidth, window.innerHeight); camera.aspect = window.innerWidth/ window.innerHeight; camera.updateProjectMatrix(); }); function mousemovement(event) { const mouseX = (event.clientX / window.innerWidth) * 2 - 1; const mouseY = -(event.clientY / window.innerHeight) * 2 + 1; light.position.x = mouseX * 11 + 2 ; light.position.y = mouseY * 4 + 4.5 ; }; var numberofclicks = 2; window.addEventListener('mousemove', mousemovement); window.addEventListener('click', e =>{ numberofclicks = numberofclicks + 1; if(numberofclicks % 2 == 0) { window.addEventListener('mousemove', mousemovement); } else { window.removeEventListener('mousemove', mousemovement); } }); //GLTF moldal var loader = new GLTFLoader(); loader.load("wrktblv2.gltf", function (gltf) { loader.castShadow = true; loader.receiveShadow = true; scene.add(gltf.scene); }); var light = new THREE.PointLight(0xffffff, 2, 20); light.position.set(1,10,2) scene.add(light); camera.position.set(2,3,9); //const lightHelper = new THREE.PointLightHelper(light); //const gridHelper = new THREE.GridHelper(200,50); //scene.add(lightHelper, gridHelper); function animate(){ requestAnimationFrame(animate); renderer.render(scene,camera); } animate();

Nuevamente gracias y saludos!


Editar: obtuve algo de ayuda, hay sombras, pero ahora hay un problema.


La cuestión.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente agregar light.castShadow = true . Además, no debes proyectar sombras en el cargador, sino en cada malla. así que reemplaza

 loader.castShadow = true; loader.receiveShadow = true;

con

 gltf.scene.traverse(function(child) { if (child.isMesh) { child.castShadow = true; child.receiveShadow = true; } })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!