如何在three.js中使用gltf模型投射阴影? [英] How to cast a shadow with a gltf model in three.js?

查看:168
本文介绍了如何在three.js中使用gltf模型投射阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是三个 js 的新手 &想知道如何使用 gltf 模型投射阴影?我可以看到这是可能的,因为它正在这里我假设我没有正确构建我的代码-

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;

这是小提琴https://jsfiddle.net/steveham/ckpfwy24/87/

干杯!

推荐答案

您需要在每个子网格上设置 castShadow = true,如下所示:

You need to set castShadow = true on each child mesh, like so:

var loader = new THREE.GLTFLoader();

loader.load( 'https://threejs.org/examples/models/gltf/Duck/glTF/Duck.gltf', function( gltf ) {

    gltf.scene.traverse( function( node ) {

        if ( node.isMesh ) { node.castShadow = true; }

    } );

    scene.add( gltf.scene );

} );

three.js r.113

three.js r.113

这篇关于如何在three.js中使用gltf模型投射阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆