【问题标题】:How to make COLLADA models cast shadow on its own in three.js?如何让 COLLADA 模型在 three.js 中自己投射阴影?
【发布时间】:2012-06-01 22:24:55
【问题描述】:

我试过了:

dae.castShadow = true;
dae.receiveShadow = true;
scene.add(dae);

//spotLight is defined already.
spotLight.castShadow = true;

renderer.shadowMapEnabled = true;

但是模型仍然没有阴影?我做错什么了吗?请帮忙。

【问题讨论】:

    标签: javascript three.js collada


    【解决方案1】:

    您需要为层次结构中的所有对象将castShadowreceiveShadow 设置为true

    THREE.SceneUtils.traverseHierarchy( dae, function ( child ) {
    
        child.castShadow = true;
        child.receiveShadow = true;
    
    } );
    

    【讨论】:

    • Could not initialise shadererror(#201) Requires extension support 出现错误。 ???
    • 添加代码后出现这2个错误。 :((仅在 Firefox 中,在 Chrome 中可以。)
    【解决方案2】:

    three.js 发生了变化(见three.js migration r51--r52):

    将 SceneUtils.traverseHierarchy 替换为 object.traverse。

    因此,现在为层次结构中的所有对象设置 castShadowreceiveShadow 的正确方法是:

    dae.traverse(function(child) {
        child.castShadow = true;
        child.receiveShadow = true;
    });
    

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多