|
From: <tre...@us...> - 2007-09-27 18:06:50
|
Revision: 449
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=449&view=rev
Author: trevorolio
Date: 2007-09-27 11:06:53 -0700 (Thu, 27 Sep 2007)
Log Message:
-----------
Halfway through a grand avatar rewhack.
In this half I switch over to using downloadable wadges of avatar data instead of in-jar resources for avatar data.
Removed the GeomtryProvider interface, which is now replaced by TemplateDataProvider and BodyDataProvider interfaces which are used to fill the J3DDataManager with cached versions of all network accessed resources. This allows us to control memory usage, but also (eventually) reduces our memory footprint as we only make copies of data which is avatar specific.
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-27 18:06:51 UTC (rev 448)
+++ maven/trunk/ogoglio-body-editor-applet/src/main/java/com/ogoglio/bodyeditor/BodyEditorApplet.java 2007-09-27 18:06:53 UTC (rev 449)
@@ -16,25 +16,18 @@
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Color;
-import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
-import java.awt.Graphics;
import java.awt.GraphicsConfigTemplate;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
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;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Vector;
+import java.util.zip.ZipInputStream;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Background;
@@ -45,12 +38,8 @@
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.JPanel;
-import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -63,41 +52,22 @@
import com.ogoglio.client.WebAPIClientWire;
import com.ogoglio.client.WebAPIDescriptor;
import com.ogoglio.client.model.Body;
+import com.ogoglio.client.model.BodyDataProvider;
import com.ogoglio.client.model.Space;
+import com.ogoglio.client.model.TemplateDataProvider;
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.J3DDataManager;
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.xml.AccountDocument;
import com.ogoglio.xml.BodyDocument;
public class BodyEditorApplet extends Applet {
- public static final ImageIcon LEFT_ARROW = UIConstants.loadIconFromResource("images/LeftArrow.gif");
-
- public static final ImageIcon LEFT_ARROW_DISABLED = UIConstants.loadIconFromResource("images/LeftArrowDisabled.gif");
-
- public static final ImageIcon RIGHT_ARROW = UIConstants.loadIconFromResource("images/RightArrow.gif");
-
- public static final ImageIcon RIGHT_ARROW_DISABLED = UIConstants.loadIconFromResource("images/RightArrowDisabled.gif");
-
- private RowModel hairRowModel = null;
-
- private RowModel eyesRowModel = null;
-
- private RowModel noseRowModel = null;
-
- private RowModel mouthRowModel = null;
-
- private RowModel faceRowModel = null;
-
private URI serviceURI = null;
private String authCookie = null;
@@ -114,10 +84,12 @@
private SpacelessUser user = null;
- private WebAPIClient webClient;
+ private WebAPIClient webClient = null;
private boolean completedInitialLoad = false;
+ private J3DDataManager dataManager = null;
+
public BodyEditorApplet() {
setBackground(Color.WHITE);
setLayout(new BorderLayout());
@@ -132,49 +104,14 @@
private class SpacelessContext implements Context {
- public InputStream getUserGeometryStream(String username, String name) throws IOException {
- if (user.getBody().isMale()) {
- return UIConstants.getResource(BodyConstants.MALE_AVATAR_PATH);
- } else {
- return UIConstants.getResource(BodyConstants.FEMALE_AVATAR_PATH);
- }
+ public BodyDocument getBodyDocument(String username, long bodyID) throws IOException {
+ return new BodyDocument(bodyID, username, "Body", 1, 1, 1, 1, 1, false, 2, 1);
}
- public InputStream getUserAnimationStream(String username, long animationID) throws IOException {
- return BodyConstants.getUserAnimation((int) animationID);
- }
-
- public InputStream getUserSkinMapStream(String username) throws IOException {
- 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) {
return null;
}
- public InputStream getTemplateGeometryStream(String ownerUsername, long templateID, int lodIndex) {
- return null;
- }
-
- public InputStream getTemplateResourceStream(String ownerUsername, long templateID, String name) throws IOException {
- return null;
- }
-
- public InputStream getThingAnimationStream(long thingID, long animationID) throws IOException {
- return null;
- }
-
- public String getThingScript(long thingID) throws IOException {
- return null;
- }
-
- public BodyDocument getBodyDocument(String username, long bodyID) throws IOException {
- return bodyDoc;
- }
}
private class BodyPanel extends Panel {
@@ -213,7 +150,8 @@
public boolean addUserRenderable() {
try {
- renderable = new J3DUserRenderable(user, true, new BvhParser(user, 0).parse());
+ System.err.println("Trevor needs to fix the body editor");
+ renderable = new J3DUserRenderable(user, dataManager.getBodyData("mike"));
userGroup.addChild(renderable);
return true;
} catch (Exception e) {
@@ -264,18 +202,6 @@
private class WestPanel extends Panel {
Dimension dimension = new Dimension(150, 300);
- ScrollingRowPanel hairRow = new ScrollingRowPanel(true, hairRowModel);
-
- ScrollingRowPanel eyesRow = new ScrollingRowPanel(true, eyesRowModel);
-
- ScrollingRowPanel noseRow = new ScrollingRowPanel(true, noseRowModel);
-
- ScrollingRowPanel mouseRow = new ScrollingRowPanel(true, mouthRowModel);
-
- ScrollingRowPanel faceRow = new ScrollingRowPanel(true, faceRowModel);
-
- GenderPanel genderPanel = new GenderPanel();
-
HeightPanel heightPanel = new HeightPanel();
public WestPanel() {
@@ -284,12 +210,6 @@
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
setBackground(Color.WHITE);
- //add(hairRow);
- //add(eyesRow);
- //add(noseRow);
- //add(mouseRow);
- //add(faceRow);
- add(genderPanel);
add(heightPanel);
}
@@ -299,58 +219,6 @@
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, 100);
-
- ImageIcon maleIcon = UIConstants.loadIconFromResource("images/MaleIcon32x32.gif");
-
- ImageIcon femaleIcon = UIConstants.loadIconFromResource("images/FemaleIcon32x32.gif");
-
- JRadioButton maleButton = new JRadioButton("male", maleIcon);
-
- JRadioButton femaleButton = new JRadioButton("female", femaleIcon);
-
- public GenderPanel() {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
-
- 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 {
Dimension dimension = new Dimension(80, 35);
@@ -364,6 +232,7 @@
private class HeightPanel extends Panel implements ChangeListener {
Dimension dimension = new Dimension(150, 150);
+
JSlider slider = new JSlider(JSlider.VERTICAL, 150, 210, 200);
public HeightPanel() {
@@ -373,15 +242,14 @@
setLayout(new BorderLayout());
setBackground(Color.WHITE);
-
JLabel heightLabel = new JLabel("height:");
heightLabel.setBackground(Color.WHITE);
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
panel.setBackground(Color.WHITE);
panel.add(heightLabel);
add(panel, BorderLayout.NORTH);
-
- int value = (int)(user.getBody().getHeight() * 100);
+
+ int value = (int) (user.getBody().getHeight() * 100);
slider.setValue(value);
slider.addChangeListener(this);
slider.setMajorTickSpacing(20);
@@ -420,279 +288,21 @@
}
}
- 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);
- ScrollingRowPanel hairRow = new ScrollingRowPanel(false, hairRowModel);
-
- ScrollingRowPanel eyesRow = new ScrollingRowPanel(false, eyesRowModel);
-
- ScrollingRowPanel noseRow = new ScrollingRowPanel(false, noseRowModel);
-
- ScrollingRowPanel mouthRow = new ScrollingRowPanel(false, mouthRowModel);
-
- ScrollingRowPanel faceRow = new ScrollingRowPanel(false, faceRowModel);
-
TexturePanel texturePanel = new TexturePanel();
WidthPanel widthPanel = new WidthPanel();
- AnimationPanel animationPanel = new AnimationPanel();
-
public EastPanel() {
setPreferredSize(dimension);
setMinimumSize(dimension);
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5));
setBackground(Color.WHITE);
-
- //add(hairRow);
- //add(eyesRow);
- //add(noseRow);
- //add(mouthRow);
- //add(faceRow);
-
- add(animationPanel);
- //add(texturePanel);
- //add(widthPanel);
}
}
- private class ArrowButton extends Panel implements MouseListener {
- Image image = null;
-
- ArrowButtonListener listener = null;
-
- ArrowButton(Image image, ArrowButtonListener listener) {
- this.image = image;
- this.listener = listener;
- this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- setPreferredSize(new Dimension(image.getWidth(this), image.getHeight(this)));
- addMouseListener(this);
- }
-
- public void paint(Graphics graphics) {
- graphics.drawImage(image, 0, 0, this);
- }
-
- public void mouseClicked(MouseEvent event) {
- if (listener != null) {
- listener.clicked(this);
- }
- }
-
- public void mouseEntered(MouseEvent arg0) {
- }
-
- public void mouseExited(MouseEvent arg0) {
- }
-
- public void mousePressed(MouseEvent arg0) {
- }
-
- public void mouseReleased(MouseEvent arg0) {
- }
-
- }
-
- private interface ArrowButtonListener {
- public void clicked(ArrowButton button);
- }
-
- private class RowModel {
- int currentIndex = 0;
-
- Image[] icons = null;
-
- Vector listeners = new Vector();
-
- RowModel(int index, Image[] icons) {
- this.currentIndex = index;
- this.icons = icons;
- }
-
- void increment() {
- if (currentIndex >= icons.length - 1) {
- return;
- }
- currentIndex++;
- for (int i = 0; i < listeners.size(); i++) {
- ((RowModelListener) listeners.elementAt(i)).indexChanged(this);
- }
- }
-
- void decrement() {
- if (currentIndex <= 0) {
- return;
- }
- currentIndex--;
- for (int i = 0; i < listeners.size(); i++) {
- ((RowModelListener) listeners.elementAt(i)).indexChanged(this);
- }
- }
- }
-
- private interface RowModelListener {
- public void indexChanged(RowModel model);
- }
-
- private class ScrollingRowPanel extends Panel implements ArrowButtonListener, RowModelListener {
- boolean left = false;
-
- int iconDisplayWidth = 32;
-
- int iconDisplayHeight = 32;
-
- int iconPadding = 12;
-
- Dimension dimension = new Dimension(150, 38);
-
- ArrowButton arrowButton = null;
-
- RowModel model = null;
-
- int numIcons = 0;
-
- int iconYPos = 1;
-
- public ScrollingRowPanel(boolean left, RowModel model) {
- setPreferredSize(dimension);
- setMinimumSize(dimension);
- setBackground(Color.WHITE);
- this.left = left;
- this.model = model;
-
- setLayout(new FlowLayout(left ? FlowLayout.LEFT : FlowLayout.RIGHT, 0, 1));
-
- arrowButton = new ArrowButton(left ? LEFT_ARROW.getImage() : RIGHT_ARROW.getImage(), this);
- add(arrowButton);
- float widthToHeightRatio = model.icons[0].getWidth(null) / (float) model.icons[0].getHeight(null);
- if (model.icons[0].getWidth(null) > model.icons[0].getHeight(null)) {
- iconDisplayHeight = (int) (iconDisplayWidth / widthToHeightRatio);
- } else {
- iconDisplayWidth = (int) (iconDisplayHeight * widthToHeightRatio);
- }
-
- numIcons = (int) ((dimension.width - arrowButton.getPreferredSize().getWidth()) / (iconDisplayWidth + (2 * iconPadding)));
- iconYPos = (dimension.height / 2) - (iconDisplayHeight / 2);
- model.listeners.add(this);
- }
-
- public void paint(Graphics graphics) {
- graphics.setColor(Color.WHITE);
- graphics.fillRect(0, 0, getWidth(), getHeight());
- if (left) {
- paintLeft(graphics);
- } else {
- paintRight(graphics);
- }
- }
-
- void paintLeft(Graphics graphics) {
- graphics.setColor(Color.GRAY);
- graphics.drawRect(0, 0, getWidth() + 1, getHeight() - 1);
- if (getWidth() <= 1) {
- return;
- }
- int numDrawn = 0;
- for (int i = model.currentIndex - 1; i >= 0 && i < model.icons.length && numDrawn <= numIcons; i--) {
- graphics.drawImage(model.icons[i], getWidth() - iconDisplayWidth - (numDrawn * iconDisplayWidth) - (numDrawn * iconPadding), iconYPos, iconDisplayWidth, iconDisplayHeight, this);
- numDrawn++;
- }
- }
-
- void paintRight(Graphics graphics) {
- graphics.setColor(Color.GRAY);
- graphics.drawRect(-1, 0, getWidth(), getHeight() - 1);
- if (getWidth() <= 1) {
- return;
- }
- int numDrawn = 0;
- for (int i = model.currentIndex + 1; i < model.icons.length && numDrawn <= numIcons; i++) {
- graphics.drawImage(model.icons[i], ((i - model.currentIndex - 1) * iconDisplayWidth) + (numDrawn * iconPadding), iconYPos, iconDisplayWidth, iconDisplayHeight, this);
- numDrawn++;
- }
-
- }
-
- public void clicked(ArrowButton button) {
- if (left) {
- model.increment();
- } else {
- model.decrement();
- }
- }
-
- public void indexChanged(RowModel model) {
- repaint();
- if (model == hairRowModel) {
- bodyDoc.setHairIndex(hairRowModel.currentIndex);
- } else if (model == eyesRowModel) {
- bodyDoc.setEyesIndex(eyesRowModel.currentIndex);
- } else if (model == noseRowModel) {
- bodyDoc.setNoseIndex(noseRowModel.currentIndex);
- } else if (model == mouthRowModel) {
- bodyDoc.setMouthIndex(mouthRowModel.currentIndex);
- } else if (model == faceRowModel) {
- bodyDoc.setFaceIndex(faceRowModel.currentIndex);
- } else {
- throw new IllegalStateException("Unknown model: " + model);
- }
- Body body = user.getBody();
- body.set(bodyDoc.getHairIndex(), bodyDoc.getEyesIndex(), bodyDoc.getNoseIndex(), bodyDoc.getMouthIndex(), bodyDoc.getFaceIndex());
- bodyPanel.renderable.repaintSkinTexture();
- try {
- webClient.updateBody(bodyDoc);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
public void start() {
authCookie = getParameter("loginCookie");
if (authCookie == null) {
@@ -715,17 +325,10 @@
accountDoc = authenticator.getAccountDocument(true);
bodyDoc = webClient.getBodyDocument(accountDoc.getUsername(), accountDoc.getDefaultBodyID());
+ dataManager = new J3DDataManager(true, new TemplateProvider(), new BodyProvider());
+
user = new SpacelessUser(accountDoc.getUsername());
- hairRowModel = new RowModel(bodyDoc.getEyesIndex(), BodyConstants.EYES);
- eyesRowModel = new RowModel(bodyDoc.getEyesIndex(), BodyConstants.EYES);
- noseRowModel = new RowModel(bodyDoc.getNoseIndex(), BodyConstants.NOSES);
- mouthRowModel = new RowModel(bodyDoc.getMouthIndex(), BodyConstants.MOUTHES);
- 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);
@@ -760,6 +363,34 @@
//renderer.stopRenderer();
}
+ private class TemplateProvider implements TemplateDataProvider {
+ public InputStream getTemplateGeometry(String username, long templateID, int lod) {
+ return null;
+ }
+
+ public InputStream getTemplateResource(String username, long templateID, String resourceName) {
+ return null;
+ }
+
+ public String getTemplateScript(String username, long templateID) {
+ return null;
+ }
+ }
+
+ private class BodyProvider implements BodyDataProvider {
+ public ZipInputStream getBodyData(String bodyName) {
+ try {
+ return webClient.getBodyData(bodyName);
+ } catch (IOException e) {
+ removeAll();
+ validate();
+ add(new ErrorPanel("Unfortunately, I could not load a body."));
+ validate();
+ return null;
+ }
+ }
+ }
+
//TODO make the error panel less ugly
private class ErrorPanel extends Panel {
public ErrorPanel(String errorMessage) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|