2015-09-29 18:52:18 +02:00
|
|
|
/*
|
2017-08-30 14:26:04 +02:00
|
|
|
* skinpreview3d.js
|
|
|
|
* https://github.com/yushijinhun/skinpreview3d.js
|
|
|
|
*/
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
'use strict';
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-29 17:04:08 +02:00
|
|
|
(function($) {
|
2017-08-29 13:43:35 +02:00
|
|
|
$.fn.skinPreview3D = function (options) {
|
2017-08-30 14:32:15 +02:00
|
|
|
var sp = new SkinPreview3D(this, options.width, options.height, options.slim === true);
|
2016-01-10 18:28:54 +01:00
|
|
|
sp.setSkin(options.skinUrl);
|
2017-08-30 14:32:15 +02:00
|
|
|
if(options.capeUrl != null)
|
2016-01-10 18:28:54 +01:00
|
|
|
sp.setCape(options.capeUrl);
|
2015-09-29 18:52:18 +02:00
|
|
|
};
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
} (window.jQuery));
|
|
|
|
|
2017-08-30 14:32:15 +02:00
|
|
|
function SkinPreview3D(model, canvasW, canvasH, isSlim){
|
2015-09-29 18:52:18 +02:00
|
|
|
var radius = 32;
|
|
|
|
var isPaused = false;
|
|
|
|
var originMouseX = 0;
|
|
|
|
var rotating = false;
|
|
|
|
var modelRot = 0;
|
|
|
|
var angleRot = 0;
|
|
|
|
var mouseDown = false;
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
var camera = new THREE.PerspectiveCamera(75, canvasW / canvasH, 1, 10000);
|
2015-09-29 18:52:18 +02:00
|
|
|
camera.position.y = -12;
|
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
var scene = new THREE.Scene();
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-30 14:32:15 +02:00
|
|
|
var skinCanvas = document.createElement('canvas');
|
2017-08-29 13:43:35 +02:00
|
|
|
skinCanvas.width = 64;
|
|
|
|
skinCanvas.height = 64;
|
|
|
|
var skinContext = skinCanvas.getContext("2d");
|
2017-08-30 14:26:04 +02:00
|
|
|
var skinTexture = new THREE.Texture(skinCanvas);
|
|
|
|
skinTexture.magFilter = THREE.NearestFilter;
|
|
|
|
skinTexture.minFilter = THREE.NearestMipMapNearestFilter;
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2017-08-30 14:32:15 +02:00
|
|
|
var capeCanvas = document.createElement('canvas');
|
2017-08-29 17:04:08 +02:00
|
|
|
capeCanvas.width = 32;
|
|
|
|
capeCanvas.height = 32;
|
2017-08-29 13:43:35 +02:00
|
|
|
var capeContext = capeCanvas.getContext("2d");
|
|
|
|
var capeTexture = new THREE.Texture(capeCanvas);
|
2016-01-10 18:28:54 +01:00
|
|
|
capeTexture.magFilter = THREE.NearestFilter;
|
|
|
|
capeTexture.minFilter = THREE.NearestMipMapNearestFilter;
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
var layer1Material = new THREE.MeshBasicMaterial({map: skinTexture, side: THREE.FrontSide});
|
|
|
|
var layer2Material = new THREE.MeshBasicMaterial({map: skinTexture, transparent: true, opacity: 1, side: THREE.DoubleSide});
|
|
|
|
var capeMaterial = new THREE.MeshBasicMaterial({map: capeTexture});
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-29 13:43:35 +02:00
|
|
|
var skinImg = new Image();
|
|
|
|
skinImg.crossOrigin = '';
|
2015-09-29 18:52:18 +02:00
|
|
|
var hasAnimate = false;
|
2017-08-29 13:43:35 +02:00
|
|
|
skinImg.onload = () => {
|
|
|
|
skinContext.clearRect(0, 0, 64, 64);
|
|
|
|
skinContext.drawImage(skinImg, 0, 0);
|
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
skinTexture.needsUpdate = true;
|
2017-08-29 13:43:35 +02:00
|
|
|
layer1Material.needsUpdate = true;
|
|
|
|
layer2Material.needsUpdate = true;
|
|
|
|
|
|
|
|
if(!hasAnimate) {
|
2015-09-29 18:52:18 +02:00
|
|
|
initializeSkin();
|
|
|
|
hasAnimate = true;
|
|
|
|
drawSkin();
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
};
|
|
|
|
skinImg.onerror = () => console.log("Failed loading " + skinImg.src);
|
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
var capeImg = new Image();
|
2017-08-29 13:43:35 +02:00
|
|
|
capeImg.crossOrigin = '';
|
|
|
|
capeImg.onload = () => {
|
|
|
|
capePivot.add(capeMesh);
|
2016-01-10 18:28:54 +01:00
|
|
|
|
2017-08-29 13:43:35 +02:00
|
|
|
capeContext.clearRect(0, 0, capeCanvas.width, capeCanvas.height);
|
2017-08-29 17:04:08 +02:00
|
|
|
capeContext.drawImage(capeImg, 0, 0, capeCanvas.width, capeCanvas.height);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2016-01-10 18:28:54 +01:00
|
|
|
capeTexture.needsUpdate = true;
|
2017-08-29 13:43:35 +02:00
|
|
|
capeMaterial.needsUpdate = true;
|
|
|
|
};
|
|
|
|
capeImg.onerror = () => console.log("Failed loading " + capeImg.src);
|
|
|
|
|
|
|
|
this.setSkin = url => skinImg.src = url;
|
|
|
|
this.setCape = url => capeImg.src = url;
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
var renderer;
|
|
|
|
var capePivot;
|
|
|
|
var headBox, headMesh, bodyBox, bodyMesh, rightArmBox, rightArmMesh, leftArmBox, leftArmMesh, rightLegBox, rightLegMesh, leftLegBox, leftLegMesh, head2Box, head2Mesh, body2Box, body2Mesh, rightArm2Box, rightArm2Mesh, leftArm2Box, leftArm2Mesh, rightLeg2Box, rightLeg2Mesh, leftLeg2Box, leftLeg2Mesh, capeBox, capeMesh;
|
|
|
|
|
2017-08-30 14:26:04 +02:00
|
|
|
var initializeSkin = () => {
|
|
|
|
var toFaceVertices = (x1,y1,x2,y2,w,h) => [
|
|
|
|
new THREE.Vector2(x1/w, 1.0-y2/h),
|
|
|
|
new THREE.Vector2(x2/w, 1.0-y2/h),
|
|
|
|
new THREE.Vector2(x2/w, 1.0-y1/h),
|
|
|
|
new THREE.Vector2(x1/w, 1.0-y1/h)
|
|
|
|
];
|
|
|
|
var toSkinVertices = (x1,y1,x2,y2) => toFaceVertices(x1, y1, x2, y2, 64.0, 64.0);
|
|
|
|
var toCapeVertices = (x1,y1,x2,y2) => toFaceVertices(x1, y1, x2, y2, 22.0, 17.0);
|
|
|
|
var addVertices = (box,top,bottom,left,front,right,back) => {
|
|
|
|
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]];
|
|
|
|
};
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2017-08-30 14:26:04 +02:00
|
|
|
// Head Parts
|
2015-09-29 18:52:18 +02:00
|
|
|
headBox = new THREE.BoxGeometry(8, 8, 8, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(headBox,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
headMesh = new THREE.Mesh(headBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
headMesh.name = "head";
|
|
|
|
scene.add(headMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Body Parts
|
|
|
|
bodyBox = new THREE.BoxGeometry(8, 12, 4, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(bodyBox,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
bodyMesh = new THREE.Mesh(bodyBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
bodyMesh.name = "body";
|
|
|
|
bodyMesh.position.y = -10;
|
|
|
|
scene.add(bodyMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Right Arm Parts
|
2017-08-30 14:26:04 +02:00
|
|
|
rightArmBox = new THREE.BoxGeometry(isSlim?3:4, 12, 4, 0, 0, 0);
|
|
|
|
if (isSlim) {
|
|
|
|
addVertices(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 {
|
|
|
|
addVertices(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)
|
|
|
|
);
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
rightArmMesh = new THREE.Mesh(rightArmBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
rightArmMesh.name = "rightArm";
|
|
|
|
rightArmMesh.position.y = -10;
|
2017-08-30 14:26:04 +02:00
|
|
|
rightArmMesh.position.x = isSlim?-5.5:-6;
|
2015-09-29 18:52:18 +02:00
|
|
|
scene.add(rightArmMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Left Arm Parts
|
2017-08-30 14:26:04 +02:00
|
|
|
leftArmBox = new THREE.BoxGeometry(isSlim?3:4, 12, 4, 0, 0, 0);
|
|
|
|
if (isSlim) {
|
|
|
|
addVertices(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 {
|
|
|
|
addVertices(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)
|
|
|
|
);
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
leftArmMesh = new THREE.Mesh(leftArmBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
leftArmMesh.name = "leftArm";
|
|
|
|
leftArmMesh.position.y = -10;
|
2017-08-30 14:26:04 +02:00
|
|
|
leftArmMesh.position.x = isSlim?5.5:6;
|
2015-09-29 18:52:18 +02:00
|
|
|
scene.add(leftArmMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Right Leg Parts
|
|
|
|
rightLegBox = new THREE.BoxGeometry(4, 12, 4, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(rightLegBox,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
rightLegMesh = new THREE.Mesh(rightLegBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
rightLegMesh.name = "rightLeg"
|
|
|
|
rightLegMesh.position.y = -22;
|
|
|
|
rightLegMesh.position.x = -2;
|
|
|
|
scene.add(rightLegMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Left Leg Parts
|
|
|
|
leftLegBox = new THREE.BoxGeometry(4, 12, 4, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(leftLegBox,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
leftLegMesh = new THREE.Mesh(leftLegBox, layer1Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
leftLegMesh.name = "leftLeg";
|
|
|
|
leftLegMesh.position.y = -22;
|
|
|
|
leftLegMesh.position.x = 2;
|
|
|
|
scene.add(leftLegMesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Head Overlay Parts
|
|
|
|
head2Box = new THREE.BoxGeometry(9, 9, 9, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(head2Box,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
head2Mesh = new THREE.Mesh(head2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
head2Mesh.name = "head2"
|
2017-08-30 07:59:00 +02:00
|
|
|
scene.add(head2Mesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Body Overlay Parts
|
|
|
|
body2Box = new THREE.BoxGeometry(9, 13.5, 4.5, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(body2Box,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
body2Mesh = new THREE.Mesh(body2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
body2Mesh.name = "body2";
|
|
|
|
body2Mesh.position.y = -10;
|
|
|
|
scene.add(body2Mesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Right Arm Overlay Parts
|
2017-08-30 14:26:04 +02:00
|
|
|
rightArm2Box = new THREE.BoxGeometry(isSlim?3.375:4.5, 13.5, 4.5, 0, 0, 0);
|
|
|
|
if (isSlim) {
|
|
|
|
addVertices(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 {
|
|
|
|
addVertices(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)
|
|
|
|
);
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
rightArm2Mesh = new THREE.Mesh(rightArm2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
rightArm2Mesh.name = "rightArm2";
|
|
|
|
rightArm2Mesh.position.y = -10;
|
|
|
|
rightArm2Mesh.position.x = -6;
|
|
|
|
scene.add(rightArm2Mesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Left Arm Overlay Parts
|
2017-08-30 14:26:04 +02:00
|
|
|
leftArm2Box = new THREE.BoxGeometry(isSlim?3.375:4.5, 13.5, 4.5, 0, 0, 0);
|
|
|
|
if (isSlim) {
|
|
|
|
addVertices(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 {
|
|
|
|
addVertices(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)
|
|
|
|
);
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
leftArm2Mesh = new THREE.Mesh(leftArm2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
leftArm2Mesh.name = "leftArm2";
|
|
|
|
leftArm2Mesh.position.y = -10;
|
|
|
|
leftArm2Mesh.position.x = 6;
|
|
|
|
// leftArm2Mesh.visible = true;
|
|
|
|
scene.add(leftArm2Mesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Right Leg Overlay Parts
|
|
|
|
rightLeg2Box = new THREE.BoxGeometry(4.5, 13.5, 4.5, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(rightLeg2Box,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
rightLeg2Mesh = new THREE.Mesh(rightLeg2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
rightLeg2Mesh.name = "rightLeg2"
|
|
|
|
rightLeg2Mesh.position.y = -22;
|
|
|
|
rightLeg2Mesh.position.x = -2;
|
|
|
|
scene.add(rightLeg2Mesh);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
// Left Leg Overlay Parts
|
2017-08-30 07:59:00 +02:00
|
|
|
leftLeg2Box = new THREE.BoxGeometry(4.5, 13.5, 4.5, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(leftLeg2Box,
|
|
|
|
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)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
leftLeg2Mesh = new THREE.Mesh(leftLeg2Box, layer2Material);
|
2015-09-29 18:52:18 +02:00
|
|
|
leftLeg2Mesh.name = "leftLeg2";
|
|
|
|
leftLeg2Mesh.position.y = -22;
|
|
|
|
leftLeg2Mesh.position.x = 2;
|
2017-08-29 13:43:35 +02:00
|
|
|
scene.add(leftLeg2Mesh);
|
|
|
|
|
2016-01-10 18:28:54 +01:00
|
|
|
// Cape Parts
|
2017-08-30 14:26:04 +02:00
|
|
|
// back = outside
|
|
|
|
// front = inside
|
2017-08-30 07:59:00 +02:00
|
|
|
capeBox = new THREE.BoxGeometry(10, 16, 1, 0, 0, 0);
|
2017-08-30 14:26:04 +02:00
|
|
|
addVertices(capeBox,
|
|
|
|
toCapeVertices(1, 0, 11, 0),
|
|
|
|
toCapeVertices(11, 0, 21, 0),
|
|
|
|
toCapeVertices(11, 1, 11, 17),
|
|
|
|
toCapeVertices(12, 1, 22, 17),
|
|
|
|
toCapeVertices(0, 1, 0, 17),
|
|
|
|
toCapeVertices(1, 1, 11, 17)
|
|
|
|
);
|
2017-08-29 13:43:35 +02:00
|
|
|
capeMesh = new THREE.Mesh(capeBox, capeMaterial);
|
2016-01-10 18:28:54 +01:00
|
|
|
capeMesh.name = "cape";
|
|
|
|
capeMesh.position.y = -12.75;
|
|
|
|
capeMesh.position.z = -0.55;
|
2017-08-30 14:26:04 +02:00
|
|
|
capePivot = new THREE.Group();
|
2016-01-10 18:28:54 +01:00
|
|
|
capePivot.rotation.x = 25 * (Math.PI/180);
|
2017-08-30 14:26:04 +02:00
|
|
|
scene.add(capePivot);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2017-08-29 18:15:57 +02:00
|
|
|
renderer = new THREE.WebGLRenderer({angleRot: true, alpha: true, antialias: false});
|
2015-09-29 18:52:18 +02:00
|
|
|
renderer.setSize(canvasW, canvasH);
|
2017-08-29 18:21:35 +02:00
|
|
|
renderer.context.getShaderInfoLog = () => ''; // shut firefox up
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
model.append(renderer.domElement);
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2016-01-10 18:28:54 +01:00
|
|
|
var startTime = Date.now();
|
2017-08-30 14:26:04 +02:00
|
|
|
var drawSkin = () => {
|
2015-09-29 18:52:18 +02:00
|
|
|
requestAnimationFrame(drawSkin);
|
2016-01-10 18:28:54 +01:00
|
|
|
var time = (Date.now() - startTime)/1000;
|
2015-09-29 18:52:18 +02:00
|
|
|
if(!mouseDown && !isPaused){
|
|
|
|
modelRot += 0.5;
|
|
|
|
angleRot += 0.01;
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
var ang = -(modelRot * Math.PI / 180);
|
|
|
|
|
|
|
|
camera.rotation.y = ang;
|
|
|
|
camera.position.z = radius*Math.cos(ang);
|
|
|
|
camera.position.x = radius*Math.sin(ang);
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2016-01-10 18:28:54 +01:00
|
|
|
var speed = 3;
|
2017-08-29 13:43:35 +02:00
|
|
|
//Leg Swing
|
2016-01-10 18:28:54 +01:00
|
|
|
leftLeg2Mesh.rotation.x = leftLegMesh.rotation.x = Math.cos(angleRot*speed);
|
2015-09-29 18:52:18 +02:00
|
|
|
leftLeg2Mesh.position.z = leftLegMesh.position.z = 0 - 6*Math.sin(leftLegMesh.rotation.x);
|
|
|
|
leftLeg2Mesh.position.y = leftLegMesh.position.y = -16 - 6*Math.abs(Math.cos(leftLegMesh.rotation.x));
|
2016-01-10 18:28:54 +01:00
|
|
|
rightLeg2Mesh.rotation.x = rightLegMesh.rotation.x = Math.cos(angleRot*speed + (Math.PI));
|
2015-09-29 18:52:18 +02:00
|
|
|
rightLeg2Mesh.position.z = rightLegMesh.position.z = 0 - 6*Math.sin(rightLegMesh.rotation.x);
|
|
|
|
rightLeg2Mesh.position.y = rightLegMesh.position.y = -16 - 6*Math.abs(Math.cos(rightLegMesh.rotation.x));
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
//Arm Swing
|
2016-01-10 18:28:54 +01:00
|
|
|
leftArm2Mesh.rotation.x = leftArmMesh.rotation.x = Math.cos(angleRot*speed + (Math.PI));
|
2015-09-29 18:52:18 +02:00
|
|
|
leftArm2Mesh.position.z = leftArmMesh.position.z = 0 - 6*Math.sin(leftArmMesh.rotation.x);
|
|
|
|
leftArm2Mesh.position.y = leftArmMesh.position.y = -4 - 6*Math.abs(Math.cos(leftArmMesh.rotation.x));
|
2016-01-10 18:28:54 +01:00
|
|
|
rightArm2Mesh.rotation.x = rightArmMesh.rotation.x = Math.cos(angleRot*speed);
|
2015-09-29 18:52:18 +02:00
|
|
|
rightArm2Mesh.position.z = rightArmMesh.position.z = 0 - 6*Math.sin(rightArmMesh.rotation.x);
|
|
|
|
rightArm2Mesh.position.y = rightArmMesh.position.y = -4 - 6*Math.abs(Math.cos(rightArmMesh.rotation.x));
|
2016-01-10 18:28:54 +01:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
renderer.render(scene, camera);
|
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
if(angleRot > 360)
|
2015-09-29 18:52:18 +02:00
|
|
|
angleRot = 0;
|
|
|
|
}
|
2017-08-29 13:43:35 +02:00
|
|
|
|
2015-09-29 18:52:18 +02:00
|
|
|
model.mousedown(function(e){
|
|
|
|
originMouseX = (e.pageX - this.offsetLeft) - modelRot;
|
|
|
|
mouseDown = true;
|
|
|
|
});
|
|
|
|
|
2017-08-30 07:59:00 +02:00
|
|
|
window.jQuery(document).mouseup(() => mouseDown = false);
|
2015-09-29 18:52:18 +02:00
|
|
|
|
2017-08-29 17:04:08 +02:00
|
|
|
model.bind("contextmenu", e => {
|
2015-09-29 18:52:18 +02:00
|
|
|
e.preventDefault();
|
|
|
|
isPaused = !isPaused;
|
|
|
|
});
|
|
|
|
|
|
|
|
model.mousemove(function(e){
|
2017-08-30 07:59:00 +02:00
|
|
|
if(!mouseDown) return;
|
2015-09-29 18:52:18 +02:00
|
|
|
var x = (e.pageX - this.offsetLeft) - originMouseX;
|
2017-08-29 13:43:35 +02:00
|
|
|
modelRot = x;
|
2016-01-10 18:28:54 +01:00
|
|
|
});
|
2017-08-29 13:43:35 +02:00
|
|
|
}
|