2021SC@SDUSC ClayGL Camera类分析(七)

2021SC@SDUSC ClayGL Camera类分析(七)
接上文

1.off(action, contextopt)

删除事件侦听器
参数:

名称类型属性
actionfunction
contextObject可选
    off: function(name, action) {
        var handlers = this.__handlers__ || (this.__handlers__={});
        if (!action) {
            handlers[name] = [];
            return;
        }
        if (handlers[name]) {
            var hdls = handlers[name];
            var retains = [];
            for (var i = 0; i < hdls.length; i++) {
                if (action && hdls[i].action !== action) {
                    retains.push(hdls[i]);
                }
            }
            handlers[name] = retains;
        }
        return this;
    },

2.on(name, action, contextopt)

注册事件处理程序
参数:

名称类型属性
actionfunction
namestring
contextObject可选
    on: function(name, action, context) {
        if (!name || !action) {
            return;
        }
        var handlers = this.__handlers__ || (this.__handlers__={});
        if (!handlers[name]) {
            handlers[name] = [];
        }
        else {
            if (this.has(name, action)) {
                return;
            }
        }
        var handler = new Handler(action, context || this);
        handlers[name].push(handler);
        return this;
    },

3.once(name, action, contextopt)

注册事件,事件只会触发一次,然后删除
参数:

名称类型属性
actionfunction
namestring
contextObject可选
    once: function(name, action, context) {
        if (!name || !action) {
            return;
        }
        var self = this;
        function wrapper() {
            self.off(name, wrapper);
            action.apply(this, arguments);
        }
        return this.on(name, wrapper, context);
    },

4.queryNode(path) → {clay.Node}

按路径查询后代节点

参数:

名称类型
pathstring

返回值:
类型 clay.Node
例如:
node.queryNode(‘root/parent/child’);


    queryNode: function (path) {
        if (!path) {
            return;
        }
        // TODO Name have slash ?
        var pathArr = path.split('/');
        var current = this;
        for (var i = 0; i < pathArr.length; i++) {
            var name = pathArr[i];
            // Skip empty
            if (!name) {
                continue;
            }
            var found = false;
            var children = current._children;
            for (var j = 0; j < children.length; j++) {
                var child = children[j];
                if (child.name === name) {
                    current = child;
                    found = true;
                    break;
                }
            }
            // Early return if not found
            if (!found) {
                return;
            }
        }
        return current;
    },

5.remove(node)

删除给定的子场景节点
参数:

名称类型
nodeclay.Node
    remove: function (node) {
        var children = this._children;
        var idx = children.indexOf(node);
        if (idx < 0) {
            return;
        }
        children.splice(idx, 1);
        node._parent = null;
        if (this._scene) {
            node.traverse(this._removeSelfFromScene, this);
        }
    },

6.removeAll()

删除所有孩子项

    removeAll: function () {
        var children = this._children;
        for (var idx = 0; idx < children.length; idx++) {
            children[idx]._parent = null;
            if (this._scene) {
                children[idx].traverse(this._removeSelfFromScene, this);
            }
        }
        this._children = [];
    },

7.rotateAround(point, axis, angle)

按角度度沿轴旋转节点,轴穿过点
参数:

名称类型说明
pointclay.Vector3Center point
axisclay.Vector3Center axis
anglenumberRotation angle
    rotateAround: (function () {
        var v = new Vector3();
        var RTMatrix = new Matrix4();
        // TODO improve performance
        return function (point, axis, angle) {
            v.copy(this.position).subtract(point);
            var localTransform = this.localTransform;
            localTransform.identity();
            // parent node
            localTransform.translate(point);
            localTransform.rotate(angle, axis);
            RTMatrix.fromRotationTranslation(this.rotation, v);
            localTransform.multiply(RTMatrix);
            localTransform.scale(this.scale);
            this.decomposeLocalTransform();
            this._needsUpdateWorldTransform = true;
        };
    })(),

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值