Harlotte 发表于 2024-6-26 21:02:13

初试面向对象,。。

本帖最后由 Harlotte 于 2024-6-27 20:27 编辑

阿弥诺斯function Button(modelClusters, x, y, z, rx, ry, rz, minimumAngle, maximumAngle, nowAngle, direction) {
    this.modelClusters = modelClusters;
    this.x = x;
    this.y = y;
    this.z = z;
    this.rx = rx;
    this.ry = ry;
    this.rz = rz;
    this.minimumAngle = minimumAngle;
    this.maximumAngle = maximumAngle;
    this.nowAngle = nowAngle;
    this.direction = direction;
}

Button.prototype.draw = function(carriage, ctx) {
    let tempMatrices = new Matrices();
    tempMatrices.rotateZ(state.wobblerot);
    tempMatrices.translate(this.x, this.y, this.z);
    tempMatrices.rotateX(this.rx);
    tempMatrices.rotateY(this.ry);
    tempMatrices.rotateZ(this.rz);
    tempMatrices.rotateX(degreesToRadians(this.nowAngle * this.direction));
    tempMatrices.rotateY(degreesToRadians(this.nowAngle * this.direction));
    tempMatrices.rotateZ(degreesToRadians(this.nowAngle * this.direction));
    for(let i = 0; i < carriage; i++){
      ctx.drawCarModel(this.modelClusters, i, tempMatrices);
    }
};

Button.prototype.turnTo = function(angle) {
    this.nowAngle = angle;
};

Button.prototype.turnMaximum = function() {
    this.nowAngle = this.maximumAngle;
};

Button.prototype.turnMinimum = function() {
    this.nowAngle = this.minimumAngle;
};

Button.prototype.turnMiddle = function() {
    this.nowAngle = (this.maximumAngle + this.minimumAngle) / 2;
};

Button.prototype.getMinimumAngle = function() {
    return this.minimumAngle;
};

Button.prototype.getMaximumAngle = function() {
    return this.maximumAngle;
};

//----------

let buttonRawModels = ModelManager.loadPartedRawModel(Resources.manager(), Resources.idRelative("df5g_buttons.obj"), null);
var buttonModelClusters = uploadPartedModels(buttonRawModels);

//----------

function create(ctx, state, train) {
    state.buttons = new Map();
    for(let i=0;i<buttonsInformation.length;i++){
      state.buttons.set(buttonModelClusters.name], new Button(buttonModelClusters.name],buttonsInformation.x,buttonsInformation.y,buttonsInformation.z,buttonsInformation.rx,buttonsInformation.ry,buttonsInformation.rz,buttonsInformation.minimumAngle,buttonsInformation.maximumAngle,buttonsInformation.nowAngle,buttonsInformation.direction))
    }
}

//----------

function render(ctx, state, train) {
    for (let value of state.buttons.values()) {
      value.draw(train.trainCars(), ctx);
    }
}

//----------

function uploadPartedModels(modelClusterss) {//直接搬过来的,上传模型
    let result = {};
    for (it = modelClusterss.entrySet().iterator(); it.hasNext(); ) {
      entry = it.next();
      entry.getValue().applyUVMirror(false, true);
      result = ModelManager.uploadVertArrays(entry.getValue());
    }
    return result;
}

function degreesToRadians(degrees) {
    return degrees * Math.PI / 180;
}
哎 然后这次写的时候突然又开始注重命名规范了,真是我不可多得的一点改进啊(大喜

还有多亏了blender支持python,搞了个小代码可以按照我要的方式输出数据,要不一个一个的复制坐标和旋转得累死我

而且就现在这个按钮信息还差了一半,要问就是现在只搞了一个控制台,还有一个控制台在对面


下面是部分代码,控制逻辑还没有,过一阵完善,只实现了一些比较基础的东西,供各位借鉴借鉴,有问题请指出

位于“button.js”:

位于"main.js":
var buttonsInformation = new Array();
buttonsInformation.push({name:"B1", x:-0.67873430, y:-5.86294317, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B2", x:-0.70873421, y:-5.86294317, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B3", x:-0.73873419, y:-5.86294317, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B4", x:-0.76873422, y:-5.86294317, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B5", x:-0.79873425, y:-5.86294317, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B6", x:-0.82873416, y:-5.86294317, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B7", x:-0.85873419, y:-5.86294317, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B8", x:-0.88873410, y:-5.86294317, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B9", x:-0.67873430, y:-5.78294325, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B10", x:-0.70873421, y:-5.78294325, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B11", x:-0.73873425, y:-5.78294325, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B12", x:-0.76873422, y:-5.78294325, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B13", x:-0.79873419, y:-5.78294325, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B14", x:-0.82873416, y:-5.78294325, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B15", x:-0.85873419, y:-5.78294325, z:1.63171601, rx:1.57079625, ry:2.00712872, rz:1.57079625, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B16", x:-0.88873410, y:-5.78294325, z:1.63171601, rx:-1.57079613, ry:1.13446403, rz:-1.57079613, minimumAngle:-25, maximumAngle:25, direction:});
buttonsInformation.push({name:"B17b", x:-0.78984880, y:-5.63463020, z:1.75308025, rx:-0.00000026, ry:-1.10015225, rz:1.57079649, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B17r", x:-0.78984880, y:-5.63698387, z:1.75427735, rx:-0.00000026, ry:-1.10015225, rz:1.57079649, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B18b", x:-1.25822449, y:-5.62597370, z:1.76651037, rx:-0.00000024, ry:-1.10015225, rz:1.57079661, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B18r", x:-1.25822449, y:-5.62775612, z:1.76741731, rx:-0.00000024, ry:-1.10015225, rz:1.57079661, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B19b", x:-1.37824154, y:-5.62596798, z:1.76652133, rx:-0.00000024, ry:-1.10015225, rz:1.57079661, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B19r", x:-1.37824154, y:-5.62775040, z:1.76742828, rx:-0.00000024, ry:-1.10015225, rz:1.57079661, minimumAngle:-135, maximumAngle:135, direction:});
buttonsInformation.push({name:"B20", x:-0.33558506, y:-5.58756828, z:2.22708082, rx:-1.57079649, ry:-0.00000003, rz:-0.72945309, minimumAngle:-20, maximumAngle:20, direction:});
buttonsInformation.push({name:"B21", x:-1.05873716, y:-5.83794308, z:1.63690805, rx:0.00000000, ry:1.57079637, rz:0.00000000, minimumAngle:-40, maximumAngle:40, direction:});
buttonsInformation.push({name:"B22", x:-0.98935747, y:-5.83794308, z:1.64137828, rx:0.00000000, ry:0.00000000, rz:0.00000000, minimumAngle:-40, maximumAngle:40, direction:});
buttonsInformation.push({name:"B23", x:-0.98935747, y:-5.79227972, z:1.65701008, rx:1.57079637, ry:0.00000000, rz:0.00000000, minimumAngle:0, maximumAngle:90, direction:});




Sheriff 发表于 2024-6-26 23:01:22

膜拜大佬

ShentongMetro 发表于 2024-6-27 16:13:26

你说得对但是Rhino实现的ES6不支持class,请用function.prototype

Harlotte 发表于 2024-6-27 18:56:33

ShentongMetro 发表于 2024-6-27 16:13
你说得对但是Rhino实现的ES6不支持class,请用function.prototype

嘶嘶嘶嘶嘶嘶
页: [1]
查看完整版本: 初试面向对象,。。