From 3a0f1372dae7103c55ea379349ff4673368a9502 Mon Sep 17 00:00:00 2001 From: chrisleung Date: Mon, 11 Feb 2008 01:41:55 +0000 Subject: [PATCH] OS X bug fixes; however emissive light is broken on OS X --- src/powerreader/Pick.java | 19 +++++++++++++------ src/util/HierarchyObject.java | 10 ++++++++-- src/util/RawTextParser.java | 1 + src/util/TextObject3d.java | 14 +++++++------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/powerreader/Pick.java b/src/powerreader/Pick.java index 5081d27..8345fcc 100644 --- a/src/powerreader/Pick.java +++ b/src/powerreader/Pick.java @@ -42,6 +42,7 @@ import java.net.MalformedURLException; import java.net.URL; import javax.media.j3d.Raster; +import javax.media.j3d.SceneGraphPath; import javax.vecmath.Point3f; import com.sun.j3d.utils.picking.*; @@ -102,13 +103,19 @@ public void mouseClicked(MouseEvent e) { PickResult result = pickCanvas.pickClosest(); if (result != null) { - Shape3D s3 = (Shape3D)result.getNode(PickResult.SHAPE3D); - if (s3 != null) { - - // Get the textobject picked - TextObject3d tObj = (TextObject3d) s3.getParent().getParent().getParent(); - + // Retrieve the picked text object + TextObject3d tObj = null; + SceneGraphPath pickedPath = result.getSceneGraphPath(); + + for(int i = 0; i< pickedPath.nodeCount(); i++) { + if (pickedPath.getNode(i) instanceof TextObject3d) { + tObj = (TextObject3d) pickedPath.getNode(i); + } + } + + if (tObj != null) { + // Get its hierarchy object of the word WordHashMap map = WordHashMap.getInstance(); HierarchyObject pickedObject = map.getHirarchyObject(tObj); diff --git a/src/util/HierarchyObject.java b/src/util/HierarchyObject.java index 78c4c93..803a0f3 100644 --- a/src/util/HierarchyObject.java +++ b/src/util/HierarchyObject.java @@ -51,6 +51,9 @@ public class HierarchyObject { // Ordered list of children private ArrayList m_children; + // Stores whether this object is being rendered or not + private boolean m_render; + /** * Creates a new instance of HierarchyObject * @param newLevel Level of the hierarchy object @@ -58,6 +61,7 @@ public class HierarchyObject { * @param newNode Reference to the scene graph node */ public HierarchyObject(int newLevel, String newType) { + m_render = true; m_level = newLevel; m_type = newType; m_children = new ArrayList(); @@ -206,14 +210,16 @@ public void color(boolean highLight) { } public void disableRender() { - if(this.getParent() != null) { + if(m_render == true) { this.getParent().getTransformGroup().removeChild(m_branchGroup); + m_render = false; } } public void enabledRender() { - if(this.getParent() != null && m_branchGroup.getParent() == null) { + if(this.getParent() != null && m_render == false) { this.getParent().getTransformGroup().addChild(m_branchGroup); + m_render = true; } } } diff --git a/src/util/RawTextParser.java b/src/util/RawTextParser.java index a60d1fb..fa53c00 100644 --- a/src/util/RawTextParser.java +++ b/src/util/RawTextParser.java @@ -85,6 +85,7 @@ public void parse() { node.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); node.setCapability(BranchGroup.ALLOW_CHILDREN_READ); node.setCapability(BranchGroup.ALLOW_DETACH); + node.setCapability(BranchGroup.ENABLE_PICK_REPORTING); BufferedReader input = null; String line = null; diff --git a/src/util/TextObject3d.java b/src/util/TextObject3d.java index 1966166..6345ed1 100644 --- a/src/util/TextObject3d.java +++ b/src/util/TextObject3d.java @@ -73,9 +73,12 @@ public class TextObject3d extends TransformGroup { public TextObject3d(String text) { super(); + this.setCapability(TransformGroup.ENABLE_PICK_REPORTING); + // face it in the scene graph Transform3D rotation = new Transform3D(); TransformGroup rotation_group = new TransformGroup( rotation ); + rotation_group.setCapability(TransformGroup.ENABLE_PICK_REPORTING); this.addChild( rotation_group ); // Set up 3d geometry @@ -107,17 +110,17 @@ public TextObject3d(String text) { nextLocation.x += up.x + nextLocationIncrementWordSentence.x; - m_textShape = new Shape3D(); - m_textShape.setGeometry(textGeom); - m_textShape.setAppearance(m_textAppearanceBaseColor); - m_textShape.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE); + m_textShape = new Shape3D(textGeom,m_textAppearanceBaseColor); + m_textShape.setAppearanceOverrideEnable(true); m_textShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + m_textShape.setCapability(Shape3D.ENABLE_PICK_REPORTING); // attach it theText = new TransformGroup(); theText.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); theText.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); theText.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); + theText.setCapability(TransformGroup.ENABLE_PICK_REPORTING); theText.addChild(m_textShape); rotation_group.addChild( theText ); @@ -132,9 +135,6 @@ public static Appearance createAppearance(Color3f color) { // create the 3d text Appearance textAppear = new Appearance(); Material textMaterial = new Material(); - textMaterial.setCapability(Material.ALLOW_COMPONENT_WRITE); - textMaterial.setCapability(Material.ALLOW_COMPONENT_READ); - textMaterial.setCapability(Material.EMISSIVE); textMaterial.setEmissiveColor(color); textAppear.setMaterial(textMaterial); return textAppear;