public Vertex bake(Mesh mesh, Function<Node<?>, Matrix4f> animator) { // geometry Float totalWeight = 0f; Matrix4f t = new Matrix4f(); if (mesh.getWeightMap().get(this).isEmpty()) { t.setIdentity(); } else { for (Pair<Float, Node<Bone>> bone : mesh.getWeightMap().get(this)) { totalWeight += bone.getLeft(); Matrix4f bm = animator.apply(bone.getRight()); bm.mul(bone.getLeft()); t.add(bm); } if (Math.abs(totalWeight) > 1e-4) t.mul(1f / totalWeight); else t.setIdentity(); } // pos Vector4f pos = new Vector4f(this.pos), newPos = new Vector4f(); pos.w = 1; t.transform(pos, newPos); Vector3f rPos = new Vector3f(newPos.x / newPos.w, newPos.y / newPos.w, newPos.z / newPos.w); // normal Vector3f rNormal = null; if (this.normal != null) { Matrix3f tm = new Matrix3f(); t.getRotationScale(tm); tm.invert(); tm.transpose(); Vector3f normal = new Vector3f(this.normal); rNormal = new Vector3f(); tm.transform(normal, rNormal); rNormal.normalize(); } // texCoords TODO return new Vertex(rPos, rNormal, color, texCoords); }
public Matrix3f orientation() { Matrix4f t = transform(); Matrix3f ori = new Matrix3f(); t.getRotationScale(ori); return ori; }