PMDSkinMesh[] skinTargets;
PMDGeometry[] pmdGeometryArray;
Map<String, Skin> skinMap = new HashMap<String, Skin>();
+ Skin[] skinArray = new Skin[0];
javax.vecmath.Vector3f skinPosArray[];
javax.vecmath.Vector3f skinNormalArray[];
javax.vecmath.Vector3f skinPosArrayOrig[];
offsetMatrices = skeleton.computeSkinningMatrices();
return offsetMatrices;
}
-
+boolean setBoneMatricesFlag = true;
public void update() {
// skeleton.reset(); // reset skeleton to bind pose
if (true /*
skinTargets[0].skinvb2.setUpdateNeeded();
skinTargets[0].skinnb2.setUpdateNeeded();
for(PMDSkinMesh skinMesh : skinTargets) {
- skinMesh.clearBuffer(Type.Position);
- skinMesh.clearBuffer(Type.Normal);
+// skinMesh.clearBuffer(Type.Position);
+// skinMesh.clearBuffer(Type.Normal);
skinMesh.setBuffer(skinTargets[0].getSkinvb2());
skinMesh.setBuffer(skinTargets[0].getSkinnb2());
}
for(int i=skinPosArray.length-1;i>=0;i--) {
skinPosArray[i].set(skinPosArrayOrig[i]);
}
- for (Skin skin : skinMap.values()) {
+ for (Skin skin : skinArray) {
if (true || skin.isUpdateNeeded()) {
if (skin.getWeight() != 0f) {
for (PMDSkinVertData svd : skin.getSkinData().getSkinVertData()) {
VertexBuffer nb = skinMesh.getBuffer(Type.Normal);
FloatBuffer fnb = (FloatBuffer) nb.getData();
- for (Skin skin : skinMap.values()) {
+ for (Skin skin : skinArray) {
if (skin.isUpdateNeeded()) {
if (skin.getWeight() != 1f) {
for (PMDSkinVertData svd : skin.getSkinData().getSkinVertData()) {
for (PMDMesh mesh : targets) {
resetToBind(mesh);
}
- for (Skin skin : skinMap.values()) {
+ for (Skin skin : skinArray) {
skin.setWeight(0f);
}
setUpdateNeeded(true);
skin = skin.clone();
newPMDNode.skinMap.put(skinName, skin);
}
+ newPMDNode.skinArray = newPMDNode.skinMap.values().toArray(new Skin[newPMDNode.skinMap.size()]);
newPMDNode.skinPosArray = new javax.vecmath.Vector3f[skinPosArray.length];
for(int i=0;i<skinPosArray.length;i++) {
newPMDNode.skinPosArray[i] = new javax.vecmath.Vector3f(skinPosArray[i]);
}
axis.normalizeLocal();
// System.out.println("axis = " + axis);
- rot.fromAngleAxis(angle, axis);
+ rot.fromAngleNormalAxis(angle, axis);
// rot.normalize();
if (hizaFlag) {
if (iterationCount == -1) {
Vector3f axis = effectorBonePos.cross(targetBonePos, tmpV5);
axis.normalizeLocal();
Quaternion rot = tmpQ1;
- rot.fromAngleAxis(angle, axis);
+ rot.fromAngleNormalAxis(angle, axis);
// rot.multLocal(ashiBone.getLocalRotation());
// ashiBone.getLocalRotation().set(rot);
ashiBone.getLocalRotation().multLocal(rot);
static final Object lockObject = new Object();
PhysicsSpace physicsSpace;
Map<PMDNode, PMDRigidBody[]> rigidBodyMap = new HashMap<PMDNode, PMDRigidBody[]>();
+ PMDRigidBody[][] nodeRigidBodyArray = new PMDRigidBody[0][];
Map<PMDNode, SixDofJoint[]> constraintMap = new HashMap<PMDNode, SixDofJoint[]>();
float accuracy = 1f / 120;
constArray[i] = constraint;
physicsSpace.add(constraint);
}
+ nodeRigidBodyArray = rigidBodyMap.values().toArray(new PMDRigidBody[rigidBodyMap.size()][]);
// physicsSpace.update(1 / 60f, 1);
}
}
public void updateKinematicPos() {
- for (PMDRigidBody rbarray[] : rigidBodyMap.values()) {
+ for (PMDRigidBody rbarray[] : nodeRigidBodyArray) {
for (int i = 0; i < rbarray.length; i++) {
PMDRigidBody rb = rbarray[i];
PMDNode pmdNode = rb.getPmdNode();
// CollisionObject obj = btWorld.getCollisionObjectArray().getQuick(i);
// if (obj instanceof PMDRigidBody) {
// PMDRigidBody rb = (PMDRigidBody)obj;
- for (PMDRigidBody rbarray[] : rigidBodyMap.values()) {
+ for (PMDRigidBody rbarray[] : nodeRigidBodyArray) {
for (int i = 0; i < rbarray.length; i++) {
PMDRigidBody rb = rbarray[i];
if (/*
}
}
public void resetRigidBodyPos() {
- for (PMDRigidBody rbarray[] : rigidBodyMap.values()) {
+ for (PMDRigidBody rbarray[] : nodeRigidBodyArray) {
for (int i = 0; i < rbarray.length; i++) {
PMDRigidBody rb = rbarray[i];
if (true) {
}
}
public void updateRigidBodyPos() {
- for (PMDRigidBody rbarray[] : rigidBodyMap.values()) {
+ for (PMDRigidBody rbarray[] : nodeRigidBodyArray) {
for (int i = 0; i < rbarray.length; i++) {
PMDRigidBody rb = rbarray[i];
if (true) {
import com.jme3.animation.Bone;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.objects.PhysicsRigidBody;
+import com.jme3.math.Matrix3f;
import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
public void updateFromBoneMatrix() {
if (bone != null) {
- tmpV.set(bone.getModelSpacePosition());
- tmpV.addLocal(pos);
- tmpQ.set(bone.getModelSpaceRotation());
- tmpQ.multLocal(rot);
+// tmpV.set(bone.getModelSpacePosition());
+// tmpV.addLocal(pos);
+// tmpQ.set(bone.getModelSpaceRotation());
+// tmpQ.multLocal(rot);
m2.setTranslation(bone.getModelSpacePosition());
m2.setRotationQuaternion(bone.getModelSpaceRotation());
m2.multLocal(m);
- super.setPhysicsLocation(m2.toTranslationVector());
- super.setPhysicsRotation(m2.toRotationQuat());
+ m2.toRotationMatrix(tmpMatrix3f);
+ tmpQ.fromRotationMatrix(tmpMatrix3f);
+ super.setPhysicsRotation(tmpQ);
+ m2.toTranslationVector(tmpV);
+ super.setPhysicsLocation(tmpV);
} else {
- tmpV.set(centerBone.getModelSpacePosition());
- tmpV.addLocal(pos);
- tmpQ.set(centerBone.getModelSpaceRotation());
- tmpQ.multLocal(rot);
+// tmpV.set(centerBone.getModelSpacePosition());
+// tmpV.addLocal(pos);
+// tmpQ.set(centerBone.getModelSpaceRotation());
+// tmpQ.multLocal(rot);
m2.setTranslation(centerBone.getModelSpacePosition());
m2.setRotationQuaternion(centerBone.getModelSpaceRotation());
m2.multLocal(m);
- super.setPhysicsRotation(m2.toRotationQuat());
- super.setPhysicsLocation(m2.toTranslationVector());
-
+ m2.toRotationMatrix(tmpMatrix3f);
+ tmpQ.fromRotationMatrix(tmpMatrix3f);
+ super.setPhysicsRotation(tmpQ);
+ m2.toTranslationVector(tmpV);
+ super.setPhysicsLocation(tmpV);
}
// System.out.println("objectId = "+objectId+(bone != null ? " name = "+bone.getName() : "")+" pos = "+getPhysicsLocation());
}
}
Matrix4f m2 = new Matrix4f();
Matrix4f m3 = new Matrix4f();
+ Matrix3f tmpMatrix3f = new Matrix3f();
public void updateToBoneMatrix() {
// System.out.println("objectId = "+objectId+" name = "+bone.getName()+" pos = "+getPhysicsLocation());
if (bone != null) {
if (rigidBodyType == 2) {
if (true/*!bone.getName().contains("センター")*/) {
- tmpV.set(super.getPhysicsLocation());
- tmpQ.set(super.getPhysicsRotation());
+ super.getPhysicsLocation(tmpV);
+ super.getPhysicsRotation(tmpQ);
m2.setRotationQuaternion(tmpQ);
m2.setTranslation(tmpV);
m2.multLocal(invM);
// System.out.println("updateToBoneMatrix:tmpV = "+tmpV);
// tmpV.addLocal(invPos);
// tmpQ.multLocal(invRot);
- bone.getModelSpaceRotation().set(m2.toRotationQuat());
+ m2.toRotationMatrix(tmpMatrix3f);
+ bone.getModelSpaceRotation().fromRotationMatrix(tmpMatrix3f);
+// m2.toRotationQuat(bone.getModelSpaceRotation());
// bone.getModelSpacePosition().set(m2.toTranslationVector());
// updateFromBoneMatrix();
// super.getPhysicsLocation();
}
} else {
if (rigidBodyType == 1 && !centerFlag) {
- tmpV.set(super.getPhysicsLocation());
- tmpQ.set(super.getPhysicsRotation());
+ super.getPhysicsLocation(tmpV);
+ super.getPhysicsRotation(tmpQ);
m2.setRotationQuaternion(tmpQ);
m2.setTranslation(tmpV);
m2.multLocal(invM);
// tmpV.addLocal(invPos);
// tmpQ.multLocal(invRot);
- bone.getModelSpaceRotation().set(m2.toRotationQuat());
- bone.getModelSpacePosition().set(m2.toTranslationVector());
+ m2.toRotationMatrix(tmpMatrix3f);
+ bone.getModelSpaceRotation().fromRotationMatrix(tmpMatrix3f);
+// m2.toRotationQuat(bone.getModelSpaceRotation());
+ m2.toTranslationVector(bone.getModelSpacePosition());
}
}
}
// }
// tpf = stepTime;
// tpf = 1f/15f;
- boolean needUpdateSkin = true;
+ boolean needUpdateSkin = false;
if (tpf != 0 && !pause) {
tpf += prevTpf;
for(;tpf > accuracy ; tpf -= accuracy ) {
physicsControl.getWorld().applyResultToBone();
prevTpf = tpf;
if (needUpdateSkin) {
-// resetSkins();
+ resetSkins();
calcSkins();
}
}
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
if (obj == null) {
return false;
}
return true;
}
+
+
@Override
public int hashCode() {
int hash = 7;
@Override
public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final PMDVertex other = (PMDVertex) obj;
+ if (this.pos != other.pos && (this.pos == null || !this.pos.equals(other.pos))) {
+ return false;
+ }
+ if (this.normal != other.normal && (this.normal == null || !this.normal.equals(other.normal))) {
+ return false;
+ }
+ if (this.uv != other.uv && (this.uv == null || !this.uv.equals(other.uv))) {
+ return false;
+ }
+ if (this.boneNum1 != other.boneNum1) {
+ return false;
+ }
+ if (this.boneNum2 != other.boneNum2) {
+ return false;
+ }
+ if (this.boneWeight != other.boneWeight) {
+ return false;
+ }
+ if (this.edgeFlag != other.edgeFlag) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean equals2(Object obj) {
if (this == obj) {
return true;
}
+" blue = "+green
+"}";
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final XColorRGB other = (XColorRGB) obj;
+ if (Float.floatToIntBits(this.red) != Float.floatToIntBits(other.red)) {
+ return false;
+ }
+ if (Float.floatToIntBits(this.green) != Float.floatToIntBits(other.green)) {
+ return false;
+ }
+ if (Float.floatToIntBits(this.blue) != Float.floatToIntBits(other.blue)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 41 * hash + Float.floatToIntBits(this.red);
+ hash = 41 * hash + Float.floatToIntBits(this.green);
+ hash = 41 * hash + Float.floatToIntBits(this.blue);
+ return hash;
+ }
}
+ " alpha = " + alpha
+ "}";
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!super.equals(obj)) {
+ return false;
+ }
+ final XColorRGBA other = (XColorRGBA) obj;
+ if (Float.floatToIntBits(this.alpha) != Float.floatToIntBits(other.alpha)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
}
List<MeshData> meshDataList = new ArrayList<MeshData>();
SkinMeshData skinMeshData;
HashMap<PMDVertex, Integer> meshTmpVertMap = new HashMap<PMDVertex, Integer>();
- HashMap<PMDVertex, Integer> skinTmpVertMap = new HashMap<PMDVertex, Integer>();
+ HashMap<Integer, Integer> skinTmpVertMap = new HashMap<Integer, Integer>();
public MeshConverter(PMDModel model) {
this.model = model;
int faceVertNo = 0;
for (int materialNo = 0; materialNo < model.getMaterialCount(); materialNo++) {
PMDMaterial material = model.getMaterial()[materialNo];
+ // find same material
+ MeshData meshData = new MeshData(model, maxBoneSize, material);
+ for(int meshIndex = meshDataList.size()-1;meshIndex >=0;meshIndex--) {
+ PMDMaterial material2 = meshDataList.get(meshIndex).getMaterial();
+ if (material.equals(material2)) {
+ meshData = meshDataList.get(meshIndex);
+ for(int i=meshData.getVertexList().size()-1;i>=0;i--) {
+ PMDVertex v = meshData.getVertexList().get(i);
+ meshTmpVertMap.put(v, i);
+ }
+ break;
+ }
+ }
if (material.getFaceVertCount() == 0) {
continue;
}
- MeshData meshData = new MeshData(model, maxBoneSize, material);
- meshDataList.add(meshData);
+ if (!meshDataList.contains(meshData)) {
+ meshDataList.add(meshData);
+ }
for (int materialFaceVertNo = 0; materialFaceVertNo < material.getFaceVertCount(); materialFaceVertNo += 3) {
int i1 = model.getFaceVertIndex()[faceVertNo++];
int i2 = model.getFaceVertIndex()[faceVertNo++];
for(MeshData meshData : meshDataList) {
// meshData.printTrinangles();
}
+ System.out.println("meshDataCount = "+meshDataList.size());
}
void printMeshData(MeshData meshData) {
System.out.println("vertSize = " + meshData.getVertexList().size()
} else {
newVertIndex = vertexList.size();
vertexList.add(v);
- mc.meshTmpVertMap.put(v, index);
+ mc.meshTmpVertMap.put(v, newVertIndex);
}
indexList.add(newVertIndex);
}
System.out.println(v);
}
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final MeshData other = (MeshData) obj;
+ if (this != obj) {
+ return false;
+ }
+ return true;
+ }
}
for(int i=0;i<sd.getSkinVertCount();i++) {
PMDVertex v = model.getVertexList()[sd.getSkinVertData()[i].getSkinVertIndex()];
vertexList.add(v);
- mc.skinTmpVertMap.put(v, i);
+ mc.skinTmpVertMap.put(sd.getSkinVertData()[i].getSkinVertIndex(), i);
}
}
}
private void addVertex(MeshConverter mc, List<Integer>indexList, int vertIndex) {
PMDVertex v = model.getVertexList()[vertIndex];
- Integer index = mc.skinTmpVertMap.get(v);
+ Integer index = mc.skinTmpVertMap.get(vertIndex);
int newVertIndex;
if (index != null /*vertexList.contains(v)*/) {
newVertIndex = index.intValue(); //vertexList.indexOf(v);
} else {
newVertIndex = vertexList.size();
vertexList.add(v);
- mc.skinTmpVertMap.put(v, newVertIndex);
+ mc.skinTmpVertMap.put(vertIndex, newVertIndex);
index = newVertIndex;
}
indexList.add(index/*newVertIndex*/);