Creating custom Object3D class

前端 未结 1 1592
别那么骄傲
别那么骄傲 2021-02-11 01:04

I\'m new to THREE.js coming from an AS3/Away3D background. I\'m trying to create a custom object class that extends THREE.Object3D to add to my scene. CustomObject will encapsul

1条回答
  •  北海茫月
    2021-02-11 01:45

    If you want to add your custom object to the scene directly, you can use a pattern like this one:

    function CustomObject() {
    
        this.type = 'CustomObject';
    
        this.geometry = new THREE.BoxGeometry( 540, 540, 14 );
        this.material = new THREE.MeshLambertMaterial( { color: 0xff0000 } );
    
        THREE.Mesh.call( this, this.geometry, this.material );
    
    }
    
    CustomObject.prototype = Object.create( THREE.Mesh.prototype );
    CustomObject.prototype.constructor = CustomObject;
    
    CustomObject.prototype.getMesh = function() {
    
        return this.mesh;
    
    }
    
    var foo = new CustomObject();
    scene.add( foo );
    

    three.js r.71

    0 讨论(0)
提交回复
热议问题