-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP #12: Added DamconCanvas, wireframed model, embedded in main windo…
…w/JFrame - Moved existing UI down to mimic built-in engineering console and make room for damcon and other sliders - The current process of creating a J3D Universe generates a Viewer which in turn generates its own JFrame (because it wasn't given a Canvas). We need to figure out how the default canvas is generated, make one ourselves, and pass that through (WIP function checked in as well but it doesn't work). In the worst case, we might be able to pass the J3D JFrame through to the console manager and just reuse it.
- Loading branch information
1 parent
e99109a
commit 9a9d881
Showing
3 changed files
with
118 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/com/brindyblitz/artemis/engconsole/ui/damcon/DamconCanvas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.brindyblitz.artemis.engconsole.ui.damcon; | ||
|
||
import com.sun.j3d.loaders.IncorrectFormatException; | ||
import com.sun.j3d.loaders.ParsingErrorException; | ||
import com.sun.j3d.loaders.Scene; | ||
import com.sun.j3d.loaders.objectfile.ObjectFile; | ||
import com.sun.j3d.utils.universe.SimpleUniverse; | ||
import com.sun.j3d.utils.universe.Viewer; | ||
import com.sun.j3d.utils.universe.ViewingPlatform; | ||
|
||
import javax.media.j3d.*; | ||
import javax.swing.*; | ||
import javax.vecmath.Color3f; | ||
import java.awt.*; | ||
import java.awt.event.WindowEvent; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.Enumeration; | ||
|
||
public abstract class DamconCanvas { | ||
private static final Color WIREFRAME_COLOR = Color.GREEN; | ||
|
||
public static Canvas3D buildDamconCanvas() { | ||
SimpleUniverse universe = new SimpleUniverse(); | ||
universe.getViewingPlatform().setNominalViewingTransform(); | ||
String OBJ_PATH = new File(System.getProperty("user.dir"), "art/models/obj-from-blender/artemis2.obj").getPath(); | ||
try { | ||
Scene scene = new ObjectFile(ObjectFile.RESIZE).load(OBJ_PATH); | ||
wireframeifyScene(scene); | ||
universe.addBranchGraph(scene.getSceneGroup()); | ||
} catch (FileNotFoundException | IncorrectFormatException | ParsingErrorException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// TODO: the reason this creates a new window is explained here: | ||
// http://download.java.net/media/java3d/javadoc/1.3.2/com/sun/j3d/utils/universe/Viewer.html | ||
// JFrame unused_frame = universe.getViewer().getJFrame(0); | ||
|
||
return universe.getCanvas(); | ||
} | ||
|
||
public static Canvas3D buildDamconCanvas_WIP() { | ||
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); | ||
Canvas3D canvas = new Canvas3D(config); | ||
Viewer viewer = new Viewer(canvas); | ||
ViewingPlatform viewingPlatform = new ViewingPlatform(); | ||
SimpleUniverse universe = new SimpleUniverse(viewingPlatform, viewer); | ||
universe.getViewingPlatform().setNominalViewingTransform(); | ||
String OBJ_PATH = new File(System.getProperty("user.dir"), "art/models/obj-from-blender/artemis2.obj").getPath(); | ||
try { | ||
Scene scene = new ObjectFile(ObjectFile.RESIZE).load(OBJ_PATH); | ||
wireframeifyScene(scene); | ||
universe.addBranchGraph(scene.getSceneGroup()); | ||
} catch (FileNotFoundException | IncorrectFormatException | ParsingErrorException e) { | ||
e.printStackTrace(); | ||
} | ||
return canvas; | ||
} | ||
|
||
private static void wireframeifyScene(Scene scene) { | ||
Appearance wireframe = getWireframeAppearance(); | ||
|
||
// TODO: This works for the Artemis OBJ model. If the scene graph has multiple Shape3D nodes, this would need to be set on all of them. Is that necessary or can we guarantee it won't be needed? | ||
|
||
Enumeration<Node> children = scene.getSceneGroup().getAllChildren(); | ||
while (children.hasMoreElements()) { | ||
Node node = children.nextElement(); | ||
if (node.getClass().equals(Shape3D.class)) { | ||
Shape3D s3d = (Shape3D)node; | ||
s3d.setAppearance(wireframe); | ||
} | ||
} | ||
} | ||
|
||
private static Appearance getWireframeAppearance() { | ||
Appearance app = new Appearance(); | ||
Color awtColor = WIREFRAME_COLOR; | ||
Color3f color = new Color3f(awtColor); | ||
ColoringAttributes ca = new ColoringAttributes(); | ||
ca.setColor(color); | ||
app.setColoringAttributes(ca); | ||
PolygonAttributes pa = new PolygonAttributes(); | ||
pa.setPolygonMode(pa.POLYGON_LINE); | ||
pa.setCullFace(pa.CULL_NONE); | ||
app.setPolygonAttributes(pa); | ||
return app; | ||
} | ||
} |