jeromeetienne / learningthreejs.com-backup

blog about learning three.js
http://learningthreejs.com
MIT License
22 stars 4 forks source link

Post: plugins #21

Closed jeromeetienne closed 12 years ago

jeromeetienne commented 12 years ago
jeromeetienne commented 12 years ago

Would be a good example

jeromeetienne commented 12 years ago
jeromeetienne commented 12 years ago

Three.object3d.plugins = Pluginsjsfunction'

Here you get the list of all the object which ok to modify

Start with static helpers as theyr are pretty safe

jeromeetienne commented 12 years ago

File naming convention

jeromeetienne commented 12 years ago
// filename: three.geometry.tools.js

THREE.Geometry.register('center', {

})

geometry.center().width().height().depth();
geometry.flip();
geometry.scale().translate().rotate();
jeromeetienne commented 12 years ago
(function(){
    this.register   = function(object, methodName, metadata) {
        if( object[methodName] ){
            throw new Error('Conflict! Already method called: ' + methodName);
        }
        object[methodName] = metadata[methodName];
    };
    this.unregister = function(object, methodName) {
        if( object.hasOwnProperty(methodName) === false ){
            throw new Error('Plugin not found: ' + methodName);
        }
        delete object[methodName];
    };
    this.registered = function(object, methodName){
        return object.hasOwnProperty(methodName) === true;
    }
    return this;
})(THREE.Geometry.prototype);
jeromeetienne commented 12 years ago

Did some code in examples