如何显示Elements数组的对象类型

时间:2014-03-02 02:21:24

标签: javascript arrays three.js children

//那么,我如何找到以下

的解决方法

s.getDescendants()=[THREE.Light,THREE.Mesh,THREE.Mesh]

//我想要什么[THREE.LIGHT,THREE.Mesh,THREE.Mesh] //我得到了什么[object Object,object Object,object Object]

2 个答案:

答案 0 :(得分:1)

你可以访问

 obj.constructor.name

在每个单独的Object上获取“Light”,“Mesh”和“Mesh”,但前提是你的three.js没有缩小。

答案 1 :(得分:1)

editor我使用此代码:

var getObjectType = function ( object ) {

    var types = {

        'Scene': THREE.Scene,
        'PerspectiveCamera': THREE.PerspectiveCamera,
        'AmbientLight': THREE.AmbientLight,
        'DirectionalLight': THREE.DirectionalLight,
        'HemisphereLight': THREE.HemisphereLight,
        'PointLight': THREE.PointLight,
        'SpotLight': THREE.SpotLight,
        'Mesh': THREE.Mesh,
        'Sprite': THREE.Sprite,
        'Object3D': THREE.Object3D

    };

    for ( var type in types ) {

        if ( object instanceof types[ type ] ) return type;

    }

};