|
From: <tre...@us...> - 2007-09-28 23:01:07
|
Revision: 460
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=460&view=rev
Author: trevorolio
Date: 2007-09-28 16:01:11 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Added a couple of morphs to Mike and hooked them up to the skin loader.
Don't get excited, they aren't in any order and they're not connected to any user prefs.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DBodyData.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataManager.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/SkinLoader.java
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DBodyData.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DBodyData.java 2007-09-28 23:01:06 UTC (rev 459)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DBodyData.java 2007-09-28 23:01:11 UTC (rev 460)
@@ -8,6 +8,7 @@
import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.util.BodyConstants;
+import com.ogoglio.viewer.j3d.body.MorphDeltaMap;
import com.ogoglio.viewer.j3d.bvh.Bvh;
import com.ogoglio.viewer.j3d.smap.SkinMap;
@@ -21,8 +22,10 @@
private BufferedImage baseTexture = null;
private Bvh defaultAnimation = null;
+
+ private MorphDeltaMap[] morphDeltaMaps = null;
- public J3DBodyData(IndexedTriangleArray bodyGeometry, Bvh[] animations, SkinMap skinMap, BufferedImage baseTexture) {
+ public J3DBodyData(IndexedTriangleArray bodyGeometry, Bvh[] animations, SkinMap skinMap, BufferedImage baseTexture, MorphDeltaMap[] morphDeltaMaps) {
ArgumentUtils.assertNotNull(bodyGeometry);
this.bodyGeometry = bodyGeometry;
ArgumentUtils.assertNotNull(animations);
@@ -31,7 +34,9 @@
this.skinMap = skinMap;
ArgumentUtils.assertNotNull(baseTexture);
this.baseTexture = baseTexture;
-
+ ArgumentUtils.assertNotNull(morphDeltaMaps);
+ this.morphDeltaMaps = morphDeltaMaps;
+
for (int i = 0; i < animations.length; i++) {
if (animations[i].getName().equals(BodyConstants.DEFAULT_ANIMATION_NAME)) {
defaultAnimation = animations[i];
@@ -104,4 +109,8 @@
public Bvh getDefaultAnimation() {
return defaultAnimation;
}
+
+ public MorphDeltaMap[] getMorphDeltaMaps(){
+ return morphDeltaMaps;
+ }
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataManager.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataManager.java 2007-09-28 23:01:06 UTC (rev 459)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataManager.java 2007-09-28 23:01:11 UTC (rev 460)
@@ -37,6 +37,9 @@
import com.ogoglio.util.Log;
import com.ogoglio.util.StreamUtils;
import com.ogoglio.util.UIConstants;
+import com.ogoglio.viewer.j3d.body.MorphDeltaMap;
+import com.ogoglio.viewer.j3d.body.MorphDeltaMapParseException;
+import com.ogoglio.viewer.j3d.body.MorphDeltaMapParser;
import com.ogoglio.viewer.j3d.bvh.Bvh;
import com.ogoglio.viewer.j3d.bvh.BvhParseException;
import com.ogoglio.viewer.j3d.bvh.BvhParser;
@@ -101,6 +104,7 @@
if (bodyData == null) {
throw new IllegalStateException("Trevor didn't implement an error body for an illegible body");
}
+ System.out.println("Morph count: " + bodyData.getMorphDeltaMaps().length);
dataCache.putBodyData(bodyName, bodyData);
return bodyData;
}
@@ -109,6 +113,7 @@
IndexedTriangleArray array = null;
SkinMap skinMap = null;
Vector animations = new Vector();
+ Vector morphDeltas = new Vector();
BufferedImage baseTexture = null;
try {
ZipEntry entry = null;
@@ -121,6 +126,9 @@
} else if (entry.getName().equals("geometry/body.smap")) {
SkinMapParser parser = new SkinMapParser(entryStream);
skinMap = parser.parse();
+ } else if (entry.getName().startsWith("geometry/") && entry.getName().endsWith(".ogmorph")) {
+ MorphDeltaMap deltaMap = new MorphDeltaMapParser(entryStream).parse();
+ morphDeltas.add(deltaMap);
} else if (entry.getName().startsWith("animation/") && entry.getName().indexOf(".bvh") != -1) {
String name = entry.getName().substring("animation/".length(), entry.getName().length() - 4);
BvhParser parser = new BvhParser(name, entryStream);
@@ -139,9 +147,10 @@
throw new IllegalStateException("Trevor didn't implement an error body: " + e);
} catch (BvhParseException e) {
throw new IllegalStateException("Trevor didn't implement an error body: " + e);
+ } catch (MorphDeltaMapParseException e) {
+ throw new IllegalStateException("Trevor didn't implement an error body: " + e);
}
-
- return new J3DBodyData(array, (Bvh[]) animations.toArray(new Bvh[0]), skinMap, baseTexture);
+ return new J3DBodyData(array, (Bvh[]) animations.toArray(new Bvh[0]), skinMap, baseTexture, (MorphDeltaMap[])morphDeltas.toArray(new MorphDeltaMap[0]));
}
private IndexedTriangleArray generateBodyGeometry(Obj obj) {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-09-28 23:01:06 UTC (rev 459)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-09-28 23:01:11 UTC (rev 460)
@@ -95,7 +95,7 @@
private void initBody() {
bodyGroup.removeAllChildren();
- skin = new SkinLoader((GeometryArray) bodyData.cloneBodyGeometry(), bodyData.getBaseTexture(), user.getBody()).generateSkin();
+ skin = new SkinLoader(bodyData, user.getBody()).generateSkin();
userHeight = skin.getHeight();
skinMap = bodyData.getSkinMap();
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/SkinLoader.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/SkinLoader.java 2007-09-28 23:01:06 UTC (rev 459)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/SkinLoader.java 2007-09-28 23:01:11 UTC (rev 460)
@@ -17,8 +17,10 @@
import java.awt.image.BufferedImage;
import javax.media.j3d.GeometryArray;
+import javax.vecmath.Vector3f;
import com.ogoglio.client.model.Body;
+import com.ogoglio.viewer.j3d.J3DBodyData;
public class SkinLoader {
@@ -28,28 +30,45 @@
private BufferedImage baseImage;
- public SkinLoader(GeometryArray geometry, BufferedImage baseImage, Body body) {
- this.geometry = geometry;
+ private MorphDeltaMap[] morphDeltaMaps = null;
+
+ public SkinLoader(J3DBodyData bodyData, Body body) {
+ this.geometry = bodyData.cloneBodyGeometry();
+ this.morphDeltaMaps = bodyData.getMorphDeltaMaps();
+ this.baseImage = bodyData.getBaseTexture();
this.body = body;
- this.baseImage = baseImage;
}
public Skin generateSkin() {
+ float[] vertices = geometry.getCoordRefFloat();
+ //TODO make these happen in depth first order of the morph ADG
+ for (int i = 0; i < morphDeltaMaps.length; i++) {
+ MorphDeltaMap.Range[] ranges = morphDeltaMaps[i].getRanges();
+ for (int r = 0; r < ranges.length; r++) {
+ Vector3f[] deltas = ranges[r].getDeltas();
+ for (int d = 0; d < deltas.length; d++) {
+ int index = (ranges[r].getLower() - 1 + d) * 3;
+ System.out.println(vertices[index] + "," + vertices[index + 1] + "," + vertices[index + 2]);
+ System.out.println("Deltas " + deltas[d].x + "," + deltas[d].y + "," + deltas[d].z);
+ vertices[index] = vertices[index] + deltas[d].x;
+ vertices[index + 1] = vertices[index + 1] + deltas[d].y;
+ vertices[index + 2] = vertices[index + 2] + deltas[d].z;
+ }
+ }
+ }
+
float maxY = Float.MIN_VALUE;
float minY = Float.MAX_VALUE;
-
- float[] vertices = geometry.getCoordRefFloat();
for (int i = 1; i < vertices.length; i += 3) {
- if(vertices[i] < minY){
+ if (vertices[i] < minY) {
minY = vertices[i];
}
- if(vertices[i] > maxY){
+ if (vertices[i] > maxY) {
maxY = vertices[i];
}
}
-
float heightScale = body.getHeight() / Math.abs(maxY - minY);
- if(Math.abs(heightScale) > 0.1){
+ if (Math.abs(heightScale) > 0.1) {
for (int i = 0; i < vertices.length - 2; i += 3) {
vertices[i] = vertices[i] * heightScale;
vertices[i + 1] = vertices[i + 1] * heightScale;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|