mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-03-25 17:11:15 +08:00
Merge branch 'ik' into 3.7
This commit is contained in:
commit
8b940fae21
@ -51,9 +51,10 @@
|
||||
<script src="lib/three_custom.js"></script>
|
||||
<script src="lib/GLTFExporter.js"></script>
|
||||
<script src="lib/CanvasFrame.js"></script>
|
||||
<!--script src="lib/fik.min.js"></script-->
|
||||
<script src="lib/fik.min.js"></script>
|
||||
<script src="lib/molang.umd.js"></script>
|
||||
<script src="lib/wintersky.umd.js"></script>
|
||||
|
||||
<script src="js/preview/OrbitControls.js"></script>
|
||||
<script src="js/outliner/tree.vue.js"></script>
|
||||
|
||||
|
@ -1704,7 +1704,6 @@ BARS.defineActions(function() {
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
//Inverse Kinematics
|
||||
new Action('ik_enabled', {
|
||||
icon: 'check_box_outline_blank',
|
||||
@ -1729,6 +1728,7 @@ BARS.defineActions(function() {
|
||||
},
|
||||
change: function(modify) {
|
||||
Group.selected.ik_chain_length = modify(Group.selected.ik_chain_length);
|
||||
updateSelection()
|
||||
},
|
||||
onBefore: function() {
|
||||
Undo.initEdit({keyframes: Timeline.selected})
|
||||
@ -1736,8 +1736,7 @@ BARS.defineActions(function() {
|
||||
onAfter: function() {
|
||||
Undo.finishEdit('move keyframes')
|
||||
}
|
||||
})*/
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Interface.definePanels(function() {
|
||||
|
@ -87,8 +87,8 @@ function updateNslideValues() {
|
||||
}
|
||||
}
|
||||
if (Modes.animate && Group.selected) {
|
||||
//BarItems.slider_ik_chain_length.update();
|
||||
//BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank')
|
||||
BarItems.slider_ik_chain_length.update();
|
||||
BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank')
|
||||
}
|
||||
}
|
||||
function setProjectResolution(width, height, modify_uv) {
|
||||
|
@ -16,7 +16,7 @@ const Clipbench = {
|
||||
let p = Prop.active_panel;
|
||||
let text;
|
||||
if (!check) {
|
||||
text = window.getSelection()+'';
|
||||
text = getFocusedTextInput() && window.getSelection()+'';
|
||||
}
|
||||
if (text) {
|
||||
return Clipbench.types.text;
|
||||
@ -30,7 +30,7 @@ const Clipbench = {
|
||||
if (display_mode) {
|
||||
return Clipbench.types.display_slot
|
||||
}
|
||||
if (Animator.open && Timeline.animators.length && (Timeline.selected.length || mode === 2) && ['keyframe', 'timeline'].includes(p)) {
|
||||
if (Animator.open && Timeline.animators.length && (Timeline.selected.length || mode === 2) && ['keyframe', 'timeline', 'preview'].includes(p)) {
|
||||
return Clipbench.types.keyframe
|
||||
}
|
||||
if ((p == 'uv' || p == 'preview') && Modes.edit) {
|
||||
|
@ -1559,7 +1559,6 @@ const BARS = {
|
||||
'rescale_toggle'
|
||||
]
|
||||
})
|
||||
/*
|
||||
Toolbars.bone_ik = new Toolbar({
|
||||
id: 'bone_ik',
|
||||
children: [
|
||||
@ -1567,7 +1566,7 @@ const BARS = {
|
||||
'slider_ik_chain_length'
|
||||
],
|
||||
default_place: !Blockbench.isMobile
|
||||
})*/
|
||||
})
|
||||
|
||||
|
||||
Toolbars.palette = new Toolbar({
|
||||
|
@ -222,15 +222,15 @@ function setupPanels() {
|
||||
condition: {modes: ['animate']},
|
||||
selection_only: true,
|
||||
toolbars: {
|
||||
//bone_ik: Toolbars.bone_ik,
|
||||
bone_ik: Toolbars.bone_ik,
|
||||
},
|
||||
component: {
|
||||
template: `
|
||||
<div>
|
||||
<p>${ tl('panel.element.origin') }</p>
|
||||
<div class="toolbar_wrapper bone_origin"></div>
|
||||
<!--p>${ tl('panel.bone.ik') }</p>
|
||||
<div class="toolbar_wrapper bone_ik"></div-->
|
||||
<p>${ tl('panel.bone.ik') }</p>
|
||||
<div class="toolbar_wrapper bone_ik"></div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
@ -468,6 +468,8 @@ class Group extends OutlinerElement {
|
||||
}});
|
||||
new Property(Group, 'vector', 'rotation');
|
||||
new Property(Group, 'array', 'cem_animations', {condition: () => Format.id == 'optifine_entity'});
|
||||
new Property(Group, 'boolean', 'ik_enabled', {condition: () => Format.animation_mode});
|
||||
new Property(Group, 'number', 'ik_chain_length', {condition: () => Format.animation_mode});
|
||||
|
||||
|
||||
function getCurrentGroup() {
|
||||
|
@ -605,6 +605,7 @@
|
||||
var pointerVector = new THREE.Vector2();
|
||||
|
||||
var point = new THREE.Vector3();
|
||||
var originalPoint = new THREE.Vector3();
|
||||
var offset = new THREE.Vector3();
|
||||
var scale = 1;
|
||||
var eye = new THREE.Vector3();
|
||||
@ -910,6 +911,9 @@
|
||||
Group.selected.mesh.getWorldPosition(this.position);
|
||||
if (Toolbox.selected.id == 'resize_tool') {
|
||||
Transformer.rotation_ref = Group.selected.mesh;
|
||||
} else if (Toolbox.selected.id == 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) {
|
||||
if (Transformer.dragging && Transformer.ik_target) Transformer.position.copy(Transformer.ik_target);
|
||||
delete Transformer.rotation_ref;
|
||||
} else {
|
||||
Transformer.rotation_ref = Group.selected.mesh.parent;
|
||||
}
|
||||
@ -1017,7 +1021,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
function beforeFirstChange(event) {
|
||||
function beforeFirstChange(event, point) {
|
||||
if (scope.hasChanged) return;
|
||||
|
||||
if (Modes.edit || Toolbox.selected.id == 'pivot_tool') {
|
||||
@ -1050,110 +1054,73 @@
|
||||
var undo_keyframes = [];
|
||||
var animator = Animation.selected.getBoneAnimator();
|
||||
if (animator && Toolbox.selected.id === 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) {
|
||||
/*
|
||||
|
||||
|
||||
Transformer.bones = [];
|
||||
originalPoint.copy(point);
|
||||
|
||||
var bone = Group.selected;
|
||||
for (var i = Group.selected.ik_chain_length; i > 0; i--) {
|
||||
bone = bone.parent;
|
||||
for (var i = Group.selected.ik_chain_length; i >= 0; i--) {
|
||||
if (bone instanceof Group) {
|
||||
var animator = Animation.selected.getBoneAnimator(bone);
|
||||
animator.addToTimeline();
|
||||
var {before, result} = animator.getOrMakeKeyframe('rotation');
|
||||
scope.keyframes[i-1] = result;
|
||||
scope.keyframes[i] = result;
|
||||
if (before) undo_keyframes.push(before);
|
||||
}
|
||||
bone = bone.parent;
|
||||
}
|
||||
Undo.initEdit({keyframes: undo_keyframes})
|
||||
|
||||
var solver = new FIK.Structure3D(scene);
|
||||
|
||||
var chain = new FIK.Chain3D();
|
||||
var start = new FIK.V3(0, 0, 0);
|
||||
var endLoc = new FIK.V3(0, 2, 0);
|
||||
|
||||
var basebone;
|
||||
|
||||
|
||||
var bones = [];
|
||||
let basebone;
|
||||
let bones = [];
|
||||
var bone = Group.selected;
|
||||
for (var i = Group.selected.ik_chain_length; i >= 0; i--) {
|
||||
for (let i = Group.selected.ik_chain_length; i >= 0; i--) {
|
||||
if (bone instanceof Group) {
|
||||
bones.push(bone);
|
||||
bone = bone.parent;
|
||||
}
|
||||
}
|
||||
|
||||
bones.reverse();
|
||||
var parent_bone;
|
||||
|
||||
let solver = new FIK.Structure3D(scene);
|
||||
let chain = new FIK.Chain3D();
|
||||
|
||||
bones.forEach((bone, i) => {
|
||||
|
||||
var copy_bone = new THREE.Bone();
|
||||
var startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3()))
|
||||
if (!bones[i+1]) return;
|
||||
|
||||
var bone = new FIK.Bone3D(startPoint, startPoint)
|
||||
chain.addBone(bone)
|
||||
let startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3()))
|
||||
let endPoint = new FIK.V3(0,0,0).copy(bones[i+1].mesh.getWorldPosition(new THREE.Vector3()))
|
||||
|
||||
let ik_bone = new FIK.Bone3D(startPoint, endPoint)
|
||||
chain.addBone(ik_bone)
|
||||
Transformer.bones.push({
|
||||
bone,
|
||||
ik_bone,
|
||||
last_rotation: new THREE.Euler().copy(bone.mesh.rotation),
|
||||
ik_bone,
|
||||
last_diff: new THREE.Vector3(
|
||||
bones[i+1].origin[0] - bone.origin[0],
|
||||
bones[i+1].origin[1] - bone.origin[1],
|
||||
bones[i+1].origin[2] - bone.origin[2]
|
||||
)
|
||||
})
|
||||
if (!basebone) {
|
||||
basebone = bone;
|
||||
basebone = ik_bone;
|
||||
}
|
||||
})
|
||||
|
||||
Transformer.original_target_rotation = Group.selected.mesh.getWorldQuaternion(new THREE.Quaternion());
|
||||
Transformer.ik_target = new THREE.Vector3().copy(Transformer.position);
|
||||
|
||||
//chain.addBone(new FIK.Bone3D(new FIK.V3(1, 2, 0), new FIK.V3(0, 6, 0), undefined, 1, 0x00FF00));
|
||||
//chain.addBone(new FIK.Bone3D(new FIK.V3(0, 6, 0), new FIK.V3(0, 9, 0), undefined, 1, 0x0000FF));
|
||||
var target = new FIK.V3()
|
||||
solver.add(chain, Transformer.ik_target , true);
|
||||
Transformer.ik_solver = solver;
|
||||
|
||||
solver.add(chain, target, true);
|
||||
Transformer.solver = solver
|
||||
|
||||
/*
|
||||
|
||||
var ik_solver = Transformer.ik_solver = {};
|
||||
|
||||
|
||||
ik_solver.ik = new THREE.IK();
|
||||
ik_solver.chain = new THREE.IKChain();
|
||||
ik_solver.target = new THREE.Object3D();
|
||||
ik_solver.copy_bones = [];
|
||||
scene.add(ik_solver.target)
|
||||
|
||||
var bones = [];
|
||||
var bone = Group.selected;
|
||||
for (var i = Group.selected.ik_chain_length; i >= 0; i--) {
|
||||
if (bone instanceof Group) {
|
||||
bones.push(bone);
|
||||
bone = bone.parent;
|
||||
}
|
||||
}
|
||||
//build proxy chain
|
||||
bones.reverse();
|
||||
var parent_bone;
|
||||
bones.forEach((bone, i) => {
|
||||
var copy_bone = new THREE.Bone();
|
||||
if (!ik_solver.root_bone) {
|
||||
ik_solver.root_bone = copy_bone;
|
||||
bone.mesh.getWorldPosition(copy_bone.position)
|
||||
} else {
|
||||
parent_bone.add(copy_bone);
|
||||
copy_bone.position.z = bone.mesh.position.length();
|
||||
parent_bone.quaternion.setFromUnitVectors(new THREE.Vector3().copy(bone.mesh.position).normalize(), THREE.NormalZ);
|
||||
}
|
||||
ik_solver.chain.add(new THREE.IKJoint(copy_bone), {target: i == bones.length-1 ? ik_solver.target : null});
|
||||
copy_bone.original = bone;
|
||||
ik_solver.copy_bones.push(copy_bone)
|
||||
copy_bone.last_rotation = new THREE.Euler().copy(copy_bone.rotation);
|
||||
parent_bone = copy_bone;
|
||||
Transformer.ik_solver.meshChains[0].forEach(mesh => {
|
||||
mesh.visible = false;
|
||||
})
|
||||
|
||||
|
||||
ik_solver.ik.add(ik_solver.chain);
|
||||
scene.add(ik_solver.root_bone);
|
||||
|
||||
ik_solver.helper = new THREE.IKHelper(ik_solver.ik);
|
||||
scene.add(ik_solver.helper);
|
||||
|
||||
setTimeout(_ => ik_solver.ik.solve(), 80)*/
|
||||
|
||||
|
||||
|
||||
} else if (animator) {
|
||||
|
||||
var {before, result} = animator.getOrMakeKeyframe(Toolbox.selected.animation_channel);
|
||||
@ -1358,53 +1325,69 @@
|
||||
originalValue = value;
|
||||
}
|
||||
|
||||
|
||||
if (value !== previousValue && Animation.selected && Animation.selected.getBoneAnimator()) {
|
||||
beforeFirstChange(event)
|
||||
beforeFirstChange(event, planeIntersect.point)
|
||||
|
||||
var difference = value - (previousValue||0)
|
||||
if (Toolbox.selected.id === 'rotate_tool' && Math.abs(difference) > 120) {
|
||||
difference = 0;
|
||||
}
|
||||
if (axis == 'x' && Toolbox.selected.id === 'move_tool') {
|
||||
difference *= -1
|
||||
}
|
||||
if (Group.selected.ik_enabled) {
|
||||
|
||||
Transformer.position.x += 1
|
||||
Transformer.solver.update();
|
||||
|
||||
|
||||
//scope.keyframes[0].offset(axis, difference);
|
||||
//scope.keyframes[0].select()
|
||||
|
||||
|
||||
/*
|
||||
var ik_solver = Transformer.ik_solver;
|
||||
|
||||
ik_solver.target.position.copy(planeIntersect.point);
|
||||
Transformer.ik_target[axis] += difference
|
||||
|
||||
main_preview.render()
|
||||
Transformer.ik_solver.update();
|
||||
let lim = 12;
|
||||
|
||||
ik_solver.ik.solve();
|
||||
|
||||
ik_solver.copy_bones.forEach((copy_bone, i) => {
|
||||
Transformer.bones.forEach((bone, i) => {
|
||||
var keyframe = scope.keyframes[i];
|
||||
if (keyframe) {
|
||||
var bone = copy_bone.original;
|
||||
var animator = Animation.selected.getBoneAnimator(bone);
|
||||
|
||||
keyframe.offset('x', Math.radToDeg(copy_bone.last_rotation.x - copy_bone.rotation.x));
|
||||
keyframe.offset('y', Math.radToDeg(copy_bone.last_rotation.y - copy_bone.rotation.y));
|
||||
keyframe.offset('z', Math.radToDeg(copy_bone.last_rotation.z - copy_bone.rotation.z));
|
||||
let euler = new THREE.Euler()
|
||||
let q = new THREE.Quaternion()
|
||||
|
||||
let start = new THREE.Vector3().copy(Transformer.ik_solver.chains[0].bones[i].start)
|
||||
let end = new THREE.Vector3().copy(Transformer.ik_solver.chains[0].bones[i].end)
|
||||
Transformer.bones[i].bone.mesh.worldToLocal(start)
|
||||
Transformer.bones[i].bone.mesh.worldToLocal(end)
|
||||
let diff = new THREE.Vector3().copy(end).sub(start)
|
||||
|
||||
let v1 = new THREE.Vector3().copy(diff).normalize();
|
||||
let v2 = new THREE.Vector3().copy(bone.last_diff).normalize();
|
||||
v1.x *= -1;
|
||||
v2.x *= -1;
|
||||
|
||||
copy_bone.last_rotation.copy(copy_bone.rotation);
|
||||
q.setFromUnitVectors(v1, v2)
|
||||
euler.setFromQuaternion(q)
|
||||
|
||||
keyframe.offset('x', Math.clamp(Math.radToDeg(euler.x), -lim, lim));
|
||||
keyframe.offset('y', Math.clamp(Math.radToDeg(euler.y), -lim, lim));
|
||||
keyframe.offset('z', Math.clamp(Math.radToDeg(euler.z), -lim, lim));
|
||||
|
||||
Animator.preview()
|
||||
}
|
||||
})
|
||||
let last_keyframe = Transformer.keyframes.last();
|
||||
|
||||
let group_parent_rot = Group.selected.mesh.parent.getWorldQuaternion(new THREE.Quaternion());
|
||||
let diff_rot = new THREE.Quaternion().copy(Transformer.original_target_rotation);
|
||||
diff_rot.premultiply(group_parent_rot.inverse());
|
||||
let diff_rot_e = new THREE.Euler().setFromQuaternion(diff_rot, 'ZYX');
|
||||
|
||||
last_keyframe.offset('x', Math.clamp( Math.radToDeg(Group.selected.mesh.rotation.x - diff_rot_e.x), -lim, lim));
|
||||
last_keyframe.offset('y', Math.clamp( Math.radToDeg(Group.selected.mesh.rotation.y - diff_rot_e.y), -lim, lim));
|
||||
last_keyframe.offset('z', Math.clamp(-Math.radToDeg(Group.selected.mesh.rotation.z - diff_rot_e.z), -lim, lim));
|
||||
Animator.preview()
|
||||
|
||||
*/
|
||||
|
||||
} else {
|
||||
if (axis == 'x' && Toolbox.selected.id === 'move_tool') {
|
||||
difference *= -1
|
||||
}
|
||||
scope.keyframes[0].offset(axis, difference);
|
||||
scope.keyframes[0].select()
|
||||
scope.keyframes[0].select();
|
||||
}
|
||||
displayDistance(value - originalValue);
|
||||
|
||||
@ -1520,6 +1503,14 @@
|
||||
} else if (Modes.id === 'display') {
|
||||
Undo.finishEdit('edit display slot')
|
||||
}
|
||||
|
||||
if (Modes.animate && Toolbox.selected.id === 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length && Transformer.ik_solver) {
|
||||
Transformer.ik_solver.meshChains[0].forEach(mesh => {
|
||||
scene.remove(mesh)
|
||||
})
|
||||
delete Transformer.ik_solver;
|
||||
updateSelection()
|
||||
}
|
||||
}
|
||||
_dragging = false;
|
||||
|
||||
|
@ -53,6 +53,9 @@ class Property {
|
||||
if (options.label) this.label = options.label;
|
||||
if (options.options) this.options = options.options;
|
||||
}
|
||||
delete() {
|
||||
delete this.class.properties[this.name];
|
||||
}
|
||||
getDefault(instance) {
|
||||
if (typeof this.default == 'function') {
|
||||
return this.default(instance);
|
||||
|
@ -159,7 +159,7 @@ const TextureGenerator = {
|
||||
var res = options.resolution;
|
||||
var background_color = options.color;
|
||||
var texture = options.texture;
|
||||
var min_size = Project.box_uv ? 0 : 1;
|
||||
var min_size = (Project.box_uv || options.box_uv) ? 0 : 1;
|
||||
var res_multiple = res / 16
|
||||
var templates = [];
|
||||
var doubles = {};
|
||||
@ -173,7 +173,7 @@ const TextureGenerator = {
|
||||
let obj = cubes[i]
|
||||
if (obj.visibility === true) {
|
||||
var template = new TextureGenerator.boxUVCubeTemplate(obj, min_size);
|
||||
if (options.double_use && Project.box_uv && textures.length) {
|
||||
if (options.double_use && (Project.box_uv || options.box_uv) && textures.length) {
|
||||
var double_key = [...obj.uv_offset, ...obj.size(undefined, true), ].join('_')
|
||||
if (doubles[double_key]) {
|
||||
// improve chances that original is not mirrored
|
||||
|
@ -1011,7 +1011,10 @@
|
||||
"action.timeline_focus": "Filter Channels",
|
||||
"action.timeline_focus.desc": "Select the animation channels to display in the timeline",
|
||||
"action.timeline_focus.hide_empty": "Hide empty channels",
|
||||
|
||||
"action.ik_enabled": "Enable IK",
|
||||
"action.ik_enabled.desc": "Enable Inverse Kinematics for this bone",
|
||||
"action.slider_ik_chain_length": "IK Chain Length",
|
||||
"action.slider_ik_chain_length.desc": "Upwards length of the IK bone chain",
|
||||
|
||||
"timeline.rotation": "Rotation",
|
||||
"timeline.position": "Position",
|
||||
@ -1187,6 +1190,7 @@
|
||||
"panel.element.rotation": "Rotation",
|
||||
|
||||
"panel.bone": "Bone",
|
||||
"panel.bone.ik": "Inverse Kinematics (Experimental)",
|
||||
|
||||
"uv_editor.title": "UV Editor",
|
||||
"uv_editor.all_faces": "All",
|
||||
|
10
lib/fik.min.js
vendored
10
lib/fik.min.js
vendored
@ -52,10 +52,10 @@ updateChainLength:function(){this.chainLength=0;for(var a=this.numBones;a--;)thi
|
||||
d.end),c=a.getBaseboneConstraintType(),c){case 4:case 5:this.tmpMtx.createRotationMatrix(d.getDirectionUV()),d=a.getBaseboneConstraintUV().clone().applyM3(this.tmpMtx),a.setBaseboneRelativeConstraintUV(d),5===c&&a.setBaseboneRelativeReferenceConstraintUV(a.bones[0].joint.getHingeReferenceAxis().clone().applyM3(this.tmpMtx))}a.useEmbeddedTarget?a.solveForEmbeddedTarget():a.solveForTarget(b);if(this.isWithMesh)for(b=this.meshChains[e],d=0;d<a.numBones;d++)c=a.bones[d],b[d].position.copy(c.start),b[d].lookAt(c.end)}},
|
||||
clear:function(){this.clearAllBoneMesh();var a;for(a=this.numChains;a--;)this.remove(a);this.chains=[];this.meshChains=[];this.targets=[]},add:function(a,b,c){this.chains.push(a);this.targets.push(b);this.numChains++;c&&this.addChainMeshs(a)},remove:function(a){this.chains[a].clear();this.chains.splice(a,1);this.meshChains.splice(a,1);this.targets.splice(a,1);this.numChains--},setFixedBaseMode:function(a){this.fixedBaseMode=a;a=this.numChains;for(var b;a--;)b=this.chains[a].getConnectedChainNumber(),
|
||||
-1===b&&this.chains[a].setFixedBaseMode(this.fixedBaseMode)},getNumChains:function(){return this.numChains},getChain:function(a){return this.chains[a]},connectChain:function(a,b,c,d,e,g,f){if(!(b>this.numChains||c>this.chains[b].numBones)){a=a.clone();void 0!==f&&a.setColor(f);a.setBoneConnectionPoint("end"===d?21:20);a.setConnectedChainNumber(b);a.setConnectedBoneNumber(c);b="end"===d?this.chains[b].bones[c].end:this.chains[b].bones[c].start;a.setBaseLocation(b);a.setFixedBaseMode(!0);for(c=0;c<
|
||||
a.numBones;c++)a.bones[c].start.add(b),a.bones[c].end.add(b);this.add(a,e,g)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d],d-1,b,a));this.meshChains.push(b)},addBoneMesh:function(a,b,c,d){var e=a.length,g=a.color,f=new THREE.CylinderBufferGeometry(1,.5,e,4);f.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));f.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,.5*e));var h=new THREE.MeshStandardMaterial({color:g,
|
||||
wireframe:!1,shadowSide:!1}),l=new THREE.MeshBasicMaterial({wireframe:!0}),m=null;e=a.joint.type;switch(e){case 10:l.color.setHex(16737792);if(a.joint.rotor===Math.PI)break;a=new THREE.CylinderBufferGeometry(0,2,2,6,1,!0);a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));a.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,1));m=new THREE.Mesh(a,l);break;case 12:g=a.joint.getHingeRotationAxis();var n=a.joint.min;a=a.joint.max;m=2;l.color.setHex(16776960);a=new THREE.CircleBufferGeometry(m,
|
||||
12,n,-n+a);1===g.z&&a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));1===g.y&&(a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI)));1===g.x&&a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*Math.PI));m=new THREE.Mesh(a,l);break;case 11:g=a.joint.getHingeRotationAxis(),m=2,n=a.joint.min,a=a.joint.max,l.color.setHex(65535),a=new THREE.CircleBufferGeometry(m,12,n,-n+a),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*
|
||||
-Math.PI)),1===g.z&&(a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*Math.PI))),1===g.x&&a.applyMatrix((new THREE.Matrix4).makeRotationZ(.5*-Math.PI)),1===g.y&&(a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*Math.PI))),m=new THREE.Mesh(a,l)}g=new THREE.AxesHelper(1.5);f=new THREE.Mesh(f,h);f.add(g);this.scene.add(f);f.castShadow=!0;f.receiveShadow=!0;-1!==b?null!==m&&(12!==
|
||||
a.numBones;c++)a.bones[c].start.add(b),a.bones[c].end.add(b);this.add(a,e,g)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d],d-1,b,a));this.meshChains.push(b)},addBoneMesh:function(a,b,c,d){var e=a.length,g=a.color,f=new THREE.CylinderBufferGeometry(1,.5,e,4);f.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));f.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,.5*e));var h=new THREE.MeshStandardMaterial({color:g,
|
||||
wireframe:!1,shadowSide:!1}),l=new THREE.MeshBasicMaterial({wireframe:!0}),m=null;e=a.joint.type;switch(e){case 10:l.color.setHex(16737792);if(a.joint.rotor===Math.PI)break;a=new THREE.CylinderBufferGeometry(0,2,2,6,1,!0);a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));a.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,1));m=new THREE.Mesh(a,l);break;case 12:g=a.joint.getHingeRotationAxis();var n=a.joint.min;a=a.joint.max;m=2;l.color.setHex(16776960);a=new THREE.CircleBufferGeometry(m,
|
||||
12,n,-n+a);1===g.z&&a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));1===g.y&&(a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI)));1===g.x&&a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*Math.PI));m=new THREE.Mesh(a,l);break;case 11:g=a.joint.getHingeRotationAxis(),m=2,n=a.joint.min,a=a.joint.max,l.color.setHex(65535),a=new THREE.CircleBufferGeometry(m,12,n,-n+a),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*
|
||||
-Math.PI)),1===g.z&&(a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*Math.PI))),1===g.x&&a.applyMatrix4((new THREE.Matrix4).makeRotationZ(.5*-Math.PI)),1===g.y&&(a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*Math.PI))),m=new THREE.Mesh(a,l)}g=new THREE.AxesHelper(1.5);f=new THREE.Mesh(f,h);f.add(g);this.scene.add(f);f.castShadow=!0;f.receiveShadow=!0;-1!==b?null!==m&&(12!==
|
||||
e?(m.position.z=d.bones[b].length,c[b].add(m)):f.add(m)):null!==m&&f.add(m);return f},clearAllBoneMesh:function(){if(this.isWithMesh){var a,b;for(a=this.meshChains.length;a--;){for(b=this.meshChains[a].length;b--;){var c=this.meshChains[a][b];this.scene.remove(c);c.geometry.dispose();c.material.dispose()}this.meshChains[a]=[]}this.meshChains=[]}}});Object.assign(w.prototype,{isJoint2D:!0,clone:function(){var a=new w;a.coordinateSystem=this.coordinateSystem;a.max=this.max;a.min=this.min;return a},
|
||||
validateAngle:function(a){a=0>a?0:a;return 180<a?180:a},set:function(a){this.max=a.max;this.min=a.min;this.coordinateSystem=a.coordinateSystem},setClockwiseConstraintDegs:function(a){this.min=-(this.validateAngle(a)*n)},setAnticlockwiseConstraintDegs:function(a){this.max=this.validateAngle(a)*n},setConstraintCoordinateSystem:function(a){this.coordinateSystem=a},getConstraintCoordinateSystem:function(){return this.coordinateSystem}});Object.assign(x.prototype,{isBone2D:!0,clone:function(){var a=new x(this.start,
|
||||
this.end);a.length=this.length;a.globalConstraintUV=this.globalConstraintUV;a.boneConnectionPoint=this.boneConnectionPoint;a.joint=this.joint.clone();a.color=this.color;a.name=this.name;return a},setName:function(a){this.name=a},setColor:function(a){this.color=a},setBoneConnectionPoint:function(a){this.boneConnectionPoint=a},setStartLocation:function(a){this.start.copy(a)},setEndLocation:function(a){this.end.copy(a)},setLength:function(a){0<a&&(this.length=a)},setGlobalConstraintUV:function(a){this.globalConstraintUV=
|
||||
@ -76,7 +76,7 @@ updateChainLength:function(){this.chainLength=0;for(var a=this.numBones;a--;)thi
|
||||
a.setBaseLocation(20===a.getBoneConnectionPoint()?e.start:e.end),e=e.getDirectionUV(),7===c?a.setBaseboneConstraintUV(e):8===c&&(c=F.getSignedAngle(e),c=a.getBaseboneConstraintUV().clone().rotate(c),a.setBaseboneRelativeConstraintUV(c))),a.useEmbeddedTarget?a.solveForEmbeddedTarget():a.solveForTarget(b),this.isWithMesh)for(b=this.meshChains[f],e=0;e<a.numBones;e++)c=a.bones[e],b[e].position.set(c.start.x,c.start.y,0),b[e].lookAt(d.set(c.end.x,c.end.y,0))},setFixedBaseMode:function(a){this.fixedBaseMode=
|
||||
a;a=this.numChains;for(var b;a--;)b=this.chains[a].getConnectedChainNumber(),-1===b&&this.chains[a].setFixedBaseMode(this.fixedBaseMode)},clear:function(){this.clearAllBoneMesh();var a;for(a=this.numChains;a--;)this.remove(a);this.chains=[];this.meshChains=[];this.targets=[]},add:function(a,b,c){this.chains.push(a);this.targets.push(b);this.numChains++;c&&this.addChainMeshs(a)},remove:function(a){this.chains[a].clear();this.chains.splice(a,1);this.meshChains.splice(a,1);this.targets.splice(a,1);this.numChains--},
|
||||
getNumChains:function(){return this.numChains},getChain:function(a){return this.chains[a]},connectChain:function(a,b,c,d,e,f,h){d=d||"end";if(b>this.numChains)p.error("Chain not existe !");else if(c>this.chains[b].numBones)p.error("Bone not existe !");else{a=a.clone();a.setBoneConnectionPoint("end"===d?21:20);a.setConnectedChainNumber(b);a.setConnectedBoneNumber(c);b="end"===d?this.chains[b].bones[c].end:this.chains[b].bones[c].start;a.setBaseLocation(b);a.setFixedBaseMode(!0);for(c=0;c<a.numBones;c++)a.bones[c].start.add(b),
|
||||
a.bones[c].end.add(b);this.add(a,e,f)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d]));this.meshChains.push(b)},addBoneMesh:function(a){var b=a.length,c=a.color;a=new THREE.CylinderBufferGeometry(1,.5,b,4);a.applyMatrix((new THREE.Matrix4).makeRotationX(-m.pi90));a.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,.5*b));b=new THREE.MeshStandardMaterial({color:c,wireframe:!1,shadowSide:!1});new THREE.MeshBasicMaterial({wireframe:!0});
|
||||
a.bones[c].end.add(b);this.add(a,e,f)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d]));this.meshChains.push(b)},addBoneMesh:function(a){var b=a.length,c=a.color;a=new THREE.CylinderBufferGeometry(1,.5,b,4);a.applyMatrix4((new THREE.Matrix4).makeRotationX(-m.pi90));a.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,.5*b));b=new THREE.MeshStandardMaterial({color:c,wireframe:!1,shadowSide:!1});new THREE.MeshBasicMaterial({wireframe:!0});
|
||||
b=new THREE.Mesh(a,b);b.castShadow=!0;b.receiveShadow=!0;this.scene.add(b);return b},clearAllBoneMesh:function(){if(this.isWithMesh){var a,b;for(a=this.meshChains.length;a--;){for(b=this.meshChains[a].length;b--;){var c=this.meshChains[a][b];this.scene.remove(c);c.geometry.dispose();c.material.dispose()}this.meshChains[a]=[]}this.meshChains=[]}}});Object.assign(D.prototype,{isIKSolver:!0});Object.assign(E.prototype,{isIKSolver:!0});h._Math=m;h.V2=l;h.V3=f;h.M3=y;h.Q=u;h.Joint3D=v;h.Bone3D=r;h.Chain3D=
|
||||
z;h.Structure3D=B;h.Joint2D=w;h.Bone2D=x;h.Chain2D=A;h.Structure2D=C;h.IKSolver=D;h.HISolver=E;h.REVISION="1.3.3";h.PRECISION=.001;h.PRECISION_DEG=.01;h.MAX_VALUE=Infinity;h.PI=q;h.TORAD=n;h.TODEG=G;h.NONE=1;h.GLOBAL_ROTOR=2;h.GLOBAL_HINGE=3;h.LOCAL_ROTOR=4;h.LOCAL_HINGE=5;h.GLOBAL_ABSOLUTE=6;h.LOCAL_RELATIVE=7;h.LOCAL_ABSOLUTE=8;h.J_BALL=10;h.J_LOCAL=11;h.J_GLOBAL=12;h.START=20;h.END=21;h.X_AXE=H;h.Y_AXE=I;h.Z_AXE=J;h.X_NEG=K;h.Y_NEG=L;h.Z_NEG=M;h.UP=F;h.DOWN=N;h.LEFT=O;h.RIGHT=P;Object.defineProperty(h,
|
||||
"__esModule",{value:!0})});
|
||||
|
Loading…
x
Reference in New Issue
Block a user