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

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

Methods

1.decomposeLocalTransform()

将局部转换分解为 SRT,
输入参数keepScale,如果scale!=keepScale,则scale=this.scale,否则scale=null。

    decomposeLocalTransform: function (keepScale) {
        var scale = !keepScale ? this.scale: null;
        this.localTransform.decomposeMatrix(scale, this.rotation, this.position);
    },

2.decomposeProjectionMatrix()

分解相机投影矩阵

    decomposeProjectionMatrix: function () {},

3. decomposeWorldTransform()

分解世界转换为 SRT函数

    decomposeWorldTransform: (function () {
        var tmp = mat4.create();
        return function (keepScale) {
            var localTransform = this.localTransform;
            var worldTransform = this.worldTransform;
            // Assume world transform is updated
            if (this._parent) {
                mat4.invert(tmp, this._parent.worldTransform.array);
                mat4.multiply(localTransform.array, tmp, worldTransform.array);
            } else {
                mat4.copy(localTransform.array, worldTransform.array);
            }
            var scale = !keepScale ? this.scale: null;
            localTransform.decomposeMatrix(scale, this.rotation, this.position);
        };
    })(),
    transformNeedsUpdate: function () {
        return this.position._dirty
            || this.rotation._dirty
            || this.scale._dirty;
    },

4.eachChild(callback, contextopt)

遍历所有子节点。
不能在迭代期间在回调中执行"添加","删除"操作。
参数:

名称类型属性
callbackfunction
contextNode可选
    eachChild: function (callback, context) {
        var _children = this._children;
        for(var i = 0, len = _children.length; i < len; i++) {
            var child = _children[i];
            callback.call(context, child, i);
        }
    },

5.error(action, contextopt)

一次别名(‘error’)
参数:

名称类型属性
actionfunction
contextObject可选
    error: function(action, context) {
        return this.once('error', action, context);
    },

6.getChildByName(name) → {clay.Node}

得到第一个有名字的子节点
参数:

名称类型
namestring
contextObject

返回值: 类型 clay.Node

    getChildByName: function (name) {
        var children = this._children;
        for (var i = 0; i < children.length; i++) {
            if (children[i].name === name) {
                return children[i];
            }
        }
    },

7.getDescendantByName(name) → {clay.Node}

获取第一个具有给定名称的后代节点
参数:

名称类型
namestring

返回值: 类型 clay.Node


    getDescendantByName: function (name) {
        var children = this._children;
        for (var i = 0; i < children.length; i++) {
            var child = children[i];
            if (child.name === name) {
                return child;
            } else {
                var res = child.getDescendantByName(name);
                if (res) {
                    return res;
                }
            }
        }
    },

8.getParent() → {clay.Scene}

获取父节点
返回值:
类型 clay.Scene

    getParent: function () {
        return this._parent;
    },

9.getPath(rootNodeopt) → {string}

获取查询路径,相对于根节点(默认为 scene)。
参数:

名称类型属性
rootNodeclay.Node可选

返回值:
类型 string

    getPath: function (rootNode) {
        if (!this._parent) {
            return '/';
        }
        var current = this._parent;
        var path = this.name;
        while (current._parent) {
            path = current.name + '/' + path;
            if (current._parent == rootNode) {
                break;
            }
            current = current._parent;
        }
        if (!current._parent && rootNode) {
            return null;
        }
        return path;
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值