mirror of
https://github.com/haselkern/Minecraft-ArmorStand.git
synced 2025-05-18 05:55:35 +00:00
Fixed Rotations
Minecraft uses world rotation, three.js uses local rotation. I was unable to find a way to convert the rotations, until now.
This commit is contained in:
parent
6bb0885d54
commit
5c466e71d2
2 changed files with 25 additions and 7 deletions
|
@ -28,7 +28,6 @@
|
||||||
<div id="card">
|
<div id="card">
|
||||||
|
|
||||||
<h1>MINECRAFT ARMOR STAND</h1>
|
<h1>MINECRAFT ARMOR STAND</h1>
|
||||||
<b>Please note:</b> some rotation values do not work correctly.
|
|
||||||
<div class="padding">
|
<div class="padding">
|
||||||
<center>
|
<center>
|
||||||
<a href="https://github.com/haselkern/Minecraft-ArmorStand" target="_blank"><img src="images/github.png" alt="GitHub" title="GitHub" /></a>
|
<a href="https://github.com/haselkern/Minecraft-ArmorStand" target="_blank"><img src="images/github.png" alt="GitHub" title="GitHub" /></a>
|
||||||
|
|
31
js/main.js
31
js/main.js
|
@ -358,12 +358,12 @@ function updateUI(){
|
||||||
|
|
||||||
// Rotate 3D Stuff
|
// Rotate 3D Stuff
|
||||||
// y and z rotation needs to be inverted
|
// y and z rotation needs to be inverted
|
||||||
mBody.rotation.set(body.x * DEG2RAD, -body.y * DEG2RAD, -body.z * DEG2RAD);
|
setRotation(mBody, body);
|
||||||
mHead.rotation.set(head.x * DEG2RAD, -head.y * DEG2RAD, -head.z * DEG2RAD);
|
setRotation(mHead, head);
|
||||||
mLegLeft.rotation.set(leftLeg.x * DEG2RAD, -leftLeg.y * DEG2RAD, -leftLeg.z * DEG2RAD);
|
setRotation(mLegLeft, leftLeg);
|
||||||
mLegRight.rotation.set(rightLeg.x * DEG2RAD, -rightLeg.y * DEG2RAD, -rightLeg.z * DEG2RAD);
|
setRotation(mLegRight, rightLeg);
|
||||||
mArmLeft.rotation.set(leftArm.x * DEG2RAD, -leftArm.y * DEG2RAD, -leftArm.z * DEG2RAD);
|
setRotation(mArmLeft, leftArm);
|
||||||
mArmRight.rotation.set(rightArm.x * DEG2RAD, -rightArm.y * DEG2RAD, -rightArm.z * DEG2RAD);
|
setRotation(mArmRight, rightArm);
|
||||||
armorstand.rotation.y = -rotation * DEG2RAD;
|
armorstand.rotation.y = -rotation * DEG2RAD;
|
||||||
|
|
||||||
// Scale model, depending on small variable
|
// Scale model, depending on small variable
|
||||||
|
@ -624,3 +624,22 @@ function getLeatherColorString(element, condition){
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rotate three.js mesh to fit the minecraft rotation
|
||||||
|
function setRotation(mesh, rotation){
|
||||||
|
rotateAroundWorldAxis(mesh, new THREE.Vector3(1,0,0), rotation.x * DEG2RAD, true);
|
||||||
|
rotateAroundWorldAxis(mesh, new THREE.Vector3(0,1,0), -rotation.y * DEG2RAD, false);
|
||||||
|
rotateAroundWorldAxis(mesh, new THREE.Vector3(0,0,1), -rotation.z * DEG2RAD, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// From here: http://stackoverflow.com/a/11124197/1456971
|
||||||
|
var rotWorldMatrix;
|
||||||
|
// Rotate an object around an arbitrary axis in world space
|
||||||
|
function rotateAroundWorldAxis(object, axis, radians, reset) {
|
||||||
|
rotWorldMatrix = new THREE.Matrix4();
|
||||||
|
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
|
||||||
|
if(!reset)
|
||||||
|
rotWorldMatrix.multiply(object.matrix); // pre-multiply
|
||||||
|
object.matrix = rotWorldMatrix;
|
||||||
|
object.rotation.setFromRotationMatrix(object.matrix);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue