0
//所以,我將如何找到以下如何顯示元素陣列(S)的對象的類型
解決方法s.getDescendants()=[THREE.Light,THREE.Mesh,THREE.Mesh]
//我想要[THREE.Light,THREE.Mesh ,THREE.Mesh] //我已經得到了[對象的對象,對象對象,對象對象]
//所以,我將如何找到以下如何顯示元素陣列(S)的對象的類型
解決方法s.getDescendants()=[THREE.Light,THREE.Mesh,THREE.Mesh]
//我想要[THREE.Light,THREE.Mesh ,THREE.Mesh] //我已經得到了[對象的對象,對象對象,對象對象]
,你可以對每一個對象訪問
obj.constructor.name
獲得「光」,「網格」和「網格」,但前提是你的three.js沒有被縮小。
在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;
}
};