|
|
@ -32,13 +32,17 @@ |
|
|
|
|
|
|
|
|
|
|
|
package jme3test.model.anim; |
|
|
|
package jme3test.model.anim; |
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.animation.Bone; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import com.jme3.animation.Skeleton; |
|
|
|
import java.nio.FloatBuffer; |
|
|
|
import com.jme3.animation.SkeletonControl; |
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.anim.Armature; |
|
|
|
|
|
|
|
import com.jme3.anim.Joint; |
|
|
|
|
|
|
|
import com.jme3.anim.SkinningControl; |
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
import com.jme3.app.SimpleApplication; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.AmbientLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.light.DirectionalLight; |
|
|
|
import com.jme3.math.Quaternion; |
|
|
|
import com.jme3.math.Quaternion; |
|
|
|
|
|
|
|
import com.jme3.math.Transform; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Node; |
|
|
|
import com.jme3.scene.Node; |
|
|
@ -47,13 +51,11 @@ import com.jme3.scene.VertexBuffer.Format; |
|
|
|
import com.jme3.scene.VertexBuffer.Type; |
|
|
|
import com.jme3.scene.VertexBuffer.Type; |
|
|
|
import com.jme3.scene.VertexBuffer.Usage; |
|
|
|
import com.jme3.scene.VertexBuffer.Usage; |
|
|
|
import com.jme3.scene.shape.Box; |
|
|
|
import com.jme3.scene.shape.Box; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
|
|
|
|
import java.nio.FloatBuffer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TestCustomAnim extends SimpleApplication { |
|
|
|
public class TestCustomAnim extends SimpleApplication { |
|
|
|
|
|
|
|
|
|
|
|
private Bone bone; |
|
|
|
private Joint bone; |
|
|
|
private Skeleton skeleton; |
|
|
|
private Armature armature; |
|
|
|
private Quaternion rotation = new Quaternion(); |
|
|
|
private Quaternion rotation = new Quaternion(); |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
@ -96,10 +98,9 @@ public class TestCustomAnim extends SimpleApplication { |
|
|
|
box.generateBindPose(); |
|
|
|
box.generateBindPose(); |
|
|
|
|
|
|
|
|
|
|
|
// Create skeleton
|
|
|
|
// Create skeleton
|
|
|
|
bone = new Bone("root"); |
|
|
|
bone = new Joint("root"); |
|
|
|
bone.setBindTransforms(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ); |
|
|
|
bone.setLocalTransform(new Transform(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ)); |
|
|
|
bone.setUserControl(true); |
|
|
|
armature = new Armature(new Joint[] { bone }); |
|
|
|
skeleton = new Skeleton(new Bone[]{ bone }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assign all verticies to bone 0 with weight 1
|
|
|
|
// Assign all verticies to bone 0 with weight 1
|
|
|
|
for (int i = 0; i < box.getVertexCount() * 4; i += 4) { |
|
|
|
for (int i = 0; i < box.getVertexCount() * 4; i += 4) { |
|
|
@ -126,8 +127,8 @@ public class TestCustomAnim extends SimpleApplication { |
|
|
|
model.attachChild(geom); |
|
|
|
model.attachChild(geom); |
|
|
|
|
|
|
|
|
|
|
|
// Create skeleton control
|
|
|
|
// Create skeleton control
|
|
|
|
SkeletonControl skeletonControl = new SkeletonControl(skeleton); |
|
|
|
SkinningControl skinningControl = new SkinningControl(armature); |
|
|
|
model.addControl(skeletonControl); |
|
|
|
model.addControl(skinningControl); |
|
|
|
|
|
|
|
|
|
|
|
rootNode.attachChild(model); |
|
|
|
rootNode.attachChild(model); |
|
|
|
} |
|
|
|
} |
|
|
@ -142,10 +143,10 @@ public class TestCustomAnim extends SimpleApplication { |
|
|
|
rotation.multLocal(rotate); |
|
|
|
rotation.multLocal(rotate); |
|
|
|
|
|
|
|
|
|
|
|
// Set new rotation into bone
|
|
|
|
// Set new rotation into bone
|
|
|
|
bone.setUserTransforms(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ); |
|
|
|
bone.setLocalTransform(new Transform(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ)); |
|
|
|
|
|
|
|
|
|
|
|
// After changing skeleton transforms, must update world data
|
|
|
|
// After changing skeleton transforms, must update world data
|
|
|
|
skeleton.updateWorldVectors(); |
|
|
|
armature.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|