猫史档案馆


【神奇代码岛】动作模拟器文档

用户:迷失冷光迷失冷光查看:6 回复:5 评论:6 创建时间:2021-12-22T19:40:28


先发出来

以后出讲解

const Quat = new Box3Quaternion(0,0,0,1);
const host = [];
class Joint{
    constructor(lookable,model,position = null,children = [],property = {angle: 0,up: 0,radius: 1}){
        host.push(Object.assign(this,{
            lookable,
            model,
            position,
            children,
            property,
        }));
    };
    addChildren(...joints){
        this.children.push(...joints);
    };
    removeChild(joint){
        this.children.splice(this.children.indexOf(joint));
    };
    changeChild(joint,target){
        this.children.splice(this.children.indexOf(joint));
        target.children.push(joint);
    };
    destroy(){
        if(host.includes(this)){
            host.splice(host.indexOf(this),1);
            return true;
        }else return false;
    };
}
global.Joint = Joint;
world.onTick(()=>{
    for(const e of host){
        single(e);
    }
})
function single(joint,parent = null){
    if(parent){
        //设置位置
        joint.position = point_in_ball(parent.position,joint.property.angle,joint.property.up,joint.property.radius);
        if(joint.lookable){
            joint.model.position.copy(joint.position);
        }
    }else{
        joint.position = joint.model.position;
    }
    if(joint.lookable){
        //设置旋转
        joint.meshOrientation = Quat.rotateX(joint.property.up).rotateY(joint.property.angle);
    }
    //下一级旋转
    for(const e of joint.children){
        single(e,joint);
    }
}
function point_in_ball(origin,angle,up,radius){
    return new Box3Vector3(
        origin.x + Math.cos(angle) * Math.cos(up) * radius,
        origin.y + Math.sin(up) * radius,
        origin.z + Math.sin(angle) * Math.cos(up) * radius
    )
}

 


回复

上一页1 页 / 共 1下一页
迷失冷光迷失冷光

这次应该是真的了

点赞0


评论


BXS_asteroidBXS_asteroid

emotion_doge

点赞1


评论


全能代码师全能代码师

卡顿

点赞0


评论


全能代码师全能代码师

这种其实我也可以做,就是有人反映比较卡()还有耗费文件资源

点赞0


评论


该账号已被封禁该账号已被封禁

真 不 戳

点赞0


评论