|
From: <tre...@us...> - 2007-09-18 16:02:48
|
Revision: 415
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=415&view=rev
Author: trevorolio
Date: 2007-09-18 09:02:42 -0700 (Tue, 18 Sep 2007)
Log Message:
-----------
Added the ability to choose a male or female avatar.
Both avatar models still need work.
Consolidated the two UIConstants classes into one.
Modified Paths:
--------------
maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java
Modified: maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java
===================================================================
--- maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-09-18 15:05:26 UTC (rev 414)
+++ maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-09-18 16:02:42 UTC (rev 415)
@@ -26,6 +26,8 @@
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Panel;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
@@ -43,8 +45,11 @@
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
+import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
+import javax.swing.JButton;
import javax.swing.JLabel;
+import javax.swing.JRadioButton;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
@@ -58,12 +63,14 @@
import com.ogoglio.client.model.User;
import com.ogoglio.client.model.Space.Context;
import com.ogoglio.util.BodyConstants;
+import com.ogoglio.util.UIConstants;
import com.ogoglio.viewer.j3d.J3DCamera;
import com.ogoglio.viewer.j3d.J3DCanvas;
import com.ogoglio.viewer.j3d.J3DUniverse;
import com.ogoglio.viewer.j3d.J3DUserRenderable;
+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.render.UIConstants;
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.BodyDocument;
@@ -105,9 +112,12 @@
private WebAPIClient webClient;
+ private boolean completedInitialLoad = false;
+
public BodyEditorApplet() {
setBackground(Color.WHITE);
setLayout(new BorderLayout());
+ setSize(new Dimension(500, 500));
}
private class SpacelessUser extends User {
@@ -119,15 +129,23 @@
private class SpacelessContext implements Context {
public InputStream getUserGeometryStream(String username, String name) throws IOException {
- return UIConstants.getResource("avatar/avatar.obj");
+ if (user.getBody().isMale()) {
+ return UIConstants.getResource(BodyConstants.MALE_AVATAR_PATH);
+ } else {
+ return UIConstants.getResource(BodyConstants.FEMALE_AVATAR_PATH);
+ }
}
public InputStream getUserAnimationStream(String username, long animationID) throws IOException {
- return UIConstants.getUserAnimation((int) animationID);
+ return BodyConstants.getUserAnimation((int) animationID);
}
public InputStream getUserSkinMapStream(String username) throws IOException {
- return UIConstants.getResource("avatar/avatar.smap");
+ if (user.getBody().isMale()) {
+ return UIConstants.getResource(BodyConstants.MALE_SMAP_PATH);
+ } else {
+ return UIConstants.getResource(BodyConstants.FEMALE_SMAP_PATH);
+ }
}
public InputStream getPageContentStream(long thingID, long pageID) {
@@ -232,7 +250,7 @@
canvas.getView().setSceneAntialiasingEnable(true);
camera.setRotation(-0.5, Math.PI, 0);
- camera.setLocation(new Vector3f(0f, 0.8f, -1.9f));
+ camera.setLocation(new Vector3f(0f, 1.8f, -1.2f));
sceneRoot.addChild(camera.getNode());
universe.makeLive();
@@ -252,10 +270,10 @@
ScrollingRowPanel faceRow = new ScrollingRowPanel(true, faceRowModel);
+ HeightPanel heightPanel = new HeightPanel();
+
GenderPanel genderPanel = new GenderPanel();
- HeightPanel heightPanel = new HeightPanel();
-
public WestPanel() {
setPreferredSize(dimension);
setMinimumSize(dimension);
@@ -267,20 +285,62 @@
add(noseRow);
add(mouseRow);
add(faceRow);
- //add(genderPanel);
+ add(genderPanel);
//add(heightPanel);
}
}
- private class GenderPanel extends Panel {
- Dimension dimension = new Dimension(80, 35);
+ private BodyDocument bodyToDoc(Body body) {
+ return new BodyDocument(body.getBodyID(), user.getUsername(), "Body", body.getHair(), body.getEyes(), body.getNose(), body.getMouth(), body.getFace(), body.isMale(), body.getHeight(), body.getGirth());
+ }
+ private void changeGender() {
+ Body body = user.getBody();
+ body.setMale(westPanel.genderPanel.maleButton.isSelected());
+ BodyDocument bodyDoc = bodyToDoc(body);
+ bodyPanel.renderable.setMale(body.isMale());
+ try {
+ webClient.updateBody(bodyDoc);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private class GenderPanel extends Panel implements ActionListener {
+ Dimension dimension = new Dimension(80, 55);
+
+ JRadioButton maleButton = new JRadioButton("male");
+
+ JRadioButton femaleButton = new JRadioButton("female");
+
public GenderPanel() {
setPreferredSize(dimension);
setMinimumSize(dimension);
- setBackground(Color.GRAY);
+ ButtonGroup group = new ButtonGroup();
+
+ group.add(maleButton);
+ maleButton.setBackground(Color.WHITE);
+ maleButton.setSelected(user.getBody().isMale());
+ add(maleButton);
+ maleButton.addActionListener(this);
+
+ group.add(femaleButton);
+ femaleButton.setBackground(Color.WHITE);
+ femaleButton.setSelected(!user.getBody().isMale());
+ add(femaleButton);
+ femaleButton.addActionListener(this);
+
+ setBackground(Color.WHITE);
}
+
+ public void actionPerformed(ActionEvent event) {
+ if (user.getBody().isMale() == maleButton.isSelected()) {
+ return;
+ }
+ changeGender();
+ }
}
private class TexturePanel extends Panel {
@@ -316,6 +376,51 @@
}
}
+ private class AnimationPanel extends Panel implements ActionListener {
+ Dimension dimension = new Dimension(150, 170);
+
+ JButton[] animationButtons = null;
+
+ AnimationPanel(){
+ setPreferredSize(dimension);
+ setMinimumSize(dimension);
+ setBackground(Color.WHITE);
+ animationButtons = new JButton[BodyConstants.USER_ANIMATION_COMMANDS.length];
+ for (int i = 0; i < BodyConstants.USER_ANIMATION_COMMANDS.length; i++) {
+ animationButtons[i] = new JButton(BodyConstants.USER_ANIMATION_COMMANDS[i]);
+ animationButtons[i].setBackground(Color.WHITE);
+ animationButtons[i].addActionListener(this);
+ add(animationButtons[i]);
+ }
+
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ for (int i = 0; i < animationButtons.length; i++) {
+ if(event.getSource() == animationButtons[i]){
+ playAnimation(animationButtons[i].getText());
+ break;
+ }
+ }
+ }
+ }
+
+ private void playAnimation(String command){
+ for (int i = 0; i < BodyConstants.USER_ANIMATION_COMMANDS.length; i++) {
+ if(BodyConstants.USER_ANIMATION_COMMANDS[i].equals(command)){
+ try {
+ Bvh bvh = new BvhParser(user, i).parse();
+ bodyPanel.renderable.playAnimation(bvh, false);
+ } catch (BvhParseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ break;
+ }
+ }
+ }
+
private class EastPanel extends Panel {
Dimension dimension = new Dimension(150, 300);
@@ -333,6 +438,8 @@
WidthPanel widthPanel = new WidthPanel();
+ AnimationPanel animationPanel = new AnimationPanel();
+
public EastPanel() {
setPreferredSize(dimension);
setMinimumSize(dimension);
@@ -344,7 +451,8 @@
add(noseRow);
add(mouthRow);
add(faceRow);
-
+
+ add(animationPanel);
//add(texturePanel);
//add(widthPanel);
}
@@ -569,8 +677,11 @@
eyesRowModel = new RowModel(bodyDoc.getEyesIndex(), BodyConstants.EYES);
noseRowModel = new RowModel(bodyDoc.getNoseIndex(), BodyConstants.NOSES);
mouthRowModel = new RowModel(bodyDoc.getMouthIndex(), BodyConstants.MOUTHES);
- faceRowModel = new RowModel(bodyDoc.getFaceIndex(), BodyConstants.BASE_SKIN_TEXTURES);
-
+ if (user.getBody().isMale()) {
+ faceRowModel = new RowModel(bodyDoc.getFaceIndex(), BodyConstants.MALE_BASE_SKIN_TEXTURES);
+ } else {
+ faceRowModel = new RowModel(bodyDoc.getFaceIndex(), BodyConstants.FEMALE_BASE_SKIN_TEXTURES);
+ }
add(bodyPanel, BorderLayout.CENTER);
westPanel = new WestPanel();
add(westPanel, BorderLayout.WEST);
@@ -592,6 +703,7 @@
new Thread() {
public void run() {
bodyPanel.addUserRenderable();
+ completedInitialLoad = true;
}
}.start();
}
@@ -625,5 +737,9 @@
configTemplate.setDoubleBuffer(GraphicsConfigTemplate.REQUIRED);
return device.getBestConfiguration(configTemplate);
}
+
+ public boolean completedInitialLoad() {
+ return completedInitialLoad ;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|