three.js

How to cast a shadow with a gltf model in three.js?

喜夏-厌秋 提交于 2021-02-20 19:14:13
问题 Hey there i'm new to three js & was wondering how to cast a shadow with a gltf model? I can see it's possible as it's working here I assume i'm not structuring my code correctly- var model = new THREE.GLTFLoader(); model.load('https://threejs.org/examples/models/gltf/Duck/glTF/Duck.gltf', function(gltf) {scene.add(gltf.scene);}); model.castShadow = true; Here's the fiddle https://jsfiddle.net/steveham/ckpfwy24/87/ Cheers! 回答1: You need to set castShadow = true on each child mesh, like so: var

How to cast a shadow with a gltf model in three.js?

懵懂的女人 提交于 2021-02-20 19:14:11
问题 Hey there i'm new to three js & was wondering how to cast a shadow with a gltf model? I can see it's possible as it's working here I assume i'm not structuring my code correctly- var model = new THREE.GLTFLoader(); model.load('https://threejs.org/examples/models/gltf/Duck/glTF/Duck.gltf', function(gltf) {scene.add(gltf.scene);}); model.castShadow = true; Here's the fiddle https://jsfiddle.net/steveham/ckpfwy24/87/ Cheers! 回答1: You need to set castShadow = true on each child mesh, like so: var

THREE.js Change the opacity of an entire branch

梦想与她 提交于 2021-02-18 07:46:32
问题 Is there any way to change the opacity/alpha of all hierarchy (branch) rather than per each mesh material? 回答1: No. You can, however, use object.traverse() to set the opacity of an object's material and it's children. mesh.traverse( function( node ) { if( node.material ) { node.material.opacity = 0.5; node.material.transparent = true; } }); three.js r.56 来源: https://stackoverflow.com/questions/15214543/three-js-change-the-opacity-of-an-entire-branch

How to extrude a spline to scene's origin with THREE.js

穿精又带淫゛_ 提交于 2021-02-17 02:50:25
问题 I'm having headaches when trying to extrude a spline to scene's origin. Here's what I'm trying to do : I'm creating a spline with let centerX = 0 let centerY = 0 let radius = 200 let coils = 50 let rotation = 2 * Math.PI let thetaMax = coils * Math.PI let awayStep = radius / thetaMax let chord = 5 let vertices = [] for (let theta = chord / awayStep; theta <= thetaMax;) { let away = awayStep * theta let around = theta + rotation let x = centerX + Math.cos(around) * away let y = centerY + Math

How to use video element or html content as a face texture in three.js?

核能气质少年 提交于 2021-02-16 09:21:26
问题 I am looking to use a video texture for a face in three.js. I know this is fairly easy to do if you have the video data. But what would I do if I only have the element it is playing from? For example: How would I play a youtube video and copy the video or player onto a face in three.js? 回答1: There is an example of integrating Three.js and YouTube videos at http://threejs.org/examples/css3d_youtube.html#cats and examples of including general HTML elements (using CSS3D) at http:/

THREE.js loading modal with model

自古美人都是妖i 提交于 2021-02-11 14:45:21
问题 What I'm currently trying to do is to load main model and then on click event display modal popup window with different model. I'm using raycaster to detect click and everything is working fine, but I'm not able to perform orbit control and raycast on the model that is displayed in the modal. raycast code part: raycaster = new THREE.Raycaster(); renderer.domElement.addEventListener( 'click', raycast, false ); function raycast ( e ) { //1. sets the mouse position with a coordinate system where

threejs - Reset camera position/rotation when using PointerLockControls

眉间皱痕 提交于 2021-02-11 12:32:31
问题 well i wants to reset the position and the rotation, when i am using the PointerLockControls. Currently i use controls.getObject().position.set( -30, 10, 80 ); controls.getObject().position.y = 10; for the position. But how can i reset the rotation? I tried different things like: camera.lookAt(new THREE.Vector3(1,0,0)); camera.rotation.x = - Math.PI / 2; controls.getObject().rotation.x = 0; controls.getObject().rotation.y = 0; controls.updateProjectionMatrix(); ... Have you an idea? Greeting,

I can't get the aoMap showing in three.js using a glb/gltf asset

流过昼夜 提交于 2021-02-11 08:58:22
问题 I’m having a hard time getting an aoMap working in three.js… I have a glb asset with an aoMap on the red channel or something. When I bring it into to the babylon viewer, I can see the ao just fine, but it wont show up in the three.js viewer or my project. I think this has something to do with a second set of uvs, but I can't find a resource that involves doing that on top of using the gltf loader… I really don't know what to do here. Any response would be greatly appreciated! Here is my code

Three.js place a plane through perpendicular by line

纵饮孤独 提交于 2021-02-10 20:50:58
问题 I have an a line and plane in 3D space. I want to place plane's width and length line as perpendicular by line. Please see my jsFiddle. I am newbie at both three.js and vector calculation. Current 2. Desired result Please advice me. (Apologies for my bad English) JS code: let renderer; let camera; let controls; let scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(54, window.innerWidth / window.innerHeight, 0.1, 1000); renderer = new THREE.WebGLRenderer({ antialias: true });

Three.js place a plane through perpendicular by line

依然范特西╮ 提交于 2021-02-10 20:48:18
问题 I have an a line and plane in 3D space. I want to place plane's width and length line as perpendicular by line. Please see my jsFiddle. I am newbie at both three.js and vector calculation. Current 2. Desired result Please advice me. (Apologies for my bad English) JS code: let renderer; let camera; let controls; let scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera(54, window.innerWidth / window.innerHeight, 0.1, 1000); renderer = new THREE.WebGLRenderer({ antialias: true });