skinview3d/src/model.ts

580 lines
16 KiB
TypeScript
Raw Normal View History

2020-01-26 20:39:29 +01:00
import { ModelType } from "skinview-utils";
import { BoxGeometry, DoubleSide, FrontSide, Group, Mesh, MeshBasicMaterial, Object3D, Texture, Vector2 } from "three";
2017-10-01 14:00:45 +02:00
2020-02-01 12:13:46 +01:00
function toFaceVertices(x1: number, y1: number, x2: number, y2: number, w: number, h: number): Array<Vector2> {
2017-10-01 14:00:45 +02:00
return [
new Vector2(x1 / w, 1.0 - y2 / h),
new Vector2(x2 / w, 1.0 - y2 / h),
new Vector2(x2 / w, 1.0 - y1 / h),
new Vector2(x1 / w, 1.0 - y1 / h)
2017-10-01 14:00:45 +02:00
];
}
2020-02-01 12:13:46 +01:00
function toSkinVertices(x1: number, y1: number, x2: number, y2: number): Array<Vector2> {
2017-10-01 14:00:45 +02:00
return toFaceVertices(x1, y1, x2, y2, 64.0, 64.0);
}
2020-02-01 12:13:46 +01:00
function toCapeVertices(x1: number, y1: number, x2: number, y2: number): Array<Vector2> {
2017-10-01 14:00:45 +02:00
return toFaceVertices(x1, y1, x2, y2, 64.0, 32.0);
}
2020-06-08 22:32:54 +02:00
function toElytraVertices(x1: number, y1: number, x2: number, y2: number) {
return toFaceVertices(x1 + 22, y1, x2 + 22, y2, 64.0, 32.0);
}
2020-04-26 01:00:10 +02:00
function toEarVertices(x1: number, y1: number, x2: number, y2: number): Array<Vector2> {
return toFaceVertices(x1, y1, x2, y2, 14.0, 7.0);
}
2020-02-01 12:13:46 +01:00
function setVertices(box: BoxGeometry, top: Array<Vector2>, bottom: Array<Vector2>, left: Array<Vector2>, front: Array<Vector2>, right: Array<Vector2>, back: Array<Vector2>): void {
2017-10-01 14:00:45 +02:00
box.faceVertexUvs[0] = [];
box.faceVertexUvs[0][0] = [right[3], right[0], right[2]];
box.faceVertexUvs[0][1] = [right[0], right[1], right[2]];
box.faceVertexUvs[0][2] = [left[3], left[0], left[2]];
box.faceVertexUvs[0][3] = [left[0], left[1], left[2]];
box.faceVertexUvs[0][4] = [top[3], top[0], top[2]];
box.faceVertexUvs[0][5] = [top[0], top[1], top[2]];
box.faceVertexUvs[0][6] = [bottom[0], bottom[3], bottom[1]];
box.faceVertexUvs[0][7] = [bottom[3], bottom[2], bottom[1]];
box.faceVertexUvs[0][8] = [front[3], front[0], front[2]];
box.faceVertexUvs[0][9] = [front[0], front[1], front[2]];
box.faceVertexUvs[0][10] = [back[3], back[0], back[2]];
box.faceVertexUvs[0][11] = [back[0], back[1], back[2]];
}
/**
* Notice that innerLayer and outerLayer may NOT be the direct children of the Group.
*/
export class BodyPart extends Group {
2018-10-20 16:28:58 +02:00
constructor(
readonly innerLayer: Object3D,
readonly outerLayer: Object3D
2018-10-20 16:28:58 +02:00
) {
super();
2019-04-20 16:08:49 +02:00
innerLayer.name = "inner";
outerLayer.name = "outer";
}
}
export class SkinObject extends Group {
2018-07-17 20:49:00 +02:00
// body parts
readonly head: BodyPart;
readonly body: BodyPart;
readonly rightArm: BodyPart;
readonly leftArm: BodyPart;
readonly rightLeg: BodyPart;
readonly leftLeg: BodyPart;
2018-07-17 20:49:00 +02:00
private modelListeners: Array<() => void> = []; // called when model(slim property) is changed
2020-01-26 20:39:29 +01:00
private slim = false;
2018-07-17 20:49:00 +02:00
constructor(texture: Texture) {
2017-10-01 14:00:45 +02:00
super();
2020-08-31 01:38:19 +02:00
const layer1Material = new MeshBasicMaterial({
map: texture,
side: FrontSide
2020-08-31 01:38:19 +02:00
});
const layer2Material = new MeshBasicMaterial({
map: texture,
side: DoubleSide,
transparent: true,
2020-08-18 09:37:02 +02:00
alphaTest: 1e-5
2020-08-31 01:38:19 +02:00
});
2020-09-05 06:09:03 +02:00
const layer1MaterialBiased = layer1Material.clone();
layer1MaterialBiased.polygonOffset = true;
layer1MaterialBiased.polygonOffsetFactor = 1.0;
layer1MaterialBiased.polygonOffsetUnits = 1.0;
2020-08-31 01:38:19 +02:00
const layer2MaterialBiased = layer2Material.clone();
layer2MaterialBiased.polygonOffset = true;
layer2MaterialBiased.polygonOffsetFactor = 1.0;
layer2MaterialBiased.polygonOffsetUnits = 1.0;
2017-10-01 14:00:45 +02:00
// Head
2020-08-31 01:56:13 +02:00
const headBox = new BoxGeometry(8, 8, 8);
2018-07-02 08:54:49 +02:00
setVertices(headBox,
2017-10-01 14:00:45 +02:00
toSkinVertices(8, 0, 16, 8),
toSkinVertices(16, 0, 24, 8),
toSkinVertices(0, 8, 8, 16),
toSkinVertices(8, 8, 16, 16),
toSkinVertices(16, 8, 24, 16),
toSkinVertices(24, 8, 32, 16)
);
const headMesh = new Mesh(headBox, layer1Material);
2017-10-01 14:00:45 +02:00
2020-08-31 01:56:13 +02:00
const head2Box = new BoxGeometry(9, 9, 9);
2018-07-02 08:54:49 +02:00
setVertices(head2Box,
2017-10-01 14:00:45 +02:00
toSkinVertices(40, 0, 48, 8),
toSkinVertices(48, 0, 56, 8),
toSkinVertices(32, 8, 40, 16),
toSkinVertices(40, 8, 48, 16),
toSkinVertices(48, 8, 56, 16),
toSkinVertices(56, 8, 64, 16)
);
const head2Mesh = new Mesh(head2Box, layer2Material);
2017-10-01 14:00:45 +02:00
head2Mesh.renderOrder = -1;
this.head = new BodyPart(headMesh, head2Mesh);
2019-04-20 16:08:49 +02:00
this.head.name = "head";
this.head.add(headMesh, head2Mesh);
2017-10-01 14:00:45 +02:00
this.add(this.head);
// Body
2020-08-31 01:56:13 +02:00
const bodyBox = new BoxGeometry(8, 12, 4);
2018-07-02 08:54:49 +02:00
setVertices(bodyBox,
2017-10-01 14:00:45 +02:00
toSkinVertices(20, 16, 28, 20),
toSkinVertices(28, 16, 36, 20),
toSkinVertices(16, 20, 20, 32),
toSkinVertices(20, 20, 28, 32),
toSkinVertices(28, 20, 32, 32),
toSkinVertices(32, 20, 40, 32)
);
2020-08-31 01:38:19 +02:00
const bodyMesh = new Mesh(bodyBox, layer1Material);
2017-10-01 14:00:45 +02:00
2020-08-31 01:56:13 +02:00
const body2Box = new BoxGeometry(9, 13.5, 4.5);
2018-07-02 08:54:49 +02:00
setVertices(body2Box,
2017-10-01 14:00:45 +02:00
toSkinVertices(20, 32, 28, 36),
toSkinVertices(28, 32, 36, 36),
toSkinVertices(16, 36, 20, 48),
toSkinVertices(20, 36, 28, 48),
toSkinVertices(28, 36, 32, 48),
toSkinVertices(32, 36, 40, 48)
);
2020-08-31 01:38:19 +02:00
const body2Mesh = new Mesh(body2Box, layer2Material);
2017-10-01 14:00:45 +02:00
this.body = new BodyPart(bodyMesh, body2Mesh);
2019-04-20 16:08:49 +02:00
this.body.name = "body";
this.body.add(bodyMesh, body2Mesh);
2017-10-01 14:00:45 +02:00
this.body.position.y = -10;
this.add(this.body);
// Right Arm
2020-08-31 01:56:13 +02:00
const rightArmBox = new BoxGeometry();
const rightArmMesh = new Mesh(rightArmBox, layer1Material);
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
rightArmMesh.scale.x = this.slim ? 3 : 4;
rightArmMesh.scale.y = 12;
rightArmMesh.scale.z = 4;
2018-07-02 09:46:48 +02:00
if (this.slim) {
setVertices(rightArmBox,
toSkinVertices(44, 16, 47, 20),
toSkinVertices(47, 16, 50, 20),
toSkinVertices(40, 20, 44, 32),
toSkinVertices(44, 20, 47, 32),
toSkinVertices(47, 20, 51, 32),
toSkinVertices(51, 20, 54, 32)
);
} else {
setVertices(rightArmBox,
toSkinVertices(44, 16, 48, 20),
toSkinVertices(48, 16, 52, 20),
toSkinVertices(40, 20, 44, 32),
toSkinVertices(44, 20, 48, 32),
toSkinVertices(48, 20, 52, 32),
toSkinVertices(52, 20, 56, 32)
);
}
rightArmBox.uvsNeedUpdate = true;
rightArmBox.elementsNeedUpdate = true;
});
2020-08-31 01:56:13 +02:00
const rightArm2Box = new BoxGeometry();
2020-08-31 01:38:19 +02:00
const rightArm2Mesh = new Mesh(rightArm2Box, layer2MaterialBiased);
2017-10-01 14:00:45 +02:00
rightArm2Mesh.renderOrder = 1;
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
rightArm2Mesh.scale.x = this.slim ? 3.375 : 4.5;
rightArm2Mesh.scale.y = 13.5;
rightArm2Mesh.scale.z = 4.5;
2018-07-02 09:46:48 +02:00
if (this.slim) {
setVertices(rightArm2Box,
toSkinVertices(44, 32, 47, 36),
toSkinVertices(47, 32, 50, 36),
toSkinVertices(40, 36, 44, 48),
toSkinVertices(44, 36, 47, 48),
toSkinVertices(47, 36, 51, 48),
toSkinVertices(51, 36, 54, 48)
);
} else {
setVertices(rightArm2Box,
toSkinVertices(44, 32, 48, 36),
toSkinVertices(48, 32, 52, 36),
toSkinVertices(40, 36, 44, 48),
toSkinVertices(44, 36, 48, 48),
toSkinVertices(48, 36, 52, 48),
toSkinVertices(52, 36, 56, 48)
);
}
rightArm2Box.uvsNeedUpdate = true;
rightArm2Box.elementsNeedUpdate = true;
});
2017-10-01 14:00:45 +02:00
const rightArmPivot = new Group();
rightArmPivot.add(rightArmMesh, rightArm2Mesh);
2020-05-24 06:05:53 +02:00
rightArmPivot.position.y = -4;
this.rightArm = new BodyPart(rightArmMesh, rightArm2Mesh);
2019-04-20 16:08:49 +02:00
this.rightArm.name = "rightArm";
2017-10-01 14:00:45 +02:00
this.rightArm.add(rightArmPivot);
2020-05-24 06:05:53 +02:00
this.rightArm.position.y = -6;
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
this.rightArm.position.x = this.slim ? -5.5 : -6;
});
2017-10-01 14:00:45 +02:00
this.add(this.rightArm);
// Left Arm
2020-08-31 01:56:13 +02:00
const leftArmBox = new BoxGeometry();
const leftArmMesh = new Mesh(leftArmBox, layer1Material);
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
leftArmMesh.scale.x = this.slim ? 3 : 4;
leftArmMesh.scale.y = 12;
leftArmMesh.scale.z = 4;
2018-07-02 09:46:48 +02:00
if (this.slim) {
setVertices(leftArmBox,
toSkinVertices(36, 48, 39, 52),
toSkinVertices(39, 48, 42, 52),
toSkinVertices(32, 52, 36, 64),
toSkinVertices(36, 52, 39, 64),
toSkinVertices(39, 52, 43, 64),
toSkinVertices(43, 52, 46, 64)
);
} else {
setVertices(leftArmBox,
toSkinVertices(36, 48, 40, 52),
toSkinVertices(40, 48, 44, 52),
toSkinVertices(32, 52, 36, 64),
toSkinVertices(36, 52, 40, 64),
toSkinVertices(40, 52, 44, 64),
toSkinVertices(44, 52, 48, 64)
);
}
leftArmBox.uvsNeedUpdate = true;
2018-07-17 20:49:00 +02:00
leftArmBox.elementsNeedUpdate = true;
2018-07-02 09:46:48 +02:00
});
2020-08-31 01:56:13 +02:00
const leftArm2Box = new BoxGeometry();
2020-08-31 01:38:19 +02:00
const leftArm2Mesh = new Mesh(leftArm2Box, layer2MaterialBiased);
2017-10-01 14:00:45 +02:00
leftArm2Mesh.renderOrder = 1;
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
leftArm2Mesh.scale.x = this.slim ? 3.375 : 4.5;
leftArm2Mesh.scale.y = 13.5;
leftArm2Mesh.scale.z = 4.5;
2018-07-02 09:46:48 +02:00
if (this.slim) {
setVertices(leftArm2Box,
toSkinVertices(52, 48, 55, 52),
toSkinVertices(55, 48, 58, 52),
toSkinVertices(48, 52, 52, 64),
toSkinVertices(52, 52, 55, 64),
toSkinVertices(55, 52, 59, 64),
toSkinVertices(59, 52, 62, 64)
);
} else {
setVertices(leftArm2Box,
toSkinVertices(52, 48, 56, 52),
toSkinVertices(56, 48, 60, 52),
toSkinVertices(48, 52, 52, 64),
toSkinVertices(52, 52, 56, 64),
toSkinVertices(56, 52, 60, 64),
toSkinVertices(60, 52, 64, 64)
);
}
leftArm2Box.uvsNeedUpdate = true;
leftArm2Box.elementsNeedUpdate = true;
});
2017-10-01 14:00:45 +02:00
const leftArmPivot = new Group();
leftArmPivot.add(leftArmMesh, leftArm2Mesh);
2020-05-24 06:05:53 +02:00
leftArmPivot.position.y = -4;
this.leftArm = new BodyPart(leftArmMesh, leftArm2Mesh);
2019-04-20 16:08:49 +02:00
this.leftArm.name = "leftArm";
2017-10-01 14:00:45 +02:00
this.leftArm.add(leftArmPivot);
2020-05-24 06:05:53 +02:00
this.leftArm.position.y = -6;
2018-07-02 09:46:48 +02:00
this.modelListeners.push(() => {
this.leftArm.position.x = this.slim ? 5.5 : 6;
});
2017-10-01 14:00:45 +02:00
this.add(this.leftArm);
// Right Leg
2020-08-31 01:56:13 +02:00
const rightLegBox = new BoxGeometry(4, 12, 4);
2018-07-02 08:54:49 +02:00
setVertices(rightLegBox,
2017-10-01 14:00:45 +02:00
toSkinVertices(4, 16, 8, 20),
toSkinVertices(8, 16, 12, 20),
toSkinVertices(0, 20, 4, 32),
toSkinVertices(4, 20, 8, 32),
toSkinVertices(8, 20, 12, 32),
toSkinVertices(12, 20, 16, 32)
);
2020-09-05 06:09:03 +02:00
const rightLegMesh = new Mesh(rightLegBox, layer1MaterialBiased);
2017-10-01 14:00:45 +02:00
2020-08-31 01:56:13 +02:00
const rightLeg2Box = new BoxGeometry(4.5, 13.5, 4.5);
2018-07-02 08:54:49 +02:00
setVertices(rightLeg2Box,
2017-10-01 14:00:45 +02:00
toSkinVertices(4, 32, 8, 36),
toSkinVertices(8, 32, 12, 36),
toSkinVertices(0, 36, 4, 48),
toSkinVertices(4, 36, 8, 48),
toSkinVertices(8, 36, 12, 48),
toSkinVertices(12, 36, 16, 48)
);
2020-08-31 01:38:19 +02:00
const rightLeg2Mesh = new Mesh(rightLeg2Box, layer2MaterialBiased);
2017-10-01 14:00:45 +02:00
rightLeg2Mesh.renderOrder = 1;
const rightLegPivot = new Group();
rightLegPivot.add(rightLegMesh, rightLeg2Mesh);
2017-10-01 14:00:45 +02:00
rightLegPivot.position.y = -6;
this.rightLeg = new BodyPart(rightLegMesh, rightLeg2Mesh);
2019-05-02 10:33:13 +02:00
this.rightLeg.name = "rightLeg";
2017-10-01 14:00:45 +02:00
this.rightLeg.add(rightLegPivot);
this.rightLeg.position.y = -16;
this.rightLeg.position.x = -2;
this.add(this.rightLeg);
// Left Leg
2020-08-31 01:56:13 +02:00
const leftLegBox = new BoxGeometry(4, 12, 4);
2018-07-02 08:54:49 +02:00
setVertices(leftLegBox,
2017-10-01 14:00:45 +02:00
toSkinVertices(20, 48, 24, 52),
toSkinVertices(24, 48, 28, 52),
toSkinVertices(16, 52, 20, 64),
toSkinVertices(20, 52, 24, 64),
toSkinVertices(24, 52, 28, 64),
toSkinVertices(28, 52, 32, 64)
);
2020-09-05 06:09:03 +02:00
const leftLegMesh = new Mesh(leftLegBox, layer1MaterialBiased);
2017-10-01 14:00:45 +02:00
2020-08-31 01:56:13 +02:00
const leftLeg2Box = new BoxGeometry(4.5, 13.5, 4.5);
2018-07-02 08:54:49 +02:00
setVertices(leftLeg2Box,
2017-10-01 14:00:45 +02:00
toSkinVertices(4, 48, 8, 52),
toSkinVertices(8, 48, 12, 52),
toSkinVertices(0, 52, 4, 64),
toSkinVertices(4, 52, 8, 64),
toSkinVertices(8, 52, 12, 64),
toSkinVertices(12, 52, 16, 64)
);
2020-08-31 01:38:19 +02:00
const leftLeg2Mesh = new Mesh(leftLeg2Box, layer2MaterialBiased);
2017-10-01 14:00:45 +02:00
leftLeg2Mesh.renderOrder = 1;
const leftLegPivot = new Group();
leftLegPivot.add(leftLegMesh, leftLeg2Mesh);
2017-10-01 14:00:45 +02:00
leftLegPivot.position.y = -6;
this.leftLeg = new BodyPart(leftLegMesh, leftLeg2Mesh);
2019-04-20 16:08:49 +02:00
this.leftLeg.name = "leftLeg";
2017-10-01 14:00:45 +02:00
this.leftLeg.add(leftLegPivot);
this.leftLeg.position.y = -16;
this.leftLeg.position.x = 2;
this.add(this.leftLeg);
2018-07-02 09:46:48 +02:00
2020-01-26 20:39:29 +01:00
this.modelType = "default";
2018-07-02 09:46:48 +02:00
}
2020-01-26 20:39:29 +01:00
get modelType(): ModelType {
return this.slim ? "slim" : "default";
}
2018-07-02 09:46:48 +02:00
2020-01-26 20:39:29 +01:00
set modelType(value: ModelType) {
this.slim = value === "slim";
this.modelListeners.forEach(listener => listener());
}
2020-02-01 12:13:46 +01:00
private getBodyParts(): Array<BodyPart> {
2018-10-20 09:40:52 +02:00
return this.children.filter(it => it instanceof BodyPart) as Array<BodyPart>;
}
2020-02-01 12:13:46 +01:00
setInnerLayerVisible(value: boolean): void {
this.getBodyParts().forEach(part => part.innerLayer.visible = value);
}
2020-02-01 12:13:46 +01:00
setOuterLayerVisible(value: boolean): void {
this.getBodyParts().forEach(part => part.outerLayer.visible = value);
}
2017-10-02 15:29:41 +02:00
}
2017-10-01 14:00:45 +02:00
export class CapeObject extends Group {
2018-07-17 20:49:00 +02:00
readonly cape: Mesh;
2018-07-17 20:49:00 +02:00
constructor(texture: Texture) {
2017-10-01 14:00:45 +02:00
super();
2020-08-18 09:37:02 +02:00
const capeMaterial = new MeshBasicMaterial({
map: texture,
side: DoubleSide,
transparent: true,
alphaTest: 1e-5
});
2017-10-01 14:00:45 +02:00
// back = outside
// front = inside
2020-08-31 01:56:13 +02:00
const capeBox = new BoxGeometry(10, 16, 1);
2018-07-02 08:54:49 +02:00
setVertices(capeBox,
2020-09-11 00:59:12 +02:00
toCapeVertices(11, 1, 1, 0,),
toCapeVertices(21, 1, 11, 0),
2017-10-01 14:00:45 +02:00
toCapeVertices(11, 1, 12, 17),
toCapeVertices(12, 1, 22, 17),
toCapeVertices(0, 1, 1, 17),
toCapeVertices(1, 1, 11, 17)
);
this.cape = new Mesh(capeBox, capeMaterial);
2017-10-01 14:00:45 +02:00
this.cape.position.y = -8;
this.cape.position.z = -0.5;
this.add(this.cape);
}
2017-10-02 15:29:41 +02:00
}
2017-10-01 14:00:45 +02:00
2020-06-08 22:32:54 +02:00
export class ElytraObject extends Group {
readonly leftWing: Group;
readonly rightWing: Group;
constructor(texture: Texture) {
super();
const elytraMaterial = new MeshBasicMaterial({ map: texture, transparent: true, opacity: 1, side: DoubleSide, alphaTest: 0.5,
polygonOffset: true,
polygonOffsetFactor: -1.0,
polygonOffsetUnits: -4.0
});
const leftWingBox = new BoxGeometry(10, 20, 2);
setVertices(leftWingBox,
toElytraVertices(2, 0, 12, 2),
toElytraVertices(12, 0, 22, 2),
toElytraVertices(0, 2, 2, 22),
toElytraVertices(2, 2, 12, 22),
toElytraVertices(12, 2, 14, 22),
toElytraVertices(14, 2, 24, 22)
);
const leftWingMesh = new Mesh(leftWingBox, elytraMaterial);
leftWingMesh.position.x = -5;
leftWingMesh.position.y = -10;
leftWingMesh.position.z = -1;
leftWingMesh.scale.x = -1.15
leftWingMesh.scale.y = 1.15;
leftWingMesh.scale.z = 1.15;
this.leftWing = new Group();
this.leftWing.add(leftWingMesh);
this.leftWing.position.x = 3; // Left - right
this.leftWing.position.y = -1.5; //Up - down
this.leftWing.rotation.x = 0.2617994;
this.leftWing.rotation.y = 0;
this.leftWing.rotation.z = -0.19;
this.add(this.leftWing);
const rightWingBox = new BoxGeometry(10, 20, 2);
setVertices(rightWingBox,
toElytraVertices(2, 0, 12, 2),
toElytraVertices(12, 0, 22, 2),
toElytraVertices(0, 2, 2, 22),
toElytraVertices(2, 2, 12, 22),
toElytraVertices(12, 2, 14, 22),
toElytraVertices(14, 2, 24, 22)
);
const rightWingMesh = new Mesh(rightWingBox, elytraMaterial);
rightWingMesh.position.x = 5;
rightWingMesh.position.y = -10;
rightWingMesh.position.z = -1;
rightWingMesh.scale.x = 1.15
rightWingMesh.scale.y = 1.15;
rightWingMesh.scale.z = 1.15;
2020-06-08 22:32:54 +02:00
this.rightWing = new Group();
this.rightWing.add(rightWingMesh);
this.rightWing.position.x = -3; // Left - right
this.rightWing.position.y = -1.5; //Up - down
this.rightWing.rotation.x = 0.2617994; //0.2617994
this.rightWing.rotation.y = 0;
this.rightWing.rotation.z = 0.19;
this.add(this.rightWing);
}
}
2020-04-26 01:00:10 +02:00
export class EarsObject extends Group {
readonly leftEar: Mesh;
readonly rightEar: Mesh;
constructor(texture: Texture) {
super();
2020-09-11 00:59:12 +02:00
const earMaterial = new MeshBasicMaterial({
map: texture,
side: DoubleSide,
transparent: true,
alphaTest: 1e-5
});
2020-04-26 01:00:10 +02:00
// back = outside
// front = inside
2020-09-11 00:59:12 +02:00
const earBox = new BoxGeometry(6, 6, 1);
2020-04-26 01:00:10 +02:00
//x1: number, y1: number, x2: number, y2: number
setVertices(earBox,
//from look at back
toEarVertices(1, 0, 7, 1), //top
toEarVertices(7, 0, 13, 1), //bottom
toEarVertices(0, 1, 1, 7), //right
toEarVertices(1, 1, 7, 7), //front
toEarVertices(0, 1, 1, 7), //left
toEarVertices(8, 1, 14, 7) //back
);
this.leftEar = new Mesh(earBox, earMaterial);
this.leftEar.position.x = -5.5;
2020-06-08 22:32:54 +02:00
this.leftEar.scale.x = 1.3;
this.leftEar.scale.y = 1.3;
this.leftEar.scale.z = 1.3;
2020-04-26 01:00:10 +02:00
this.add(this.leftEar);
this.rightEar = new Mesh(earBox, earMaterial);
this.rightEar.position.x = 5.5;
2020-06-08 22:32:54 +02:00
this.rightEar.scale.x = 1.3;
this.rightEar.scale.y = 1.3;
this.rightEar.scale.z = 1.3;
2020-04-26 01:00:10 +02:00
this.add(this.rightEar);
}
}
export class PlayerObject extends Group {
2018-07-17 20:49:00 +02:00
2018-08-17 06:56:13 +02:00
readonly skin: SkinObject;
readonly cape: CapeObject;
2020-06-08 22:32:54 +02:00
readonly elytra: ElytraObject;
2020-04-26 01:00:10 +02:00
readonly ears: EarsObject
2018-07-17 20:49:00 +02:00
2020-04-26 01:00:10 +02:00
constructor(skinTexture: Texture, capeTexture: Texture, earTexture: Texture) {
2017-10-01 14:00:45 +02:00
super();
this.skin = new SkinObject(skinTexture);
2019-04-20 16:08:49 +02:00
this.skin.name = "skin";
2020-04-26 01:19:59 +02:00
this.skin.position.y = -2
2017-10-01 14:00:45 +02:00
this.add(this.skin);
this.cape = new CapeObject(capeTexture);
2019-04-20 16:08:49 +02:00
this.cape.name = "cape";
2017-10-01 14:00:45 +02:00
this.cape.position.z = -2;
2020-04-26 01:19:59 +02:00
this.cape.position.y = -6;
2020-04-26 01:00:10 +02:00
this.cape.rotation.x = 10 * Math.PI / 180;
2017-10-01 14:00:45 +02:00
this.add(this.cape);
2020-04-26 01:00:10 +02:00
2020-06-08 22:32:54 +02:00
this.elytra = new ElytraObject(capeTexture);
2020-07-12 18:52:08 +02:00
this.elytra.name = "elytra";
2020-06-08 22:32:54 +02:00
this.elytra.position.y = -7;
this.elytra.position.z = -2;
this.elytra.visible = false;
this.add(this.elytra);
2020-04-26 01:00:10 +02:00
this.ears = new EarsObject(earTexture);
this.ears.name = "ears";
2020-04-26 01:19:59 +02:00
this.ears.position.y = 3.5;
2020-04-26 01:00:10 +02:00
this.add(this.ears);
2017-10-01 14:00:45 +02:00
}
2017-10-02 15:29:41 +02:00
}