|
From: <tre...@us...> - 2007-09-17 22:37:59
|
Revision: 404
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=404&view=rev
Author: trevorolio
Date: 2007-09-17 15:38:01 -0700 (Mon, 17 Sep 2007)
Log Message:
-----------
Rewhacked Mike avatar to take a commonly available BVH style, so now he can walk, wave, and point.
Haven't tested it with the other two Croquet models yet, but it might Just Work. (famous last words)
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/MultiuserTests.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DSplinePath.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/MotionInputHandler.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/BodyAnimator.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skeleton.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skin.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-point.bvh
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-walk.bvh
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-wave.bvh
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar.bvh
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar.obj
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar.smap
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/MultiuserTests.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/MultiuserTests.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/MultiuserTests.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -145,7 +145,7 @@
} else if(lastSpun) {
userPosition.set(user.getPosition());
userPosition.rotY(random.nextFloat() % (2 * Math.PI));
- SplinePath path = J3DSplinePath.getSplinePath(userPosition, 1, 0, 0);
+ SplinePath path = J3DSplinePath.getSplinePath(userPosition, 1, 0, 0, 2);
robot.spaceClient.viewpointMotionChanged(path);
try {
sleep(3000 + Math.abs((random.nextInt() % 6000)));
@@ -154,7 +154,7 @@
}
lastSpun = false;
} else {
- SplinePath path = J3DSplinePath.getSplinePath(user.getPosition(), 0, 1, 0);
+ SplinePath path = J3DSplinePath.getSplinePath(user.getPosition(), 0, 1, 0, 2);
robot.spaceClient.viewpointMotionChanged(path);
try {
sleep(1000 + Math.abs((random.nextInt() % 6000)));
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Space.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -118,7 +118,6 @@
Arrays.sort(things, new DistanceComparator());
if (things.length > 0) {
- Log.info("Adding " + things[0].getName());
listener.thingAdded(things[0]);
}
@@ -128,7 +127,6 @@
}
for (int i = 1; i < things.length; i++) {
- Log.info("Adding " + things[i].getName());
listener.thingAdded(things[i]);
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -48,7 +48,9 @@
import com.ogoglio.client.model.Thing;
import com.ogoglio.client.model.User;
import com.ogoglio.util.Log;
+import com.ogoglio.viewer.j3d.bvh.Bvh;
import com.ogoglio.viewer.j3d.bvh.BvhParseException;
+import com.ogoglio.viewer.j3d.bvh.BvhParser;
import com.ogoglio.viewer.j3d.obj.Obj;
import com.ogoglio.viewer.j3d.obj.ObjParseException;
import com.ogoglio.viewer.j3d.obj.ObjParser;
@@ -109,7 +111,7 @@
private J3DWater water = null;
private boolean rendererStopped = false;
-
+
private boolean completedInitialLoad = false;
public J3DRenderer(SpaceClient spaceClient, boolean offScreen) {
@@ -239,7 +241,7 @@
private class SpaceListener implements Space.Listener {
public void pageMoved(Page page, Transform3D position) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DThingRenderable thingRenderable = (J3DThingRenderable) getThingRenderable(page.getThing().getThingID());
@@ -256,7 +258,7 @@
}
public void pageAdded(Page page) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DThingRenderable thingRenderable = (J3DThingRenderable) getThingRenderable(page.getThing().getThingID());
@@ -280,7 +282,7 @@
}
public void pageContentChanged(Page page) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DThingRenderable thingRenderable = (J3DThingRenderable) getThingRenderable(page.getThing().getThingID());
@@ -301,7 +303,7 @@
}
public void thingAdded(Thing thing) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
try {
@@ -327,7 +329,7 @@
}
public void thingMotionStarted(Thing thing, SplinePath path) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
ThingRenderable renderable = getThingRenderable(thing.getThingID());
@@ -343,7 +345,7 @@
}
public void thingReloaded(Thing thing) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
try {
@@ -386,7 +388,7 @@
}
public void userAdded(User user) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
try {
@@ -404,7 +406,7 @@
}
public void userMotionStarted(User user, SplinePath path) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DUserRenderable renderable = (J3DUserRenderable) getUserRenderable(user.getUsername());
@@ -412,7 +414,6 @@
return;
}
startRenderableMotion(renderable, path);
- /* turn off walking until we have a good animation
if (!offScreen) {
try {
BvhParser bvhParser = new BvhParser(user, 2);
@@ -424,7 +425,6 @@
e.printStackTrace();
}
}
- */
}
public void userMotionStopped(User user, Transform3D position) {
@@ -437,14 +437,13 @@
}
public void userAnimationStarted(User user, long animationID) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DUserRenderable renderable = (J3DUserRenderable) getUserRenderable(user.getUsername());
if (renderable == null) { //haven't loaded the renderable
return;
}
- /*
if (!offScreen) {
try {
BvhParser bvhParser = new BvhParser(user, animationID);
@@ -456,7 +455,6 @@
e.printStackTrace();
}
}
- */
}
public void userRemoved(User user) {
@@ -465,7 +463,7 @@
}
public void doorMotionStarted(Door door, SplinePath path) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
DoorRenderable renderable = getDoorRenderable(door.getDoorID());
@@ -478,7 +476,7 @@
}
public void doorAdded(Door door) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
try {
@@ -499,7 +497,7 @@
}
public void shapeMotionStarted(Shape shape, SplinePath path) {
- if(rendererStopped) {
+ if (rendererStopped) {
return;
}
J3DThingRenderable renderable = (J3DThingRenderable) getThingRenderable(shape.getThing().getThingID());
@@ -531,10 +529,10 @@
}
public void stopRenderer() {
- rendererStopped = true;
+ rendererStopped = true;
physicsBehavior.cleanup();
universe.removeAllLocales();
- if(!offScreen) {
+ if (!offScreen) {
canvas.stopRenderer();
Log.info("Stopped renderer");
}
@@ -598,8 +596,8 @@
}
return (UserRenderable[]) results.toArray(new UserRenderable[0]);
}
- */
-
+ */
+
private void removeUserRenderable(UserRenderable renderable) {
if (renderable == null) {
Log.error("User renderable == null");
@@ -649,11 +647,13 @@
private UserRenderable createUserRenderable(User user) throws IOException, RenderableParseException {
try {
boolean isLocalUser = !offScreen && username != null && user.getUsername().equals(username);
- final J3DUserRenderable renderable = new J3DUserRenderable(user, !offScreen && !isLocalUser);
+ Bvh defaultBvh = new BvhParser(user, 1).parse();
+ final J3DUserRenderable renderable = new J3DUserRenderable(user, !offScreen && !isLocalUser, defaultBvh);
renderable.setID(USER_ID_PREFIX + user.getUsername());
if (isLocalUser) {
- camera.setLocation(new Vector3f(0f, 2f, 0f));
+ float cameraHeight = (float) (renderable.getHeight() - renderable.getHeight() / 5);
+ camera.setLocation(new Vector3f(0f, cameraHeight, 0f));
renderable.setCamera(camera);
motionHandler = new MotionInputHandler(this, renderable, userInputListener);
@@ -667,13 +667,6 @@
renderable.setNameTag(displayName);
}
- /*
- if (!offScreen) {
- BvhParser bvhParser = new BvhParser(user, 1);
- Bvh bvh = bvhParser.parse();
- renderable.playAnimation(bvh, false);
- }
- */
return renderable;
} catch (BvhParseException e) {
e.printStackTrace();
@@ -719,7 +712,7 @@
Obj[] objs = new Obj[GeometryProvider.LOD_DISTANCES.length + 1];
for (int i = 0; i < objs.length; i++) {
objs[i] = getObj(thing, i);
- if(objs[i] != null && objs[i].getGroups().length == 0) {
+ if (objs[i] != null && objs[i].getGroups().length == 0) {
Log.error("Got obj with no groups for thing " + thing.getThingID() + ": " + thing.getName());
objs[i] = null;
}
@@ -769,7 +762,7 @@
lightD1.setInfluencingBounds(DEFAULT_SPACE_BOUNDS);
sceneRoot.addChild(lightD1);
}
- */
+ */
public Canvas getCanvas() {
return canvas;
}
@@ -829,7 +822,7 @@
public double getLandHeight(double x, double z, double pickHeight) {
pickStart.set(x, pickHeight, z);
if (picker.pickRayClosest(pickStart, DOWN_VEC, intersectionPoint) == null) {
- //System.out.println("no land height: 0!");
+ //System.out.println("no land height: 0!");
return 0;
}
//System.out.println("intersected with land: "+intersectionPoint.y);
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DSplinePath.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DSplinePath.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DSplinePath.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -56,7 +56,7 @@
* @param forwardSpeed between -1 and 1
* @param turn between -1 and 1
*/
- public static SplinePath getSplinePath(Transform3D startPosition, float forwardSpeed, float turn, float strafeSpeed) {
+ public static SplinePath getSplinePath(Transform3D startPosition, float forwardSpeed, float turn, float strafeSpeed, float userHeight) {
Vector3f[] positions = null;
Vector3f[] headings = null;
long duration = 0;
@@ -142,7 +142,7 @@
float knotValue = i == positions.length - 1 ? 1 : i * (1f / positions.length);
keyFrames[i] = new J3DSplineKeyFrame(knotValue, false, new Point3f(positions[i]), headings[i].x, headings[i].y, headings[i].z, scale, -1f, 0f, 0f);
}
- return new J3DSplinePath(keyFrames, duration, looping, true, 0.02);
+ return new J3DSplinePath(keyFrames, duration, looping, true, 0);
}
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-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -18,17 +18,17 @@
import java.io.IOException;
import javax.media.j3d.Billboard;
-import javax.media.j3d.BoundingBox;
+import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
-import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import com.ogoglio.client.model.Body;
import com.ogoglio.client.model.User;
+import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.viewer.j3d.body.BodyAnimator;
import com.ogoglio.viewer.j3d.body.Skeleton;
import com.ogoglio.viewer.j3d.body.SkeletonLoader;
@@ -49,6 +49,8 @@
public class J3DUserRenderable extends BranchGroup implements UserRenderable {
+ private static final float MAGIC_SKELETON_SCALE = 2.5f;
+
public static float PERSON_HEIGHT = 2f;
private TransformGroup transformGroup = new TransformGroup();
@@ -57,6 +59,8 @@
private User user = null;
+ private Bvh defaultAnimation = null;
+
private J3DCamera camera = null;
private Skin skin = null;
@@ -65,39 +69,48 @@
private SkinMap skinMap = null;
-// private double skinScale = 0;
+ private float skeletonScale = 1;
- private double skeletonScale = 0;
+ private BodyAnimator animator = null;
- private float skeletonYShift = 0;
+ private BodyAnimatorListener bodyAnimatorListener = new BodyAnimatorListener();
+
+ float userHeight = 2; //meters
- private BodyAnimator animator = null;
-
- public J3DUserRenderable(User user, boolean setVisible) throws IOException, ObjParseException, BvhParseException, SkinMapParseException {
+ public J3DUserRenderable(User user, boolean setVisible, Bvh defaultAnimation) throws IOException, ObjParseException, BvhParseException, SkinMapParseException {
+ ArgumentUtils.assertNotNull(user);
this.user = user;
- BvhParser bvhParser = new BvhParser(user, 1);
- Bvh bvh = bvhParser.parse();
- skeleton = new SkeletonLoader(bvh).generateSkeleton();
- //skeleton.addDebugAttachments();
-
+ ArgumentUtils.assertNotNull(defaultAnimation);
+ this.defaultAnimation = defaultAnimation;
+
if (setVisible) {
ObjParser parser = new ObjParser(user, 0);
parser.setIgnoreMaterialsFiles(true);
Obj obj = parser.parse();
skin = new SkinLoader(obj, user.getBody()).generateSkin();
-
+ userHeight = skin.getHeight();
+
SkinMapParser skinMapParser = new SkinMapParser(user);
skinMap = skinMapParser.parse();
+ }
+ scaleBVH(defaultAnimation);
+
+ skeleton = new SkeletonLoader(defaultAnimation).generateSkeleton();
+ //skeleton.addDebugAttachments();
+ if(setVisible){
skin.setSkeleton(skeleton, skinMap);
}
-
+
setCapability(BranchGroup.ALLOW_DETACH);
+ setCapability(BranchGroup.ALLOW_BOUNDS_READ);
setCapabilities(transformGroup);
addChild(transformGroup);
Transform3D rotationTransform = new Transform3D();
rotationTransform.rotY(Math.PI);
+ float hairHeight = defaultAnimation.getJointHeight("lFoot");
+ rotationTransform.setTranslation(new Vector3d(0, -1 * hairHeight, 0));
bodyGroup.setTransform(rotationTransform);
if (setVisible) {
bodyGroup.addChild(skin);
@@ -106,8 +119,17 @@
transformGroup.addChild(bodyGroup);
setPosition(user.getPosition());
+ playAnimation(defaultAnimation, false);
}
+ private void scaleBVH(Bvh bvh){
+ float bvhHeight = bvh.getHeight();
+ if(bvhHeight != userHeight){
+ skeletonScale = userHeight / bvhHeight / MAGIC_SKELETON_SCALE; //TODO figure out why we need this magic scale number
+ bvh.scale(skeletonScale);
+ }
+ }
+
public void setNameTag(String nameTag) {
TransformGroup nameGroup = new TransformGroup();
nameGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
@@ -129,6 +151,7 @@
}
private void setCapabilities(TransformGroup group) {
+ group.setCapability(TransformGroup.ALLOW_BOUNDS_READ);
group.setCapability(TransformGroup.ALLOW_PICKABLE_READ);
group.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
@@ -235,24 +258,13 @@
return skeletonScale;
}
- public float getSkeletonYShift() {
- return skeletonYShift;
- }
-
public User getUser() {
return user;
}
-
+
public double getHeight() {
- if (skin == null) {
- return 2;
- }
- BoundingBox bounds = (BoundingBox) skin.getBounds();
- Point3d upper = new Point3d();
- bounds.getUpper(upper);
- Point3d lower = new Point3d();
- bounds.getLower(lower);
- return upper.y - lower.y;
+ BoundingSphere bounds = (BoundingSphere) getBounds();
+ return Math.abs(bounds.getRadius() * 2);
}
public void cleanup() {
@@ -272,14 +284,26 @@
animator.cleanup();
animator = null;
}
+ playAnimation(defaultAnimation, false);
}
+ private class BodyAnimatorListener implements BodyAnimator.Listener {
+ public void bodyAnimationCompleted(BodyAnimator animator) {
+ if(animator.getBvh() == defaultAnimation){
+ return;
+ }
+ playAnimation(defaultAnimation, false);
+ }
+ }
+
public synchronized void playAnimation(Bvh bvh, boolean loop) {
if (animator != null) {
animator.cleanup();
}
+
if (skeleton != null && bvh != null && skin != null) {
- animator = new BodyAnimator(skeleton, bvh, skin);
+ scaleBVH(bvh);
+ animator = new BodyAnimator(skeleton, bvh, skin, bodyAnimatorListener);
animator.animate(loop);
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/MotionInputHandler.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/MotionInputHandler.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/MotionInputHandler.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -64,7 +64,7 @@
private UserInputListener userInputListener = null;
- private UserRenderable userGroup = null;
+ private UserRenderable userRenderable = null;
public MotionInputHandler(Renderer renderer, UserRenderable userGroup, UserInputListener inputListener) {
ArgumentUtils.assertNotNull(renderer);
@@ -72,7 +72,7 @@
ArgumentUtils.assertNotNull(inputListener);
this.userInputListener = inputListener;
ArgumentUtils.assertNotNull(userGroup);
- this.userGroup = userGroup;
+ this.userRenderable = userGroup;
}
private synchronized void reevaluate() {
@@ -91,14 +91,14 @@
dirty = false;
Transform3D position = new Transform3D();
- userGroup.getPosition(position);
+ userRenderable.getPosition(position);
SplinePath path = null;
float turn = (turnLeft ? -1 : 0) + (turnRight ? 1 : 0);
float forwardSpeed = (moveForward ? 1 : 0) + (moveBackward ? -1 : 0);
float strafeSpeed = (strafeLeft ? 1 : 0) + (strafeRight ? -1 : 0);
if (turn != 0 || forwardSpeed != 0 || strafeSpeed != 0) {
- path = J3DSplinePath.getSplinePath(position, forwardSpeed, turn, strafeSpeed);
+ path = J3DSplinePath.getSplinePath(position, forwardSpeed, turn, strafeSpeed, (float)userRenderable.getHeight());
userInputListener.viewpointMotionChanged(path);
return;
} else {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/BodyAnimator.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/BodyAnimator.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/BodyAnimator.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -42,17 +42,28 @@
private boolean loop = false;
private boolean cleaned = false;
-
- public BodyAnimator(Skeleton skeleton, Bvh bvh, Skin skin) {
+
+ private Listener listener = null;
+
+ public BodyAnimator(Skeleton skeleton, Bvh bvh, Skin skin, Listener listener) {
this.skeleton = skeleton;
this.bvh = bvh;
this.skin = skin;
+ this.listener = listener;
}
+ public static interface Listener {
+ public void bodyAnimationCompleted(BodyAnimator animator);
+ }
+
+ public Bvh getBvh(){
+ return bvh;
+ }
+
private void pose(int index) {
Joint joint = bvh.getRootJoint();
pose(joint, bvh.getFrame(index));
- if(cleaned) {
+ if (cleaned) {
return;
}
skin.pose();
@@ -60,7 +71,7 @@
private void pose(Bvh.Joint joint, Bvh.Frame frame) {
workingTransform.setIdentity();
- if(cleaned) {
+ if (cleaned) {
return;
}
Bone bone = skeleton.getRootBone().getBone(joint.getName());
@@ -80,6 +91,7 @@
frameIndex = 0;
} else {
cleanup();
+ listener.bodyAnimationCompleted(this);
return;
}
}
@@ -92,7 +104,7 @@
}
public synchronized void animate(boolean loop) {
- if(cleaned) {
+ if (cleaned) {
throw new IllegalStateException("Can only use a BodyAnimator once (for now)");
}
task.cancel();
@@ -104,11 +116,11 @@
private class AnimationTask extends TimerTask {
public void run() {
- if(cleaned) {
+ if (cleaned) {
cancel();
}
step();
- if(cleaned) {
+ if (cleaned) {
cancel();
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skeleton.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skeleton.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skeleton.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -98,7 +98,7 @@
}
public String toString() {
- return name;
+ return name + ":" + offset;
}
public Bone getParentBone() {
@@ -173,7 +173,7 @@
for (int i = 0; i < indent; i++) {
buffer.append("\t");
}
- Log.info(buffer.toString()+bone.getName());
+ Log.info(buffer.toString() + bone);
for (int i = 0; i < bone.getChildCount(); i++) {
print(bone.getChildBone(i), indent + 1);
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skin.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skin.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/Skin.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -19,6 +19,7 @@
import java.util.Vector;
import javax.media.j3d.Appearance;
+import javax.media.j3d.BoundingBox;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Geometry;
import javax.media.j3d.GeometryArray;
@@ -31,6 +32,7 @@
import javax.media.j3d.Texture;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
+import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
@@ -173,7 +175,6 @@
if (groups[i] != null) {
ranges[i] = groups[i].getRanges();
} else {
- Log.warn("No ranges for " + bones[i].getName());
ranges[i] = null;
}
lastTransforms[i] = new Transform3D();
@@ -266,4 +267,13 @@
}
}
+ public float getHeight() {
+ BoundingBox bounds = (BoundingBox)getBounds();
+ Point3d upper = new Point3d();
+ bounds.getUpper(upper);
+ Point3d lower = new Point3d();
+ bounds.getLower(lower);
+ return (float)(upper.y - lower.y);
+ }
+
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java 2007-09-17 22:37:42 UTC (rev 403)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java 2007-09-17 22:38:01 UTC (rev 404)
@@ -107,6 +107,17 @@
//TODO stop ignoring scale
}
+ public void scaleFrameData(float amountToScale, Frame frame) {
+ if (startIndex == -1) {
+ return;
+ }
+ if (channelIndices[0] != -1 && channelIndices[1] != -1 && channelIndices[2] != -1) {
+ frame.data[startIndex + channelIndices[0]] = frame.data[startIndex + channelIndices[0]] * amountToScale;
+ frame.data[startIndex + channelIndices[1]] = frame.data[startIndex + channelIndices[1]] * amountToScale;
+ frame.data[startIndex + channelIndices[2]] = frame.data[startIndex + channelIndices[2]] * amountToScale;
+ }
+ }
+
public String getName() {
return name;
}
@@ -169,19 +180,84 @@
public Joint getRootJoint() {
return rootJoint;
}
-
+
+ public Joint getJointByName(String jointName) {
+ Vector joints = new Vector();
+ getJoints(getRootJoint(), joints);
+ for (int i = 0; i < joints.size(); i++) {
+ if (jointName.equals(((Joint) joints.get(i)).getName())) {
+ return (Joint) joints.get(i);
+ }
+ }
+ return null;
+ }
+
+ private void getJoints(Joint joint, Vector results) {
+ results.add(joint);
+ for (int i = 0; i < joint.getChildCount(); i++) {
+ getJoints(joint.getChild(i), results);
+ }
+ }
+
public void printJoint(Joint joint) {
printJoint(joint, 0);
}
-
+
private void printJoint(Joint joint, int offset) {
- StringBuffer buff=new StringBuffer();
+ StringBuffer buff = new StringBuffer();
for (int i = 0; i < offset; i++) {
buff.append("\t");
}
- Log.info(buff.toString()+joint.getName() + ": " + joint.getOffset());
+ Log.info(buff.toString() + joint.getName() + ": " + joint.getOffset());
for (int i = 0; i < joint.getChildCount(); i++) {
printJoint(joint.getChild(i), offset + 1);
}
}
+
+ public float getHeight() {
+ float minY = Float.MAX_VALUE;
+ float maxY = Float.MIN_VALUE;
+ Vector joints = new Vector();
+ getJoints(getRootJoint(), joints);
+ for (int i = 0; i < joints.size(); i++) {
+ Joint joint = (Joint) joints.get(i);
+ if (joint.getOffset().y < minY) {
+ minY = joint.getOffset().y;
+ }
+ if (joint.getOffset().y > maxY) {
+ maxY = joint.getOffset().y;
+ }
+ }
+ if (minY == Float.MAX_VALUE || maxY == Float.MIN_VALUE) {
+ return 0;
+ }
+ return maxY - minY;
+ }
+
+ public void scale(float amountToScale) {
+ Vector joints = new Vector();
...
[truncated message content] |
|
From: <tre...@us...> - 2007-09-17 23:35:29
|
Revision: 411
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=411&view=rev
Author: trevorolio
Date: 2007-09-17 16:35:33 -0700 (Mon, 17 Sep 2007)
Log Message:
-----------
Refactored the way user animations are referenced so as to reduce duplicate code and allow for easy addition.
Now avatars can /wave /clap /point and /laugh in addition to the usual standing and walking animations.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/render/UIConstants.java
Added Paths:
-----------
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-clap.bvh
maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-laugh.bvh
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-09-17 23:35:27 UTC (rev 410)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/SpaceClient.java 2007-09-17 23:35:33 UTC (rev 411)
@@ -725,16 +725,7 @@
}
public InputStream getUserAnimationStream(String username, long animationID) throws IOException {
- if (animationID == 1) {
- return UIConstants.getResource("avatar/avatar.bvh");
- } else if (animationID == 2) {
- return UIConstants.getResource("avatar/avatar-walk.bvh");
- } else if (animationID == 3) {
- return UIConstants.getResource("avatar/avatar-wave.bvh");
- } else if (animationID == 4) {
- return UIConstants.getResource("avatar/avatar-point.bvh");
- }
- return null;
+ return UIConstants.getUserAnimation((int) animationID);
}
public InputStream getUserSkinMapStream(String username) throws IOException {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-09-17 23:35:27 UTC (rev 410)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.java 2007-09-17 23:35:33 UTC (rev 411)
@@ -416,7 +416,7 @@
startRenderableMotion(renderable, path);
if (!offScreen) {
try {
- BvhParser bvhParser = new BvhParser(user, 2);
+ BvhParser bvhParser = new BvhParser(user, 1);
Bvh bvh = bvhParser.parse();
renderable.playAnimation(bvh, true);
} catch (IOException e) {
@@ -647,7 +647,7 @@
private UserRenderable createUserRenderable(User user) throws IOException, RenderableParseException {
try {
boolean isLocalUser = !offScreen && username != null && user.getUsername().equals(username);
- Bvh defaultBvh = new BvhParser(user, 1).parse();
+ Bvh defaultBvh = new BvhParser(user, 0).parse();
final J3DUserRenderable renderable = new J3DUserRenderable(user, !offScreen && !isLocalUser, defaultBvh);
renderable.setID(USER_ID_PREFIX + user.getUsername());
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/render/UIConstants.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/render/UIConstants.java 2007-09-17 23:35:27 UTC (rev 410)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/render/UIConstants.java 2007-09-17 23:35:33 UTC (rev 411)
@@ -54,6 +54,38 @@
public static Color3f DARK_GREEN = new Color3f(0.6468f, 0.7867f, 0.0664f);
+ public static final String DEFAULT_ANIMATION_PATH = "avatar/avatar.bvh";
+
+ public static final String WALK_ANIMATION_PATH = "avatar/avatar-walk.bvh";
+
+ public static final String WAVE_ANIMATION_PATH = "avatar/avatar-wave.bvh";
+
+ public static final String POINT_ANIMATION_PATH = "avatar/avatar-point.bvh";
+
+ public static final String LAUGH_ANIMATION_PATH = "avatar/avatar-laugh.bvh";
+
+ public static final String CLAP_ANIMATION_PATH = "avatar/avatar-clap.bvh";
+
+ public static final String[] USER_ANIMATION_COMMANDS = { "default", "walk", "wave", "point", "laugh", "clap" };
+
+ public static final String[] USER_ANIMATION_PATHS = { DEFAULT_ANIMATION_PATH, WALK_ANIMATION_PATH, WAVE_ANIMATION_PATH, POINT_ANIMATION_PATH, LAUGH_ANIMATION_PATH, CLAP_ANIMATION_PATH };
+
+ public static InputStream getUserAnimation(int animationID) {
+ if(animationID < 0 || animationID >= USER_ANIMATION_PATHS.length){
+ return null;
+ }
+ return getResource(USER_ANIMATION_PATHS[animationID]);
+ }
+
+ public static InputStream getUserAnimation(String command) {
+ for (int i = 0; i < USER_ANIMATION_COMMANDS.length; i++) {
+ if (USER_ANIMATION_COMMANDS[i].equals(command)) {
+ return getResource(USER_ANIMATION_PATHS[i]);
+ }
+ }
+ return null;
+ }
+
public static ImageIcon loadIconFromResource(String resourcePath) {
try {
byte[] buffer = null;
Added: maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-clap.bvh
===================================================================
--- maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-clap.bvh (rev 0)
+++ maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-clap.bvh 2007-09-17 23:35:33 UTC (rev 411)
@@ -0,0 +1,159 @@
+HIERARCHY
+ROOT hip
+{
+ OFFSET 0.00 0.00 0.00
+ CHANNELS 6 Xposition Yposition Zposition Xrotation Zrotation Yrotation
+ JOINT abdomen
+ {
+ OFFSET 0.000000 0.000000 0.000000
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT chest
+ {
+ OFFSET 0.000000 5.018152 -1.882228
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT neckDummy
+ {
+ OFFSET 0.000000 8.316447 0.784897
+ CHANNELS 3 Xrotation Yrotation Zrotation
+ JOINT neck
+ {
+ OFFSET 0.000000 2.280413 -0.392801
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT head
+ {
+ OFFSET 0.000000 3.496879 0.529469
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT figureHair
+ {
+ OFFSET 0.000000 4.699570 0.720622
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET 0.000000 -6.419331 0.000000
+ }
+ }
+ }
+ }
+ }
+ JOINT lCollar
+ {
+ OFFSET 0.599237 8.316447 0.784897
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT lShldr
+ {
+ OFFSET 6.421198 0.010146 -0.332128
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ JOINT lForeArm
+ {
+ OFFSET 10.552783 0.025574 0.125508
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT lHand
+ {
+ OFFSET 11.035963 0.319619 0.041520
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET 10.353753 0.000000 0.000000
+ }
+ }
+ }
+ }
+ }
+ JOINT rCollar
+ {
+ OFFSET -0.599237 8.316447 0.784897
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT rShldr
+ {
+ OFFSET -6.421198 0.010146 -0.332128
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ JOINT rForeArm
+ {
+ OFFSET -10.552783 0.025574 0.125508
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT rHand
+ {
+ OFFSET -11.035963 0.319619 0.041520
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET -10.353753 0.000000 0.000000
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ JOINT lThigh
+ {
+ OFFSET 4.500466 -6.400484 -1.832696
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT lShin
+ {
+ OFFSET -1.359117 -18.918689 1.179887
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT lFoot
+ {
+ OFFSET -0.652380 -17.215186 -0.312137
+ CHANNELS 3 Xrotation Yrotation Zrotation
+ End Site
+ {
+ OFFSET 0.000000 0.000000 10.353752
+ }
+ }
+ }
+ }
+ JOINT rThigh
+ {
+ OFFSET -4.500466 -6.400484 -1.832696
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT rShin
+ {
+ OFFSET 1.359117 -18.918689 1.179887
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT rFoot
+ {
+ OFFSET 0.652380 -17.215186 -0.312137
+ CHANNELS 3 Xrotation Yrotation Zrotation
+ End Site
+ {
+ OFFSET 0.000000 0.000000 10.353752
+ }
+ }
+ }
+ }
+}
+MOTION
+Frames: 30
+Frame Time: 0.055556
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -70.100700 9.978770 15.991600 -22.515600 -9.303740 0.147736 5.969490 -0.173112 0.175734 -2.021920 5.690310 -0.063351 70.100700 -9.978770 15.991600 22.458700 9.274270 0.122349 -5.969490 0.173112 0.175734 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -0.840470 -0.504482 -0.172233 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -66.714951 0.810504 15.136398 -33.059364 -0.471056 6.272503 -0.085772 9.730258 -0.696427 -2.021920 5.690310 -0.063351 68.610527 -1.751922 15.520359 32.760422 1.819201 -2.318790 -4.378768 -3.380067 -0.017181 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -1.992414 -1.191491 -0.406759 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -61.547604 -10.858863 13.523763 -46.199417 11.783067 16.405573 -3.629590 18.011200 -1.307420 -2.021920 5.690310 -0.063351 66.482704 8.622679 14.782897 45.543797 -8.842199 -6.691029 -5.481440 -5.567040 -0.304790 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -3.107702 -1.859236 -0.634722 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -56.850883 -22.681469 12.218906 -59.688835 23.561611 25.200680 3.307336 16.108097 -0.694552 -2.021920 5.690310 -0.063351 64.472473 19.194889 14.122459 58.702427 -18.905880 -10.324443 -14.858359 -1.951636 -0.729330 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -3.785351 -2.278148 -0.777805 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -55.558533 -32.531364 12.732746 -71.785385 30.280514 25.378662 16.408247 7.717693 0.635648 -2.021920 5.690310 -0.063351 63.504807 28.299826 13.993483 70.672028 -23.704298 -9.481764 -27.760672 4.845032 -1.100487 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -3.624380 -2.218660 -0.757690 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -60.604301 -38.282600 16.576200 -80.746803 27.355700 9.660360 28.074699 -0.262909 1.787490 -2.021920 5.690310 -0.063351 64.504700 34.272598 14.850400 79.888298 -18.569901 -0.425720 -36.631699 10.323200 -1.161880 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.406863 -1.546188 -0.528601 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -73.062302 -38.744316 24.247868 -85.340576 12.983446 -23.649031 32.840622 -2.565665 2.114388 -2.021920 5.690310 -0.063351 67.945839 36.064339 16.918980 85.267357 -1.755827 17.642315 -36.402676 11.160021 -0.777410 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -0.647106 -0.506089 -0.174925 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -86.568100 -36.465996 32.197067 -86.372940 -3.518627 -53.906895 33.769402 -0.438777 1.966177 -2.021920 5.690310 -0.063351 72.496849 35.090260 19.510347 87.646965 16.802063 33.766411 -31.956453 8.740308 -0.292083 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 0.957528 0.561300 0.186407 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -85.159790 -10.052569 -54.886265 36.056801 3.240490 1.941800 -2.021920 5.690310 -0.063351 76.375092 33.381584 21.706974 88.345306 24.247229 34.051987 -30.663799 5.625790 -0.171181 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 1.851923 1.378696 0.460220 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -83.148346 -0.539186 -15.996121 42.363014 5.932910 2.379979 -2.021920 5.690310 -0.063351 78.238228 32.552097 22.818314 88.503876 14.107533 13.276083 -36.643330 3.865294 -0.649059 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 2.049955 1.921054 0.638355 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.310997 7.025680 10.810800 45.206001 6.451450 2.578560 -2.021920 5.690310 -0.063351 78.505211 32.545792 23.061838 88.557701 5.448470 0.902143 -41.005100 3.456010 -1.036360 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 1.707748 2.226383 0.734403 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -83.855423 -2.884452 -17.438789 38.683754 4.672059 1.959642 -2.021920 5.690310 -0.063351 78.035278 32.889210 22.882013 88.740509 14.876419 20.468351 -35.923370 3.821422 -0.727013 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 0.981424 2.332698 0.761958 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -85.405380 -11.843541 -45.256367 33.356602 3.370450 1.483220 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 89.187500 23.623600 37.125320 -30.837900 4.141800 -0.371817 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 0.027108 2.278009 0.734614 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -84.548409 -2.152703 -18.789125 38.927315 4.828315 2.024116 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 89.664413 13.680943 18.548706 -35.170437 3.827948 -0.642340 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -0.999076 2.100329 0.665963 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.310997 7.025680 10.810800 45.206001 6.451450 2.578560 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 88.557701 5.448470 0.902143 -41.005100 3.456010 -1.036360 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -1.941007 1.837669 0.569598 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -80.412735 -3.097756 -9.119162 41.798904 5.629185 2.154696 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 85.081345 18.386852 19.422497 -39.662682 3.624926 -0.982284 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.642560 1.528040 0.459114 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -79.906303 -12.958900 -32.277901 37.389599 4.560890 1.686930 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 83.138756 29.790140 37.151352 -36.748402 3.859450 -0.804833 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.994490 1.212298 0.348815 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.139938 -3.116477 -10.757759 41.159752 5.543164 2.128106 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 85.855698 17.716618 17.918472 -38.700531 3.654023 -0.897978 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -3.075063 0.942666 0.255858 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.310997 7.025680 10.810800 45.206001 6.451450 2.578560 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 88.557701 5.448470 0.902143 -41.005100 3.456010 -1.036360 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -3.009421 0.774211 0.198110 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.831970 -2.023535 -12.634043 41.334332 5.161318 2.126635 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.775314 16.143488 24.086418 -38.749317 3.721606 -0.954981 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.922710 0.761999 0.193441 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.127098 -11.259400 -35.341900 37.273102 3.969990 1.665200 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 84.659447 27.238169 45.330318 -36.377300 3.989400 -0.849616 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.905299 0.932208 0.250285 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.693878 -1.702936 -11.916260 40.954811 5.149749 2.099351 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.504433 16.088291 23.410763 -38.495796 3.779540 -0.934428 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.908467 1.195462 0.339337 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.310997 7.025680 10.810800 45.206001 6.451450 2.578560 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 88.557701 5.448470 0.902143 -41.005100 3.456010 -1.036360 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.848719 1.433494 0.421860 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.697075 -4.312685 -13.537966 42.519302 5.572637 2.227027 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.903908 17.888819 20.590324 -39.569717 3.457184 -0.970542 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.642560 1.528040 0.459114 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.049301 -14.833800 -37.291901 39.157700 4.519030 1.823500 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 85.023682 29.842606 42.309601 -37.617500 3.675150 -0.892063 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -2.234550 1.395161 0.423478 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.608429 -4.023938 -13.131547 41.823509 5.402511 2.178931 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.578514 17.904167 24.240858 -38.938114 3.824486 -0.963367 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -1.687122 1.096336 0.334431 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.310997 7.025680 10.810800 45.206001 6.451450 2.578560 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 88.557701 5.448470 0.902143 -41.005100 3.456010 -1.036360 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -1.081482 0.716476 0.219064 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -82.021080 -2.775906 -13.411646 43.562275 5.791809 2.279532 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 87.718666 16.027189 9.582210 -40.867767 2.395170 -0.960393 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 -0.489078 0.326186 0.099811 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.617287 -12.913471 -37.551498 41.433800 5.023420 1.952340 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.563751 27.118025 22.315382 -40.194599 1.729710 -0.885129 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
+0.000000 42.014908 0.240040 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.021920 -5.690310 -0.063351 -92.897598 -34.932201 35.860802 -81.617287 -12.913471 -37.551498 41.433800 5.023420 1.952340 -2.021920 5.690310 -0.063351 77.687698 33.108898 22.723301 86.563751 27.118025 22.315382 -40.194599 1.729710 -0.885129 -7.548709 4.016634 0.126881 15.890360 -3.336124 -0.813312 -8.628910 1.044381 -0.888102 -7.530616 -4.334307 0.100752 15.830232 3.319340 0.622262 -8.660608 -1.559428 0.936809
Added: maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-laugh.bvh
===================================================================
--- maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-laugh.bvh (rev 0)
+++ maven/trunk/ogoglio-common/src/main/resources/avatar/avatar-laugh.bvh 2007-09-17 23:35:33 UTC (rev 411)
@@ -0,0 +1,169 @@
+HIERARCHY
+ROOT hip
+{
+ OFFSET 0.00 0.00 0.00
+ CHANNELS 6 Xposition Yposition Zposition Xrotation Zrotation Yrotation
+ JOINT abdomen
+ {
+ OFFSET 0.000000 0.000000 0.000000
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT chest
+ {
+ OFFSET 0.000000 5.018152 -1.882228
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT neckDummy
+ {
+ OFFSET 0.000000 8.316447 0.784897
+ CHANNELS 3 Xrotation Yrotation Zrotation
+ JOINT neck
+ {
+ OFFSET 0.000000 2.280413 -0.392801
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT head
+ {
+ OFFSET 0.000000 3.496879 0.529469
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT figureHair
+ {
+ OFFSET 0.000000 4.699570 0.720622
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET 0.000000 -6.419331 0.000000
+ }
+ }
+ }
+ }
+ }
+ JOINT lCollar
+ {
+ OFFSET 0.599237 8.316447 0.784897
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT lShldr
+ {
+ OFFSET 6.421198 0.010146 -0.332128
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ JOINT lForeArm
+ {
+ OFFSET 10.552783 0.025574 0.125508
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT lHand
+ {
+ OFFSET 11.035963 0.319619 0.041520
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET 10.353753 0.000000 0.000000
+ }
+ }
+ }
+ }
+ }
+ JOINT rCollar
+ {
+ OFFSET -0.599237 8.316447 0.784897
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT rShldr
+ {
+ OFFSET -6.421198 0.010146 -0.332128
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ JOINT rForeArm
+ {
+ OFFSET -10.552783 0.025574 0.125508
+ CHANNELS 3 Yrotation Zrotation Xrotation
+ JOINT rHand
+ {
+ OFFSET -11.035963 0.319619 0.041520
+ CHANNELS 3 Zrotation Yrotation Xrotation
+ End Site
+ {
+ OFFSET -10.353753 0.000000 0.000000
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ JOINT lThigh
+ {
+ OFFSET 4.500466 -6.400484 -1.832696
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT lShin
+ {
+ OFFSET -1.359117 -18.918689 1.179887
+ CHANNELS 3 Xrotation Zrotation Yrotation
+ JOINT lFoot
+ {
+ OFFSET -0.652380 -17.215186 -0.312137
+ ...
[truncated message content] |
|
From: <tre...@us...> - 2007-09-18 22:45:37
|
Revision: 424
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=424&view=rev
Author: trevorolio
Date: 2007-09-18 15:45:32 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
Now you can select your height from the body editor applet.
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Body.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
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/BodyDocument.java
Added Paths:
-----------
maven/trunk/ogoglio-common/src/main/resources/sourceArt/Icons/
maven/trunk/ogoglio-common/src/main/resources/sourceArt/Icons/GenderIcons.psd
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Body.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Body.java 2007-09-18 22:45:25 UTC (rev 423)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/client/model/Body.java 2007-09-18 22:45:32 UTC (rev 424)
@@ -19,7 +19,7 @@
private float height = 2;
private float girth = 1;
-
+
public Body(long bodyID, int hair, int eyes, int nose, int mouth, int face, boolean isMale, float height, float girth) {
this.bodyID = bodyID;
this.hair = hair;
@@ -28,8 +28,8 @@
this.mouth = mouth;
this.face = face;
this.male = isMale;
- this.height = height;
- this.girth = girth;
+ this.height = height;
+ this.girth = girth;
}
public long getBodyID() {
@@ -68,11 +68,15 @@
return male;
}
- public float getHeight(){
+ public float getHeight() {
return height;
}
-
- public float getGirth(){
+
+ public void setHeight(float height) {
+ this.height = height;
+ }
+
+ public float getGirth() {
return girth;
}
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-18 22:45:25 UTC (rev 423)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DUserRenderable.java 2007-09-18 22:45:32 UTC (rev 424)
@@ -109,6 +109,7 @@
scaleBVH(defaultAnimation);
skeleton = new SkeletonLoader(defaultAnimation).generateSkeleton();
+ //skeleton.addDebugAttachments();
if (isVisible) {
skin.setSkeleton(skeleton, skinMap);
}
@@ -137,7 +138,7 @@
float bvhHeight = bvh.getHeight();
if (bvhHeight != userHeight) {
skeletonScale = userHeight / bvhHeight / MAGIC_SKELETON_SCALE; //TODO figure out why we need this magic scale number
- bvh.scale(skeletonScale);
+ bvh.scale(skeletonScale, skeletonScale, skeletonScale);
}
}
@@ -277,4 +278,19 @@
e.printStackTrace();
}
}
+
+ public void setHeight(float newHeight) {
+ try {
+ initBody();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ObjParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SkinMapParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
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-18 22:45:25 UTC (rev 423)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/body/SkinLoader.java 2007-09-18 22:45:32 UTC (rev 424)
@@ -52,12 +52,30 @@
Point3f[] vertices = obj.getVertices();
float[] vertexArray = new float[vertices.length * 3];
+ float minY = Float.MAX_VALUE;
+ float maxY = Float.MIN_VALUE;
for (int i = 0; i < vertices.length; i++) {
vertexArray[i * 3] = vertices[i].x;
vertexArray[(i * 3) + 1] = vertices[i].y;
vertexArray[(i * 3) + 2] = vertices[i].z;
+
+ if(vertices[i].y < minY){
+ minY = vertices[i].y;
+ }
+ if(vertices[i].y > maxY){
+ maxY = vertices[i].y;
+ }
}
+ float heightScale = body.getHeight() / Math.abs(maxY - minY);
+ if(Math.abs(heightScale) > 0.1){
+ for (int i = 0; i < vertices.length; i++) {
+ vertexArray[i * 3] = vertexArray[i * 3] * heightScale;
+ vertexArray[(i * 3) + 1] = vertexArray[(i * 3) + 1] * heightScale;
+ vertexArray[(i * 3) + 2] = vertexArray[(i * 3) + 2] * heightScale;
+ }
+ }
+
Point3f[] texCoords = obj.getTextureVertices();
float[] textureCoordinateArray = new float[texCoords.length * 2];
for (int i = 0; i < texCoords.length; i++) {
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java 2007-09-18 22:45:25 UTC (rev 423)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/bvh/Bvh.java 2007-09-18 22:45:32 UTC (rev 424)
@@ -107,14 +107,14 @@
//TODO stop ignoring scale
}
- public void scaleFrameData(float amountToScale, Frame frame) {
+ public void scaleFrameData(float xScale, float yScale, float zScale, Frame frame) {
if (startIndex == -1) {
return;
}
if (channelIndices[0] != -1 && channelIndices[1] != -1 && channelIndices[2] != -1) {
- frame.data[startIndex + channelIndices[0]] = frame.data[startIndex + channelIndices[0]] * amountToScale;
- frame.data[startIndex + channelIndices[1]] = frame.data[startIndex + channelIndices[1]] * amountToScale;
- frame.data[startIndex + channelIndices[2]] = frame.data[startIndex + channelIndices[2]] * amountToScale;
+ frame.data[startIndex + channelIndices[0]] = frame.data[startIndex + channelIndices[0]] * xScale;
+ frame.data[startIndex + channelIndices[1]] = frame.data[startIndex + channelIndices[1]] * yScale;
+ frame.data[startIndex + channelIndices[2]] = frame.data[startIndex + channelIndices[2]] * zScale;
}
}
@@ -234,15 +234,15 @@
return maxY - minY;
}
- public void scale(float amountToScale) {
+ public void scale(float xScale, float yScale, float zScale) {
Vector joints = new Vector();
getJoints(getRootJoint(), joints);
for (int i = 0; i < joints.size(); i++) {
Joint joint = (Joint) joints.get(i);
Vector3f offset = joint.getOffset();
- joint.setOffset(offset.x * amountToScale, offset.y * amountToScale, offset.z * amountToScale);
+ joint.setOffset(offset.x * xScale, offset.y * yScale, offset.z * zScale);
for (int j = 0; j < getFrameCount(); j++) {
- joint.scaleFrameData(amountToScale, getFrame(j));
+ joint.scaleFrameData(xScale, yScale, zScale, getFrame(j));
}
}
}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/BodyDocument.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/BodyDocument.java 2007-09-18 22:45:25 UTC (rev 423)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/xml/BodyDocument.java 2007-09-18 22:45:32 UTC (rev 424)
@@ -144,18 +144,26 @@
data.setAttribute(FACE_INDEX, index);
}
- public boolean isMale(){
+ public boolean isMale() {
return data.getBooleanAttribute(IS_MALE);
}
-
- public float getHeight(){
+
+ public float getHeight() {
return data.getFloatAttribute(HEIGHT);
}
-
- public float getGirth(){
+
+ public void setHeight(float newHeight) {
+ data.setAttribute(HEIGHT, newHeight);
+ }
+
+ public float getGirth() {
return data.getFloatAttribute(GIRTH);
}
-
+
+ public void setGirth(float girth) {
+ data.setAttribute(GIRTH, girth);
+ }
+
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof BodyDocument)) {
return false;
@@ -166,4 +174,5 @@
public int hashCode() {
return ("BodyDocument-" + getBodyID()).hashCode();
}
+
}
\ No newline at end of file
Added: maven/trunk/ogoglio-common/src/main/resources/sourceArt/Icons/GenderIcons.psd
===================================================================
(Binary files differ)
Property changes on: maven/trunk/ogoglio-common/src/main/resources/sourceArt/Icons/GenderIcons.psd
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tre...@us...> - 2007-09-24 06:53:27
|
Revision: 433
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=433&view=rev
Author: trevorolio
Date: 2007-09-23 23:53:23 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
Added a data manager which holds all template geometry and appearance in a cache for reuse, and eventually for smarter memory management. Firefox really likes to crash the entire browser when its JVM stack is full so we're going to need to prevent that from happening. We can't just catch the OutOfMemoryExceptions because by then it has segfaulted. *sigh*
Modified Paths:
--------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderableLoader.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderer.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/BodyAnimator.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/obj/MtlParser.java
maven/trunk/ogoglio-common/src/main/resources/avatar/female.obj
maven/trunk/ogoglio-common/src/main/resources/avatar/female.smap
Added Paths:
-----------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataCache.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/J3DTemplateData.java
Added: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataCache.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataCache.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataCache.java 2007-09-24 06:53:23 UTC (rev 433)
@@ -0,0 +1,41 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+package com.ogoglio.viewer.j3d;
+
+import java.util.HashMap;
+
+public class J3DDataCache {
+
+ private HashMap templateDataMap = new HashMap(); //maps template guid to GeometryCacheEntry objects
+
+ public J3DTemplateData getTemplateData(long templateID, int lod) {
+ return (J3DTemplateData) templateDataMap.get(createGUID(templateID, lod));
+ }
+
+ public void putTemplateData(long templateID, int lod, J3DTemplateData entry) {
+ templateDataMap.put(createGUID(templateID, lod), entry);
+ }
+
+ private String createGUID(long id, int lod){
+ return id + "-" + lod;
+ }
+
+ private long getIDFromGUID(String guid){
+ return Long.parseLong(guid.split("-")[0]);
+ }
+
+ private long getLODFromGUID(String guid){
+ return Long.parseLong(guid.split("-")[1]);
+ }
+}
Added: 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 (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DDataManager.java 2007-09-24 06:53:23 UTC (rev 433)
@@ -0,0 +1,315 @@
+package com.ogoglio.viewer.j3d;
+
+import java.awt.Image;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Vector;
+
+import javax.imageio.ImageIO;
+import javax.media.j3d.Appearance;
+import javax.media.j3d.Geometry;
+import javax.media.j3d.GeometryArray;
+import javax.media.j3d.ImageComponent;
+import javax.media.j3d.Material;
+import javax.media.j3d.RenderingAttributes;
+import javax.media.j3d.Texture;
+import javax.media.j3d.TextureAttributes;
+import javax.media.j3d.TransparencyAttributes;
+import javax.vecmath.Color3f;
+import javax.vecmath.Point3f;
+import javax.vecmath.TexCoord2f;
+
+import com.ogoglio.client.model.GeometryProvider;
+import com.ogoglio.util.Log;
+import com.ogoglio.viewer.j3d.obj.Obj;
+import com.ogoglio.viewer.j3d.obj.ObjMtl;
+import com.ogoglio.viewer.j3d.obj.ObjParseException;
+import com.ogoglio.viewer.j3d.obj.ObjParser;
+import com.sun.j3d.utils.geometry.GeometryInfo;
+import com.sun.j3d.utils.geometry.NormalGenerator;
+import com.sun.j3d.utils.geometry.Stripifier;
+import com.sun.j3d.utils.image.TextureLoader;
+
+public class J3DDataManager {
+
+ public static Appearance DEFAULT_APPEARANCE = new Appearance();
+
+ private static Material DEFAULT_MATERIAL = new Material();
+ static {
+ DEFAULT_MATERIAL.setAmbientColor(new Color3f(1, 1, 1));
+ DEFAULT_MATERIAL.setDiffuseColor(new Color3f(0.1f, 0.1f, 0.1f));
+ DEFAULT_MATERIAL.setSpecularColor(new Color3f(1, 1, 1));
+ DEFAULT_MATERIAL.setShininess(1);
+ DEFAULT_MATERIAL.setLightingEnable(true);
+
+ DEFAULT_APPEARANCE.setMaterial(DEFAULT_MATERIAL);
+ }
+
+ private GeometryProvider errorGeometryProvider = null;
+
+ private J3DDataCache dataCache = new J3DDataCache();
+
+ private boolean loadAppearances = true;
+
+ public J3DDataManager(boolean loadAppearances) {
+ this.loadAppearances = loadAppearances;
+ }
+
+ public J3DTemplateData[] getTemplateData(long templateID, GeometryProvider geoProvider, boolean useCache) {
+ J3DTemplateData[] results = new J3DTemplateData[GeometryProvider.LOD_DISTANCES.length + 1];
+ if (useCache) {
+ boolean hitCache = false;
+ for (int i = 0; i < results.length; i++) {
+ results[i] = dataCache.getTemplateData(templateID, i);
+ hitCache = hitCache || results[i] != null;
+ }
+ if (hitCache) {
+ return results;
+ }
+ }
+
+ fetchTemplateData(templateID, geoProvider, results);
+ for (int i = 0; i < results.length; i++) {
+ if (results[i] == null) {
+ continue;
+ }
+ dataCache.putTemplateData(templateID, i, results[i]);
+ }
+
+ return results;
+ }
+
+ private void fetchTemplateData(long templateID, GeometryProvider geoProvider, J3DTemplateData[] results) {
+ Obj[] objs = getObjs(geoProvider, templateID);
+
+ HashMap textures = new HashMap();
+ for (int i = 0; i < objs.length; i++) {
+ if (objs[i] == null) {
+ continue;
+ }
+ results[i] = new J3DTemplateData();
+
+ Obj.Group[] groups = objs[i].getGroups();
+ for (int g = 0; g < groups.length; g++) {
+ Geometry geometry = generateGeometry(geoProvider, groups[g]);
+ results[i].putGeometry(groups[g].getName(), geometry);
+ Appearance appearance = generateAppearance(geoProvider, groups[g], textures);
+ results[i].putAppearances(groups[g].getName(), appearance);
+ }
+ }
+ textures.clear();
+ }
+
+ private Geometry generateGeometry(GeometryProvider geoProvider, Obj.Group group) {
+ //TODO consider a more memory efficient way to load shapes
+ Obj.Range[] ranges = group.getRanges();
+ if (ranges.length == 0) {
+ Log.error("Zero range group: " + group.getName());
+ return null;
+ }
+
+ Vector textureVertices = new Vector();
+ Vector vertices = new Vector();
+ Vector stripCounts = new Vector();
+ for (int i = 0; i < ranges.length; i++) { //for each range
+ for (int j = ranges[i].getLower(); j <= ranges[i].getUpper(); j++) { //for each face in range
+ stripCounts.add(new Integer(addFaceVertices(group.getObj(), j, vertices, textureVertices)));
+ }
+ }
+
+ if (vertices.size() == 0) {
+ Log.error("Empty group: " + group.getName());
+ return null;
+ }
+
+ Point3f[] vertexPoints = (Point3f[]) vertices.toArray(new Point3f[0]);
+ int[] stripCountInts = new int[stripCounts.size()];
+ int total = 0;
+ for (int i = 0; i < stripCounts.size(); i++) {
+ stripCountInts[i] = ((Integer) stripCounts.get(i)).intValue();
+ total += stripCountInts[i];
+ }
+
+ int[] coordinateIndices = new int[vertexPoints.length];
+ for (int i = 0; i < coordinateIndices.length; i++) {
+ coordinateIndices[i] = i;
+ }
+
+ GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
+ gi.setStripCounts(stripCountInts);
+ gi.setCoordinates(vertexPoints);
+ gi.setCoordinateIndices(coordinateIndices);
+
+ TexCoord2f[] texCoords = new TexCoord2f[vertexPoints.length];
+ int[] texCoordIndices = new int[vertexPoints.length];
+ for (int i = 0; i < texCoordIndices.length; i++) {
+ texCoordIndices[i] = i;
+ }
+
+ Point3f textVertex = null;
+ for (int i = 0; i < texCoords.length; i++) {
+ textVertex = (Point3f) textureVertices.get(i);
+ texCoords[i] = new TexCoord2f(textVertex.x, textVertex.y);
+ }
+
+ gi.setTextureCoordinateParams(1, 2); //one set with two dimensions
+ gi.setTextureCoordinateIndices(0, texCoordIndices);
+ gi.setTextureCoordinates(0, texCoords);
+
+ new NormalGenerator(-1.0f).generateNormals(gi);
+ new Stripifier().stripify(gi);
+ GeometryArray geometryArray = gi.getGeometryArray(false, false, false);
+ geometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
+ geometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);
+ geometryArray.setCapability(GeometryArray.ALLOW_FORMAT_READ);
+ geometryArray.setCapability(GeometryArray.ALLOW_INTERSECT);
+
+ return geometryArray;
+ }
+
+ private int addFaceVertices(Obj obj, int faceIndex, Vector vertices, Vector textureCoordinates) {
+ int[][] faceIndices = obj.getFaceIndices(faceIndex);
+ for (int i = 0; i < faceIndices.length; i++) {
+ vertices.add(obj.getVertex(faceIndices[i][0]));
+ if (faceIndices[i].length > 1 && faceIndices[i][1] != -1) {
+ textureCoordinates.add(obj.getTextureVertex(faceIndices[i][1]));
+ } else {
+ textureCoordinates.add(new Point3f());
+ }
+ }
+ return faceIndices.length;
+ }
+
+ private Appearance generateAppearance(GeometryProvider geoProvider, Obj.Group group, HashMap textures) {
+ Obj.Range[] ranges = group.getRanges();
+ ObjMtl.Material material = group.getObj().getMaterialForFace(ranges[0].getLower());
+ if (material == null) {
+ return DEFAULT_APPEARANCE;
+ }
+
+ Appearance appearance = new Appearance();
+ appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
+ Material j3dMaterial = new Material();
+ appearance.setMaterial(j3dMaterial);
+
+ Color3f ambientColor = new Color3f();
+ material.getAmbientColor(ambientColor);
+ j3dMaterial.setAmbientColor(ambientColor);
+
+ Color3f diffuseColor = new Color3f();
+ material.getDiffuseColor(diffuseColor);
+ j3dMaterial.setDiffuseColor(diffuseColor);
+
+ Color3f specularColor = new Color3f();
+ material.getSpecularColor(specularColor);
+ j3dMaterial.setSpecularColor(specularColor);
+
+ if (material.getDissolve() != 1) {
+ TransparencyAttributes tAttribs = new TransparencyAttributes(TransparencyAttributes.BLENDED, material.getDissolve());
+ appearance.setTransparencyAttributes(tAttribs);
+ }
+
+ if (material.getSpecularExponent() != -1) {
+ //TODO figure out why shininess appears to have no effect
+ }
+
+ if (material.getDiffuseMapName() != null) { //Woot, texture!
+ try {
+ Texture texImage = (Texture) textures.get(material.getDiffuseMapName());
+
+ if (texImage == null) {
+ InputStream imageStream = geoProvider.getSubGeometryStream(material.getDiffuseMapName());
+ if (imageStream != null) {
+ Image image = ImageIO.read(new BufferedInputStream(imageStream));
+ if (image != null) {
+ //I don't really care for any of these formats
+ // LUMINANCE is nice for a film noir effect
+ if (material.getDiffuseMapName().startsWith("transparent_")) {
+ texImage = new TextureLoader(image, "RGBA", null).getTexture();
+ } else {
+ texImage = new TextureLoader(image, "RGB", null).getTexture();
+ }
+ textures.put(material.getDiffuseMapName(), texImage);
+ }
+ imageStream.close();
+ }
+ }
+ if (texImage != null) {
+ texImage.getImage(0).setCapability(ImageComponent.ALLOW_SIZE_READ);
+ texImage.getImage(0).setCapability(ImageComponent.ALLOW_IMAGE_READ);
+ texImage.getImage(0).setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
+ appearance.setTexture(texImage);
+
+ TextureAttributes textureAttributes = new TextureAttributes();
+ textureAttributes.setTextureMode(TextureAttributes.MODULATE);
+ appearance.setTextureAttributes(textureAttributes);
+
+ // this is a hack so that only textures named transparent_* get these attributes set
+ // otherwise we get all kinds of bad ordering problems
+ //TODO figure out what the right thing is for transparent texture attributes
+ if (material.getDiffuseMapName().startsWith("transparent_")) {
+ TextureAttributes textureAtts = new TextureAttributes();
+ textureAtts.setTextureMode(TextureAttributes.REPLACE);
+ appearance.setTextureAttributes(textureAtts);
+
+ TransparencyAttributes tAttribs = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0, TransparencyAttributes.BLEND_SRC_ALPHA, TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);
+ appearance.setTransparencyAttributes(tAttribs);
+ appearance.setRenderingAttributes(new RenderingAttributes());
+ }
+
+ }
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ return appearance;
+ }
+
+ private Obj[] getObjs(GeometryProvider geoProvider, long templateID) {
+ boolean gotObj = false;
+ Obj[] objs = new Obj[GeometryProvider.LOD_DISTANCES.length + 1];
+ try {
+ for (int i = 0; i < objs.length; i++) {
+ objs[i] = getObj(geoProvider, i);
+ if (objs[i] != null && objs[i].getGroups().length == 0) {
+ Log.error("Got obj with no groups for template " + templateID);
+ objs[i] = null;
+ }
+ if (!gotObj && objs[i] != null) {
+ gotObj = true;
+ }
+ }
+ } catch (ObjParseException e) {
+ Log.error("Error parsing obj: " + e);
+ }
+ if (!gotObj) {
+ try {
+ objs[0] = getObj(errorGeometryProvider, 0);
+ } catch (ObjParseException e) {
+ throw new IllegalStateException("Error parsing the error template?!?");
+ }
+
+ }
+ if (objs[0] == null) {
+ throw new IllegalStateException("Where's my error template?");
+ }
+ return objs;
+ }
+
+ private Obj getObj(GeometryProvider provider, int lodIndex) throws ObjParseException {
+ if (lodIndex != 0) {
+ return null;
+ }
+ try {
+ ObjParser parser = new ObjParser(provider, lodIndex);
+ return parser.parse();
+ } catch (Exception e) {
+ System.err.println("Could not load obj: " + e);
+ return null;
+ }
+ }
+
+}
Modified: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderableLoader.java
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderableLoader.java 2007-09-23 00:32:43 UTC (rev 432)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/viewer/j3d/J3DRenderableLoader.java 2007-09-24 06:53:23 UTC (rev 433)
@@ -14,289 +14,88 @@
package com.ogoglio.viewer.j3d;
-import java.awt.Image;
-import java.io.BufferedInputStream;
-import java.io.InputStream;
import java.util.HashMap;
import java.util.Vector;
-import javax.imageio.ImageIO;
import javax.media.j3d.Appearance;
-import javax.media.j3d.GeometryArray;
-import javax.media.j3d.ImageComponent;
-import javax.media.j3d.Material;
-import javax.media.j3d.RenderingAttributes;
+import javax.media.j3d.Geometry;
import javax.media.j3d.Shape3D;
-import javax.media.j3d.Texture;
-import javax.media.j3d.TextureAttributes;
-import javax.media.j3d.TransparencyAttributes;
-import javax.vecmath.Color3f;
-import javax.vecmath.Point3f;
-import javax.vecmath.TexCoord2f;
import com.ogoglio.client.model.Door;
import com.ogoglio.client.model.GeometryProvider;
import com.ogoglio.client.model.Shape;
import com.ogoglio.client.model.Thing;
-import com.ogoglio.util.Log;
-import com.ogoglio.viewer.j3d.obj.Obj;
-import com.ogoglio.viewer.j3d.obj.ObjMtl;
+import com.ogoglio.util.ArgumentUtils;
import com.ogoglio.viewer.render.Renderable;
-import com.sun.j3d.utils.geometry.GeometryInfo;
-import com.sun.j3d.utils.geometry.NormalGenerator;
-import com.sun.j3d.utils.image.TextureLoader;
public class J3DRenderableLoader {
- public static Appearance DEFAULT_APPEARANCE = new Appearance();
+ private J3DTemplateData[] templateData = null;
- private static Material DEFAULT_MATERIAL = new Material();
- static {
- DEFAULT_MATERIAL.setAmbientColor(new Color3f(1, 1, 1));
- DEFAULT_MATERIAL.setDiffuseColor(new Color3f(0.1f, 0.1f, 0.1f));
- DEFAULT_MATERIAL.setSpecularColor(new Color3f(1, 1, 1));
- DEFAULT_MATERIAL.setShininess(1);
- DEFAULT_MATERIAL.setLightingEnable(true);
-
- DEFAULT_APPEARANCE.setMaterial(DEFAULT_MATERIAL);
+ public J3DRenderableLoader(J3DTemplateData[] templateData) {
+ this.templateData = templateData;
}
- private Obj[] objs = null;
-
- private HashMap textures = new HashMap();
-
- boolean loadMaterials = true;
-
- public J3DRenderableLoader(Obj[] objs, boolean loadMaterials) {
- this.objs = objs;
- this.loadMaterials = loadMaterials;
- }
-
- private J3DShapeRenderable generateShape(GeometryProvider geoProvider, Renderable renderable, Obj.Group group) {
- //TODO consider a more memory efficient way to load shapes
- Obj.Range[] ranges = group.getRanges();
- if (ranges.length == 0) {
- Log.error("Zero range group: " + group.getName());
- return null;
- }
-
- Vector textureVertices = new Vector();
- Vector vertices = new Vector();
- Vector stripCounts = new Vector();
- for (int i = 0; i < ranges.length; i++) { //for each range
- for (int j = ranges[i].getLower(); j <= ranges[i].getUpper(); j++) { //for each face in range
- stripCounts.add(new Integer(addFaceVertices(group.getObj(), j, vertices, textureVertices)));
- }
- }
-
- if (vertices.size() == 0) {
- Log.error("Empty group: " + group.getName());
- return null;
- }
-
- Point3f[] vertexPoints = (Point3f[]) vertices.toArray(new Point3f[0]);
- int[] stripCountInts = new int[stripCounts.size()];
- int total = 0;
- for (int i = 0; i < stripCounts.size(); i++) {
- stripCountInts[i] = ((Integer) stripCounts.get(i)).intValue();
- total += stripCountInts[i];
- }
-
- int[] coordinateIndices = new int[vertexPoints.length];
- for (int i = 0; i < coordinateIndices.length; i++) {
- coordinateIndices[i] = i;
- }
-
- GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
- gi.setStripCounts(stripCountInts);
- gi.setCoordinates(vertexPoints);
- gi.setCoordinateIndices(coordinateIndices);
-
- TexCoord2f[] texCoords = new TexCoord2f[vertexPoints.length];
- int[] texCoordIndices = new int[vertexPoints.length];
- for (int i = 0; i < texCoordIndices.length; i++) {
- texCoordIndices[i] = i;
- }
-
- Point3f textVertex = null;
- for (int i = 0; i < texCoords.length; i++) {
- textVertex = (Point3f) textureVertices.get(i);
- texCoords[i] = new TexCoord2f(textVertex.x, textVertex.y);
- }
-
- gi.setTextureCoordinateParams(1, 2); //one set with two dimensions
- gi.setTextureCoordinateIndices(0, texCoordIndices);
- gi.setTextureCoordinates(0, texCoords);
-
- new NormalGenerator(-1.0f).generateNormals(gi);
- GeometryArray geometryArray = gi.getGeometryArray(false, false, false);
- geometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
- geometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);
- geometryArray.setCapability(GeometryArray.ALLOW_FORMAT_READ);
- geometryArray.setCapability(GeometryArray.ALLOW_INTERSECT);
-
- Shape shape = null;
- if (renderable instanceof J3DThingRenderable) {
- Thing thing = ((J3DThingRenderable) renderable).getThing();
- shape = thing.getShape(group.getName());
- if (shape == null) {
- shape = new Shape(thing, group.getName());
- ((J3DThingRenderable) renderable).getThing().addShape(shape);
- }
- }
-
- J3DShapeRenderable shapeRenderable = new J3DShapeRenderable(renderable, shape);
- shapeRenderable.getInnerShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
- shapeRenderable.getInnerShape().setCapability(Shape3D.ALLOW_GEOMETRY_READ);
- shapeRenderable.getInnerShape().setCapability(Shape3D.ALLOW_PICKABLE_READ);
- shapeRenderable.getInnerShape().addGeometry(geometryArray);
-
- ObjMtl.Material objMat = group.getObj().getMaterialForFace(ranges[0].getLower());
- if (loadMaterials && objMat != null) {
- shapeRenderable.getInnerShape().setAppearance(getAppearance(geoProvider, objMat));
- } else {
- shapeRenderable.getInnerShape().setAppearance(DEFAULT_APPEARANCE);
- }
- shapeRenderable.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
- shapeRenderable.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
- return shapeRenderable;
- }
-
- private Appearance getAppearance(GeometryProvider geoProvider, ObjMtl.Material material) {
-
- Appearance appearance = new Appearance();
- appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
- Material j3dMaterial = new Material();
- appearance.setMaterial(j3dMaterial);
-
- Color3f ambientColor = new Color3f();
- material.getAmbientColor(ambientColor);
- j3dMaterial.setAmbientColor(ambientColor);
-
- Color3f diffuseColor = new Color3f();
- material.getDiffuseColor(diffuseColor);
- j3dMaterial.setDiffuseColor(diffuseColor);
-
- Color3f specularColor = new Color3f();
- material.getSpecularColor(specularColor);
- j3dMaterial.setSpecularColor(specularColor);
-
- if (material.getDissolve() != 1) {
- TransparencyAttributes tAttribs = new TransparencyAttributes(TransparencyAttributes.BLENDED, material.getDissolve());
- appearance.setTransparencyAttributes(tAttribs);
- }
-
- if (material.getSpecularExponent() != -1) {
- //TODO figure out why shininess appears to have no effect
- }
-
- if (material.getDiffuseMapName() != null) { //Woot, texture!
- try {
- Texture texImage = (Texture) textures.get(material.getDiffuseMapName());
- if (texImage == null) {
- InputStream imageStream = geoProvider.getSubGeometryStream(material.getDiffuseMapName());
- if (imageStream != null) {
- Image image = ImageIO.read(new BufferedInputStream(imageStream));
- if (image != null) {
- //I don't really care for any of these formats
- // LUMINANCE is nice for a film noir effect
- if (material.getDiffuseMapName().startsWith("transparent_")) {
- texImage = new TextureLoader(image, "RGBA", null).getTexture();
- } else {
- texImage = new TextureLoader(image, "RGB", null).getTexture();
- }
- textures.put(material.getDiffuseMapName(), texImage);
- }
- imageStream.close();
- }
- }
- if (texImage != null) {
- texImage.getImage(0).setCapability(ImageComponent.ALLOW_SIZE_READ);
- texImage.getImage(0).setCapability(ImageComponent.ALLOW_IMAGE_READ);
- texImage.getImage(0).setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
- appearance.setTexture(texImage);
- // this is a hack so that only textures named transparent_* get these attributes set
- // otherwise we get all kinds of bad ordering problems
- //TODO figure out what the right thing is for transparent texture attributes
- if (material.getDiffuseMapName().startsWith("transparent_")) {
- TextureAttributes textureAtts = new TextureAttributes();
- textureAtts.setTextureMode(TextureAttributes.REPLACE);
- appearance.setTextureAttributes(textureAtts);
-
- TransparencyAttributes tAttribs = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0, TransparencyAttributes.BLEND_SRC_ALPHA, TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);
- appearance.setTransparencyAttributes(tAttribs);
- appearance.setRenderingAttributes(new RenderingAttributes());
- }
-
- }
-
- } catch (Throwable e) {
- e.printStackTrace();
- }
- }
-
- return appearance;
- }
-
- private int addFaceVertices(Obj obj, int faceIndex, Vector vertices, Vector textureCoordinates) {
- int[][] faceIndices = obj.getFaceIndices(faceIndex);
- for (int i = 0; i < faceIndices.length; i++) {
- vertices.add(obj.getVertex(faceIndices[i][0]));
- if (faceIndices[i].length > 1 && faceIndices[i][1] != -1) {
- textureCoordinates.add(obj.getTextureVertex(faceIndices[i][1]));
- } else {
- textureCoordinates.add(new Point3f());
- }
- }
- return faceIndices.length;
- }
-
public J3DThingRenderable loadThing(Thing thing) {
J3DThingRenderable renderable = new J3DThingRenderable(thing);
Vector lodDistances = new Vector();
Vector lodGroups = new Vector();
-
- for (int i = 0; i < objs.length; i++) {
- if (objs[i] == null) {
+ for (int i = 0; i < templateData.length; i++) {
+ if (templateData[i] == null) {
continue;
}
HashMap shapeGroup = new HashMap();
- Obj.Group[] groups = objs[i].getGroups();
- for (int g = 0; g < groups.length; g++) {
- J3DShapeRenderable shape = generateShape(thing, renderable, groups[g]);
- if (shape != null) {
- shapeGroup.put(shape.getName(), shape);
+ String[] shapeNames = templateData[i].getShapeNames();
+ for (int g = 0; g < shapeNames.length; g++) {
+ Shape shape = thing.getShape(shapeNames[g]);
+ if (shape == null) {
+ shape = new Shape(thing, shapeNames[g]);
+ thing.addShape(shape);
}
+ Geometry geometry = templateData[i].getGeometry(shapeNames[g]);
+ Appearance appearance = templateData[i].getAppearance(shapeNames[g]);
+ J3DShapeRenderable shapeRenderable = generateShapeRenderable(renderable, shape, geometry, appearance);
+ shapeGroup.put(shape.getName(), shapeRenderable);
}
- if (shapeGroup.size() > 0) {
- if (lodGroups.size() > 0) { //there is one less distance than shapeGroup
- lodDistances.add(new Float(GeometryProvider.LOD_DISTANCES[i - 1]));
- }
- lodGroups.add(shapeGroup);
+ if (lodGroups.size() > 0) { //there is one less distance than shapeGroup
+ lodDistances.add(new Float(GeometryProvider.LOD_DISTANCES[i - 1]));
}
+ lodGroups.add(shapeGroup);
}
float[] distances = new float[lodDistances.size()];
for (int i = 0; i < distances.length; i++) {
distances[i] = ((Float) lodDistances.elementAt(i)).floatValue();
}
rend...
[truncated message content] |