parent
56065d0d70
commit
c630ac2e59
@ -0,0 +1,24 @@ |
||||
package com.jme3.anim.util; |
||||
|
||||
import com.jme3.animation.AnimControl; |
||||
import com.jme3.scene.SceneGraphVisitor; |
||||
import com.jme3.scene.Spatial; |
||||
|
||||
public class AnimMigrationUtils { |
||||
|
||||
public static Spatial migrate(Spatial source) { |
||||
//source.depthFirstTraversal();
|
||||
return source; |
||||
} |
||||
|
||||
private class AnimControlVisitor implements SceneGraphVisitor { |
||||
|
||||
@Override |
||||
public void visit(Spatial spatial) { |
||||
AnimControl control = spatial.getControl(AnimControl.class); |
||||
if (control != null) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,199 +0,0 @@ |
||||
package com.jme3.scene.debug.custom; |
||||
|
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
import com.jme3.anim.Armature; |
||||
import com.jme3.anim.Joint; |
||||
import com.jme3.bounding.*; |
||||
import com.jme3.math.Quaternion; |
||||
import com.jme3.math.Vector3f; |
||||
import com.jme3.scene.*; |
||||
import com.jme3.scene.shape.Sphere; |
||||
|
||||
import java.nio.FloatBuffer; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static com.jme3.util.BufferUtils.createFloatBuffer; |
||||
|
||||
/** |
||||
* The class that displays either wires between the bones' heads if no length |
||||
* data is supplied and full bones' shapes otherwise. |
||||
*/ |
||||
public class ArmatureBone extends Node { |
||||
|
||||
/** |
||||
* The armature to be displayed. |
||||
*/ |
||||
private Armature armature; |
||||
/** |
||||
* The map between the bone index and its length. |
||||
*/ |
||||
private Map<Joint, Node> jointNode = new HashMap<>(); |
||||
private Map<Node, Joint> nodeJoint = new HashMap<>(); |
||||
private Node selectedNode = null; |
||||
private boolean guessJointsOrientation = false; |
||||
|
||||
/** |
||||
* Creates a wire with bone lengths data. If the data is supplied then the |
||||
* wires will show each full bone (from head to tail). |
||||
* |
||||
* @param armature the armature that will be shown |
||||
* @param boneLengths a map between the bone's index and the bone's length |
||||
*/ |
||||
public ArmatureBone(Armature armature, Map<Integer, Float> boneLengths, boolean guessJointsOrientation) { |
||||
this.armature = armature; |
||||
this.guessJointsOrientation = guessJointsOrientation; |
||||
|
||||
BoneShape boneShape = new BoneShape(); |
||||
Sphere jointShape = new Sphere(16, 16, 0.05f); |
||||
jointShape.setBuffer(VertexBuffer.Type.Color, 4, createFloatBuffer(jointShape.getVertexCount() * 4)); |
||||
FloatBuffer cb = jointShape.getFloatBuffer(VertexBuffer.Type.Color); |
||||
|
||||
cb.rewind(); |
||||
for (int i = 0; i < jointShape.getVertexCount(); i++) { |
||||
cb.put(0.05f).put(0.05f).put(0.05f).put(1f); |
||||
} |
||||
|
||||
for (Joint joint : armature.getRoots()) { |
||||
createSkeletonGeoms(joint, boneShape, jointShape, boneLengths, armature, this, guessJointsOrientation); |
||||
} |
||||
this.updateModelBound(); |
||||
|
||||
|
||||
Sphere originShape = new Sphere(16, 16, 0.02f); |
||||
originShape.setBuffer(VertexBuffer.Type.Color, 4, createFloatBuffer(originShape.getVertexCount() * 4)); |
||||
cb = originShape.getFloatBuffer(VertexBuffer.Type.Color); |
||||
cb.rewind(); |
||||
for (int i = 0; i < jointShape.getVertexCount(); i++) { |
||||
cb.put(0.4f).put(0.4f).put(0.05f).put(1f); |
||||
} |
||||
|
||||
Geometry origin = new Geometry("origin", originShape); |
||||
BoundingVolume bv = this.getWorldBound(); |
||||
float scale = 1; |
||||
if (bv.getType() == BoundingVolume.Type.AABB) { |
||||
BoundingBox bb = (BoundingBox) bv; |
||||
scale = (bb.getXExtent() + bb.getYExtent() + bb.getZExtent()) / 3f; |
||||
} else if (bv.getType() == BoundingVolume.Type.Sphere) { |
||||
BoundingSphere bs = (BoundingSphere) bv; |
||||
scale = bs.getRadius(); |
||||
} |
||||
origin.scale(scale); |
||||
attachChild(origin); |
||||
} |
||||
|
||||
protected final void createSkeletonGeoms(Joint joint, Mesh boneShape, Mesh jointShape, Map<Integer, Float> boneLengths, Armature armature, Node parent, boolean guessBonesOrientation) { |
||||
|
||||
Node n = new Node(joint.getName() + "Node"); |
||||
Geometry bGeom = new Geometry(joint.getName() + "Bone", boneShape); |
||||
Geometry jGeom = new Geometry(joint.getName() + "Joint", jointShape); |
||||
n.setLocalTransform(joint.getLocalTransform()); |
||||
|
||||
float boneLength = boneLengths.get(armature.getJointIndex(joint)); |
||||
|
||||
if (guessBonesOrientation) { |
||||
//One child only, the bone direction is from the parent joint to the child joint.
|
||||
if (joint.getChildren().size() == 1) { |
||||
Vector3f v = joint.getChildren().get(0).getLocalTranslation(); |
||||
Quaternion q = new Quaternion(); |
||||
q.lookAt(v, Vector3f.UNIT_Z); |
||||
bGeom.setLocalRotation(q); |
||||
} |
||||
//no child, the bone has the same direction as the parent bone.
|
||||
if (joint.getChildren().isEmpty()) { |
||||
//no parent, let's use the bind orientation of the bone
|
||||
Spatial s = parent.getChild(0); |
||||
if (s != null) { |
||||
bGeom.setLocalRotation(s.getLocalRotation()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
float boneScale = boneLength * 0.8f; |
||||
float scale = boneScale / 8f; |
||||
bGeom.setLocalScale(new Vector3f(scale, scale, boneScale)); |
||||
Vector3f offset = new Vector3f(0, 0, boneLength * 0.1f); |
||||
bGeom.getLocalRotation().multLocal(offset); |
||||
bGeom.setLocalTranslation(offset); |
||||
jGeom.setLocalScale(boneLength); |
||||
|
||||
if (joint.getChildren().size() <= 1) { |
||||
n.attachChild(bGeom); |
||||
} |
||||
n.attachChild(jGeom); |
||||
|
||||
jointNode.put(joint, n); |
||||
nodeJoint.put(n, joint); |
||||
parent.attachChild(n); |
||||
for (Joint child : joint.getChildren()) { |
||||
createSkeletonGeoms(child, boneShape, jointShape, boneLengths, armature, n, guessBonesOrientation); |
||||
} |
||||
} |
||||
|
||||
protected Joint select(Geometry g) { |
||||
Node parentNode = g.getParent(); |
||||
|
||||
if (parent != null) { |
||||
Joint j = nodeJoint.get(parentNode); |
||||
if (j != null) { |
||||
selectedNode = parentNode; |
||||
} |
||||
return j; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected Node getSelectedNode() { |
||||
return selectedNode; |
||||
} |
||||
|
||||
|
||||
protected final void updateSkeletonGeoms(Joint joint) { |
||||
Node n = jointNode.get(joint); |
||||
n.setLocalTransform(joint.getLocalTransform()); |
||||
|
||||
for (Joint child : joint.getChildren()) { |
||||
updateSkeletonGeoms(child); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* The method updates the geometry according to the positions of the bones. |
||||
*/ |
||||
public void updateGeometry() { |
||||
for (Joint joint : armature.getRoots()) { |
||||
updateSkeletonGeoms(joint); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,245 @@ |
||||
package com.jme3.scene.debug.custom; |
||||
|
||||
/* |
||||
* Copyright (c) 2009-2012 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
import com.jme3.anim.Armature; |
||||
import com.jme3.anim.Joint; |
||||
import com.jme3.collision.*; |
||||
import com.jme3.math.*; |
||||
import com.jme3.renderer.queue.RenderQueue; |
||||
import com.jme3.scene.*; |
||||
import com.jme3.scene.shape.Line; |
||||
|
||||
import java.nio.FloatBuffer; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* The class that displays either wires between the bones' heads if no length |
||||
* data is supplied and full bones' shapes otherwise. |
||||
*/ |
||||
public class ArmatureNode extends Node { |
||||
|
||||
/** |
||||
* The armature to be displayed. |
||||
*/ |
||||
private Armature armature; |
||||
/** |
||||
* The map between the bone index and its length. |
||||
*/ |
||||
private Map<Joint, Geometry[]> jointToGeoms = new HashMap<>(); |
||||
private Map<Geometry, Joint> geomToJoint = new HashMap<>(); |
||||
private Joint selectedJoint = null; |
||||
private Vector3f tmpStart = new Vector3f(); |
||||
private Vector3f tmpEnd = new Vector3f(); |
||||
ColorRGBA selectedColor = ColorRGBA.Orange; |
||||
ColorRGBA selectedColorJ = ColorRGBA.Yellow; |
||||
;//new ColorRGBA(0.2f, 1f, 1.0f, 1.0f);
|
||||
ColorRGBA baseColor = new ColorRGBA(0.05f, 0.05f, 0.05f, 1f); |
||||
|
||||
|
||||
/** |
||||
* Creates a wire with bone lengths data. If the data is supplied then the |
||||
* wires will show each full bone (from head to tail). |
||||
* |
||||
* @param armature the armature that will be shown |
||||
*/ |
||||
public ArmatureNode(Armature armature, Node joints, Node wires, Node outlines) { |
||||
this.armature = armature; |
||||
|
||||
for (Joint joint : armature.getRoots()) { |
||||
createSkeletonGeoms(joint, joints, wires, outlines); |
||||
} |
||||
this.updateModelBound(); |
||||
|
||||
} |
||||
|
||||
protected final void createSkeletonGeoms(Joint joint, Node joints, Node wires, Node outlines) { |
||||
Vector3f start = joint.getModelTransform().getTranslation().clone(); |
||||
Vector3f end = null; |
||||
|
||||
//One child only, the bone direction is from the parent joint to the child joint.
|
||||
if (joint.getChildren().size() == 1) { |
||||
end = joint.getChildren().get(0).getModelTransform().getTranslation().clone(); |
||||
} |
||||
|
||||
Geometry jGeom = new Geometry(joint.getName() + "Joint", new JointShape()); |
||||
jGeom.setLocalTranslation(start); |
||||
joints.attachChild(jGeom); |
||||
Geometry bGeom = null; |
||||
Geometry bGeomO = null; |
||||
if (end != null) { |
||||
bGeom = new Geometry(joint.getName() + "Bone", new Line(start, end)); |
||||
setColor(bGeom, baseColor); |
||||
geomToJoint.put(bGeom, joint); |
||||
bGeomO = new Geometry(joint.getName() + "BoneOutline", new Line(start, end)); |
||||
setColor(bGeomO, ColorRGBA.White); |
||||
bGeom.setUserData("start", wires.getWorldTransform().transformVector(start, start)); |
||||
bGeom.setUserData("end", wires.getWorldTransform().transformVector(end, end)); |
||||
bGeom.setQueueBucket(RenderQueue.Bucket.Transparent); |
||||
wires.attachChild(bGeom); |
||||
outlines.attachChild(bGeomO); |
||||
} |
||||
|
||||
jointToGeoms.put(joint, new Geometry[]{jGeom, bGeom, bGeomO}); |
||||
|
||||
for (Joint child : joint.getChildren()) { |
||||
createSkeletonGeoms(child, joints, wires, outlines); |
||||
} |
||||
} |
||||
|
||||
protected Joint select(Geometry g) { |
||||
if (g == null) { |
||||
resetSelection(); |
||||
return null; |
||||
} |
||||
Joint j = geomToJoint.get(g); |
||||
if (j != null) { |
||||
if (selectedJoint == j) { |
||||
return null; |
||||
} |
||||
resetSelection(); |
||||
selectedJoint = j; |
||||
Geometry[] geomArray = jointToGeoms.get(selectedJoint); |
||||
setColor(geomArray[0], selectedColorJ); |
||||
setColor(geomArray[1], selectedColor); |
||||
setColor(geomArray[2], baseColor); |
||||
return j; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
private void resetSelection() { |
||||
if (selectedJoint == null) { |
||||
return; |
||||
} |
||||
Geometry[] geoms = jointToGeoms.get(selectedJoint); |
||||
setColor(geoms[0], ColorRGBA.White); |
||||
setColor(geoms[1], baseColor); |
||||
setColor(geoms[2], ColorRGBA.White); |
||||
selectedJoint = null; |
||||
} |
||||
|
||||
protected Joint getSelectedJoint() { |
||||
return selectedJoint; |
||||
} |
||||
|
||||
|
||||
protected final void updateSkeletonGeoms(Joint joint) { |
||||
Geometry[] geoms = jointToGeoms.get(joint); |
||||
if (geoms != null) { |
||||
Geometry jGeom = geoms[0]; |
||||
jGeom.setLocalTranslation(joint.getModelTransform().getTranslation()); |
||||
Geometry bGeom = geoms[1]; |
||||
if (bGeom != null) { |
||||
tmpStart.set(joint.getModelTransform().getTranslation()); |
||||
boolean hasEnd = false; |
||||
if (joint.getChildren().size() == 1) { |
||||
tmpEnd.set(joint.getChildren().get(0).getModelTransform().getTranslation()); |
||||
hasEnd = true; |
||||
} |
||||
if (hasEnd) { |
||||
updateBoneMesh(bGeom); |
||||
Geometry bGeomO = geoms[2]; |
||||
updateBoneMesh(bGeomO); |
||||
Vector3f start = bGeom.getUserData("start"); |
||||
Vector3f end = bGeom.getUserData("end"); |
||||
bGeom.setUserData("start", bGeom.getParent().getWorldTransform().transformVector(tmpStart, start)); |
||||
bGeom.setUserData("end", bGeom.getParent().getWorldTransform().transformVector(tmpEnd, end)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
for (Joint child : joint.getChildren()) { |
||||
updateSkeletonGeoms(child); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int collideWith(Collidable other, CollisionResults results) { |
||||
if (!(other instanceof Ray)) { |
||||
return 0; |
||||
} |
||||
int nbCol = 0; |
||||
for (Geometry g : geomToJoint.keySet()) { |
||||
float len = MathUtils.raySegmentShortestDistance((Ray) other, (Vector3f) g.getUserData("start"), (Vector3f) g.getUserData("end")); |
||||
if (len > 0 && len < 0.1f) { |
||||
CollisionResult res = new CollisionResult(); |
||||
res.setGeometry(g); |
||||
results.addCollision(res); |
||||
nbCol++; |
||||
} |
||||
} |
||||
return nbCol; |
||||
} |
||||
|
||||
private void updateBoneMesh(Geometry bGeom) { |
||||
VertexBuffer pos = bGeom.getMesh().getBuffer(VertexBuffer.Type.Position); |
||||
FloatBuffer fb = (FloatBuffer) pos.getData(); |
||||
fb.rewind(); |
||||
fb.put(new float[]{tmpStart.x, tmpStart.y, tmpStart.z, |
||||
tmpEnd.x, tmpEnd.y, tmpEnd.z,}); |
||||
pos.updateData(fb); |
||||
|
||||
bGeom.updateModelBound(); |
||||
} |
||||
|
||||
private void setColor(Geometry g, ColorRGBA color) { |
||||
float[] colors = new float[g.getMesh().getVertexCount() * 4]; |
||||
for (int i = 0; i < g.getMesh().getVertexCount() * 4; i += 4) { |
||||
colors[i] = color.r; |
||||
colors[i + 1] = color.g; |
||||
colors[i + 2] = color.b; |
||||
colors[i + 3] = color.a; |
||||
} |
||||
VertexBuffer colorBuff = g.getMesh().getBuffer(VertexBuffer.Type.Color); |
||||
if (colorBuff == null) { |
||||
g.getMesh().setBuffer(VertexBuffer.Type.Color, 4, colors); |
||||
} else { |
||||
FloatBuffer cBuff = (FloatBuffer) colorBuff.getData(); |
||||
cBuff.rewind(); |
||||
cBuff.put(colors); |
||||
colorBuff.updateData(cBuff); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* The method updates the geometry according to the positions of the bones. |
||||
*/ |
||||
public void updateGeometry() { |
||||
armature.update(); |
||||
for (Joint joint : armature.getRoots()) { |
||||
updateSkeletonGeoms(joint); |
||||
} |
||||
} |
||||
} |
@ -1,171 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 2009-2018 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
// $Id: Cylinder.java 4131 2009-03-19 20:15:28Z blaine.dev $
|
||||
package com.jme3.scene.debug.custom; |
||||
|
||||
import com.jme3.math.*; |
||||
import com.jme3.scene.VertexBuffer.Type; |
||||
import com.jme3.scene.shape.AbstractBox; |
||||
import com.jme3.util.BufferUtils; |
||||
|
||||
import java.nio.FloatBuffer; |
||||
|
||||
/** |
||||
* A simple cylinder, defined by its height and radius. |
||||
* (Ported to jME3) |
||||
* |
||||
* @author Mark Powell |
||||
* @version $Revision: 4131 $, $Date: 2009-03-19 16:15:28 -0400 (Thu, 19 Mar 2009) $ |
||||
*/ |
||||
public class BoneShape extends AbstractBox { |
||||
|
||||
private static Vector3f topN = new Vector3f(0, 1, 0); |
||||
private static Vector3f botN = new Vector3f(0, -1, 0); |
||||
private static Vector3f rigN = new Vector3f(1, 0, 0); |
||||
private static Vector3f lefN = new Vector3f(-1, 0, 0); |
||||
|
||||
static { |
||||
Quaternion q = new Quaternion().fromAngleAxis(-FastMath.PI / 16f, Vector3f.UNIT_X); |
||||
q.multLocal(topN); |
||||
q.inverseLocal(); |
||||
q.multLocal(botN); |
||||
q = new Quaternion().fromAngleAxis(FastMath.PI / 16f, Vector3f.UNIT_Y); |
||||
q.multLocal(rigN); |
||||
q.inverseLocal(); |
||||
q.multLocal(lefN); |
||||
} |
||||
|
||||
private static final short[] GEOMETRY_INDICES_DATA = { |
||||
2, 1, 0, 3, 2, 0, // back
|
||||
6, 5, 4, 7, 6, 4, // right
|
||||
10, 9, 8, 11, 10, 8, // front
|
||||
14, 13, 12, 15, 14, 12, // left
|
||||
18, 17, 16, 19, 18, 16, // top
|
||||
22, 21, 20, 23, 22, 20 // bottom
|
||||
}; |
||||
|
||||
private static final float[] GEOMETRY_NORMALS_DATA = { |
||||
0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, // back
|
||||
rigN.x, rigN.y, rigN.z, rigN.x, rigN.y, rigN.z, rigN.x, rigN.y, rigN.z, rigN.x, rigN.y, rigN.z, // right
|
||||
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front
|
||||
lefN.x, lefN.y, lefN.z, lefN.x, lefN.y, lefN.z, lefN.x, lefN.y, lefN.z, lefN.x, lefN.y, lefN.z, // left
|
||||
topN.x, topN.y, topN.z, topN.x, topN.y, topN.z, topN.x, topN.y, topN.z, topN.x, topN.y, topN.z, // top
|
||||
botN.x, botN.y, botN.z, botN.x, botN.y, botN.z, botN.x, botN.y, botN.z, botN.x, botN.y, botN.z // bottom
|
||||
}; |
||||
|
||||
private static final float[] GEOMETRY_TEXTURE_DATA = { |
||||
1, 0, 0, 0, 0, 1, 1, 1, // back
|
||||
1, 0, 0, 0, 0, 1, 1, 1, // right
|
||||
1, 0, 0, 0, 0, 1, 1, 1, // front
|
||||
1, 0, 0, 0, 0, 1, 1, 1, // left
|
||||
1, 0, 0, 0, 0, 1, 1, 1, // top
|
||||
1, 0, 0, 0, 0, 1, 1, 1 // bottom
|
||||
}; |
||||
|
||||
private static final float[] GEOMETRY_POSITION_DATA = { |
||||
-0.5f, -0.5f, 0, 0.5f, -0.5f, 0, 0.5f, 0.5f, 0, -0.5f, 0.5f, 0, //back
|
||||
0.5f, -0.5f, 0, 0.25f, -0.25f, 1, 0.25f, 0.25f, 1, 0.5f, 0.5f, 0, //right
|
||||
0.25f, -0.25f, 1, -0.25f, -0.25f, 1, -0.25f, 0.25f, 1, 0.25f, 0.25f, 1, //front
|
||||
-0.25f, -0.25f, 1, -0.5f, -0.5f, 0, -0.5f, 0.5f, 0, -0.25f, 0.25f, 1, //left
|
||||
0.5f, 0.5f, 0, 0.25f, 0.25f, 1, -0.25f, 0.25f, 1, -0.5f, 0.5f, 0, // top
|
||||
-0.5f, -0.5f, 0, -0.25f, -0.25f, 1, 0.25f, -0.25f, 1, 0.5f, -0.5f, 0 // bottom
|
||||
}; |
||||
|
||||
//0,1,2,3
|
||||
//1,4,6,2
|
||||
//4,5,7,6
|
||||
//5,0,3,7,
|
||||
//2,6,7,3
|
||||
//0,5,4,1
|
||||
|
||||
|
||||
// v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back
|
||||
// v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right
|
||||
// v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front
|
||||
// v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left
|
||||
// v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top
|
||||
// v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z // bottom
|
||||
|
||||
/** |
||||
* Creates a new box. |
||||
* <p> |
||||
* The box has a center of 0,0,0 and extends in the out from the center by |
||||
* the given amount in <em>each</em> direction. So, for example, a box |
||||
* with extent of 0.5 would be the unit cube. |
||||
* |
||||
* @param x the size of the box along the x axis, in both directions. |
||||
* @param y the size of the box along the y axis, in both directions. |
||||
* @param z the size of the box along the z axis, in both directions. |
||||
*/ |
||||
public BoneShape() { |
||||
super(); |
||||
updateGeometry(); |
||||
} |
||||
|
||||
/** |
||||
* Creates a clone of this box. |
||||
* <p> |
||||
* The cloned box will have '_clone' appended to it's name, but all other |
||||
* properties will be the same as this box. |
||||
*/ |
||||
@Override |
||||
public BoneShape clone() { |
||||
return new BoneShape(); |
||||
} |
||||
|
||||
protected void doUpdateGeometryIndices() { |
||||
if (getBuffer(Type.Index) == null) { |
||||
setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA)); |
||||
} |
||||
} |
||||
|
||||
protected void doUpdateGeometryNormals() { |
||||
if (getBuffer(Type.Normal) == null) { |
||||
setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA)); |
||||
} |
||||
} |
||||
|
||||
protected void doUpdateGeometryTextures() { |
||||
if (getBuffer(Type.TexCoord) == null) { |
||||
setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA)); |
||||
} |
||||
} |
||||
|
||||
protected void doUpdateGeometryVertices() { |
||||
FloatBuffer fpb = BufferUtils.createVector3Buffer(24); |
||||
fpb.put(GEOMETRY_POSITION_DATA); |
||||
setBuffer(Type.Position, 3, fpb); |
||||
updateBound(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,79 @@ |
||||
/* |
||||
* Copyright (c) 2009-2010 jMonkeyEngine |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* |
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
package com.jme3.scene.debug.custom; |
||||
|
||||
import com.jme3.scene.Mesh; |
||||
import com.jme3.scene.VertexBuffer.Type; |
||||
|
||||
|
||||
public class JointShape extends Mesh { |
||||
|
||||
|
||||
/** |
||||
* Serialization only. Do not use. |
||||
*/ |
||||
public JointShape() { |
||||
float width = 1; |
||||
float height = 1; |
||||
setBuffer(Type.Position, 3, new float[]{-width * 0.5f, -width * 0.5f, 0, |
||||
width * 0.5f, -width * 0.5f, 0, |
||||
width * 0.5f, height * 0.5f, 0, |
||||
-width * 0.5f, height * 0.5f, 0 |
||||
}); |
||||
|
||||
|
||||
setBuffer(Type.TexCoord, 2, new float[]{0, 0, |
||||
1, 0, |
||||
1, 1, |
||||
0, 1}); |
||||
|
||||
setBuffer(Type.Normal, 3, new float[]{0, 0, 1, |
||||
0, 0, 1, |
||||
0, 0, 1, |
||||
0, 0, 1}); |
||||
|
||||
setBuffer(Type.Color, 4, new float[]{1, 1, 1, 1, |
||||
1, 1, 1, 1, |
||||
1, 1, 1, 1, |
||||
1, 1, 1, 1}); |
||||
|
||||
setBuffer(Type.Index, 3, new short[]{0, 1, 2, |
||||
0, 2, 3}); |
||||
|
||||
|
||||
updateBound(); |
||||
setStatic(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,78 @@ |
||||
MaterialDef Billboard { |
||||
MaterialParameters { |
||||
Float SpriteHeight : 10 |
||||
Texture2D Texture |
||||
} |
||||
|
||||
Technique { |
||||
WorldParameters { |
||||
WorldViewMatrix |
||||
ProjectionMatrix |
||||
WorldMatrix |
||||
CameraDirection |
||||
ViewPort |
||||
CameraPosition |
||||
} |
||||
|
||||
VertexShaderNodes { |
||||
ShaderNode TexCoord { |
||||
Definition: AttributeToVarying: Common/MatDefs/ShaderNodes/Basic/AttributeToVarying.j3sn |
||||
InputMappings { |
||||
vec2Variable = Attr.inTexCoord |
||||
vec4Variable = Attr.inColor |
||||
} |
||||
OutputMappings { |
||||
} |
||||
} |
||||
ShaderNode FixedScale { |
||||
Definition: FixedScale: Common/MatDefs/ShaderNodes/Common/FixedScale.j3sn |
||||
InputMappings { |
||||
projectionMatrix = WorldParam.ProjectionMatrix |
||||
worldMatrix = WorldParam.WorldMatrix |
||||
cameraDir = WorldParam.CameraDirection |
||||
viewport = WorldParam.ViewPort |
||||
modelPosition = Attr.inPosition |
||||
cameraPos = WorldParam.CameraPosition |
||||
spriteHeight = MatParam.SpriteHeight |
||||
} |
||||
OutputMappings { |
||||
} |
||||
} |
||||
ShaderNode Billboard { |
||||
Definition: Billboard: Common/MatDefs/ShaderNodes/Common/Billboard.j3sn |
||||
InputMappings { |
||||
worldViewMatrix = WorldParam.WorldViewMatrix |
||||
projectionMatrix = WorldParam.ProjectionMatrix |
||||
modelPosition = Attr.inPosition |
||||
scale = FixedScale.scale |
||||
} |
||||
OutputMappings { |
||||
Global.position = projPosition |
||||
} |
||||
} |
||||
} |
||||
|
||||
FragmentShaderNodes { |
||||
ShaderNode TextureFetch { |
||||
Definition: TextureFetch: Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn |
||||
InputMappings { |
||||
textureMap = MatParam.Texture |
||||
texCoord = TexCoord.vec2Variable |
||||
} |
||||
OutputMappings { |
||||
} |
||||
} |
||||
ShaderNode ColorMult { |
||||
Definition: ColorMult: Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn |
||||
InputMappings { |
||||
color1 = TextureFetch.outColor |
||||
color2 = TexCoord.vec4Variable |
||||
} |
||||
OutputMappings { |
||||
Global.color = outColor |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
ShaderNodeDefinitions{ |
||||
ShaderNodeDefinition Billboard { |
||||
//Vertex/Fragment |
||||
Type: Vertex |
||||
|
||||
//Shader GLSL<version>: <Path to shader> |
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Common/Billboard100.frag |
||||
|
||||
Documentation{ |
||||
//type documentation here. This is optional but recommended |
||||
|
||||
//@input <glsltype> <varName> <description> |
||||
@input mat4 worldViewMatrix The worldView matrix |
||||
@input mat4 projectionMatrix The projection matrix |
||||
@input vec3 modelPosition the vertex position |
||||
@input float scale the scale of the billboard (defautl 1) |
||||
|
||||
//@output <glslType> <varName> <description> |
||||
@output vec4 projPosition The position in projection space |
||||
} |
||||
Input { |
||||
//all the node inputs |
||||
//<glslType> <varName> |
||||
mat4 worldViewMatrix |
||||
mat4 projectionMatrix |
||||
vec3 modelPosition |
||||
float scale 1 |
||||
} |
||||
Output { |
||||
//all the node outputs |
||||
//<glslType> <varName> |
||||
vec4 projPosition |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
void main(){ |
||||
// First colunm. |
||||
worldViewMatrix[0][0] = scale; |
||||
worldViewMatrix[0][1] = 0.0; |
||||
worldViewMatrix[0][2] = 0.0; |
||||
|
||||
// Second colunm. |
||||
worldViewMatrix[1][0] = 0.0; |
||||
worldViewMatrix[1][1] = scale; |
||||
worldViewMatrix[1][2] = 0.0; |
||||
|
||||
// Thrid colunm. |
||||
worldViewMatrix[2][0] = 0.0; |
||||
worldViewMatrix[2][1] = 0.0; |
||||
worldViewMatrix[2][2] = scale; |
||||
|
||||
vec4 position = worldViewMatrix * vec4(modelPosition,1.0); |
||||
projPosition = projectionMatrix * position; |
||||
} |
@ -0,0 +1,41 @@ |
||||
ShaderNodeDefinitions{ |
||||
ShaderNodeDefinition FixedScale { |
||||
//Vertex/Fragment |
||||
Type: Vertex |
||||
|
||||
//Shader GLSL<version>: <Path to shader> |
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Common/FixedScale100.frag |
||||
|
||||
Documentation{ |
||||
//type documentation here. This is optional but recommended |
||||
|
||||
//@input <glsltype> <varName> <description> |
||||
@input vec4 viewport The viewport information (right, top, left, bottom) |
||||
@input vec3 cameraDir The direction of the camera |
||||
@input vec3 cameraPos The position of the camera |
||||
@input mat4 worldMatrix The world matrix |
||||
@input mat4 projectionMatrix The projection matrix |
||||
@input vec3 modelPosition the vertex position |
||||
@input float spriteHeight the desired image height in pixel |
||||
|
||||
//@output <glslType> <varName> <description> |
||||
@output float scale The constant scale |
||||
} |
||||
Input { |
||||
//all the node inputs |
||||
//<glslType> <varName> |
||||
vec4 viewport |
||||
vec3 cameraDir |
||||
vec3 cameraPos |
||||
mat4 worldMatrix |
||||
mat4 projectionMatrix |
||||
vec3 modelPosition |
||||
float spriteHeight 10.0 |
||||
} |
||||
Output { |
||||
//all the node outputs |
||||
//<glslType> <varName> |
||||
float scale |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,8 @@ |
||||
void main(){ |
||||
vec4 worldPos = worldMatrix * vec4(modelPosition, 1.0); |
||||
vec3 dir = worldPos.xyz - cameraPos; |
||||
float distance = dot(cameraDir, dir); |
||||
float m11 = projectionMatrix[1][1]; |
||||
float halfHeight = (viewport.w - viewport.y) * 0.5; |
||||
scale = ((distance/halfHeight) * spriteHeight)/m11; |
||||
} |
@ -0,0 +1,57 @@ |
||||
ShaderNodeDefinitions{ |
||||
ShaderNodeDefinition TexCoord { |
||||
//Vertex/Fragment |
||||
Type: Vertex |
||||
|
||||
//Shader GLSL<version>: <Path to shader> |
||||
Shader GLSL100: Common/MatDefs/ShaderNodes/Common/texCoord100.frag |
||||
|
||||
Documentation{ |
||||
//type documentation here. This is optional but recommended |
||||
|
||||
//@input <glsltype> <varName> <description> |
||||
@input vec2 texCoord The input texture Coord |
||||
@input vec2 texCoord2 The input texture Coord |
||||
@input vec2 texCoord3 The input texture Coord |
||||
@input vec2 texCoord4 The input texture Coord |
||||
@input vec2 texCoord5 The input texture Coord |
||||
@input vec2 texCoord6 The input texture Coord |
||||
@input vec2 texCoord7 The input texture Coord |
||||
@input vec2 texCoord8 The input texture Coord |
||||
|
||||
//@output <glslType> <varName> <description> |
||||
@output vec2 texCoord The input texture Coord |
||||
@output vec2 texCoord2 The input texture Coord |
||||
@output vec2 texCoord3 The input texture Coord |
||||
@output vec2 texCoord4 The input texture Coord |
||||
@output vec2 texCoord5 The input texture Coord |
||||
@output vec2 texCoord6 The input texture Coord |
||||
@output vec2 texCoord7 The input texture Coord |
||||
@output vec2 texCoord8 The input texture Coord |
||||
} |
||||
Input { |
||||
//all the node inputs |
||||
//<glslType> <varName> |
||||
vec2 texCoord |
||||
vec2 texCoord2 |
||||
vec2 texCoord3 |
||||
vec2 texCoord4 |
||||
vec2 texCoord5 |
||||
vec2 texCoord6 |
||||
vec2 texCoord7 |
||||
vec2 texCoord8 |
||||
} |
||||
Output { |
||||
//all the node outputs |
||||
//<glslType> <varName> |
||||
vec2 texCoord |
||||
vec2 texCoord2 |
||||
vec2 texCoord3 |
||||
vec2 texCoord4 |
||||
vec2 texCoord5 |
||||
vec2 texCoord6 |
||||
vec2 texCoord7 |
||||
vec2 texCoord8 |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,2 @@ |
||||
void main(){ |
||||
} |
After Width: | Height: | Size: 367 B |
Loading…
Reference in new issue