From d2e8561528e9f3756f7763906ba24cb146f711ba Mon Sep 17 00:00:00 2001 From: markpet49 Date: Wed, 16 Sep 2020 15:45:41 -0500 Subject: [PATCH 1/3] Add Collada example --- nbproject/configs/ColladaViewer.properties | 1 + .../worldwindx/examples/ColladaViewer.java | 153 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 nbproject/configs/ColladaViewer.properties create mode 100644 src/gov/nasa/worldwindx/examples/ColladaViewer.java diff --git a/nbproject/configs/ColladaViewer.properties b/nbproject/configs/ColladaViewer.properties new file mode 100644 index 0000000000..db451073d7 --- /dev/null +++ b/nbproject/configs/ColladaViewer.properties @@ -0,0 +1 @@ +main.class=gov.nasa.worldwindx.examples.ColladaViewer diff --git a/src/gov/nasa/worldwindx/examples/ColladaViewer.java b/src/gov/nasa/worldwindx/examples/ColladaViewer.java new file mode 100644 index 0000000000..adc7066a5d --- /dev/null +++ b/src/gov/nasa/worldwindx/examples/ColladaViewer.java @@ -0,0 +1,153 @@ +/* + * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The NASA World Wind Java (WWJ) platform is 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. + * + * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source + * software: + * + * Jackson Parser – Licensed under Apache 2.0 + * GDAL – Licensed under MIT + * JOGL – Licensed under Berkeley Software Distribution (BSD) + * Gluegen – Licensed under Berkeley Software Distribution (BSD) + * + * A complete listing of 3rd Party software notices and licenses included in + * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party + * notices and licenses PDF found in code directory. + */ +package gov.nasa.worldwindx.examples; + +import gov.nasa.worldwind.*; +import gov.nasa.worldwind.avlist.AVKey; +import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.layers.Layer; +import gov.nasa.worldwind.layers.LayerList; +import gov.nasa.worldwind.layers.RenderableLayer; +import gov.nasa.worldwind.ogc.collada.ColladaRoot; +import gov.nasa.worldwind.ogc.collada.impl.ColladaController; +import gov.nasa.worldwind.util.WWUtil; + +import javax.swing.*; +import java.awt.*; +import java.io.File; + +/** + * Shows how to load COLLADA models. + */ +public class ColladaViewer extends ApplicationTemplate { + + public static class AppFrame extends ApplicationTemplate.AppFrame { + + public AppFrame() { + super(true, true, false); // Don't include the layer panel; we're using the on-screen layer tree. + + // Size the WorldWindow to take up the space typically used by the layer panel. + Dimension size = new Dimension(1400, 800); + this.setPreferredSize(size); + this.pack(); + WWUtil.alignComponent(null, this, AVKey.CENTER); + LayerList layers = getWwd().getModel().getLayers(); + for (Layer layer : layers) { + String layerName = layer.getName(); + if (layerName != null && layerName.toLowerCase().startsWith("bing")) { + layer.setEnabled(true); + break; + } + } + } + + /** + * Adds the specified colladaRoot to this app frame's WorldWindow as a new + * Layer. + * + * @param colladaRoot the ColladaRoot to add a new layer for. + */ + protected void addColladaLayer(ColladaRoot colladaRoot) { + // Create a ColladaController to adapt the ColladaRoot to the WorldWind renderable interface. + ColladaController colladaController = new ColladaController(colladaRoot); + + // Adds a new layer containing the ColladaRoot to the end of the WorldWindow's layer list. + RenderableLayer layer = new RenderableLayer(); + layer.addRenderable(colladaController); + this.getWwd().getModel().getLayers().add(layer); + } + } + + /** + * A Thread that loads a COLLADA file and displays it in an AppFrame. + */ + public static class WorkerThread extends Thread { + + /** + * Indicates the source of the COLLADA file loaded by this thread. Initialized during construction. + */ + protected Object colladaSource; + /** + * Geographic position of the COLLADA model. + */ + protected Position position; + /** + * Indicates the AppFrame the COLLADA file content is displayed in. Initialized during + * construction. + */ + protected AppFrame appFrame; + + /** + * Creates a new worker thread from a specified colladaSource and appFrame. + * + * @param colladaSource the source of the COLLADA file to load. May be a {@link java.io.File}, a {@link + * java.net.URL}, or an {@link java.io.InputStream}, or a {@link String} identifying a file path or URL. + * @param position the geographic position of the COLLADA model. + * @param appFrame the AppFrame in which to display the COLLADA source. + */ + public WorkerThread(Object colladaSource, Position position, AppFrame appFrame) { + this.colladaSource = colladaSource; + this.position = position; + this.appFrame = appFrame; + } + + /** + * Loads this worker thread's COLLADA source into a new + * {@link gov.nasa.worldwind.ogc.collada.ColladaRoot}, then adds the new ColladaRoot + * to this worker thread's AppFrame. + */ + @Override + public void run() { + try { + final ColladaRoot colladaRoot = ColladaRoot.createAndParse(this.colladaSource); + colladaRoot.setPosition(this.position); + colladaRoot.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); + + // Schedule a task on the EDT to add the parsed document to a layer + SwingUtilities.invokeLater(() -> { + appFrame.addColladaLayer(colladaRoot); + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public static void main(String[] args) { + Configuration.setValue(AVKey.INITIAL_LATITUDE, 40.028); + Configuration.setValue(AVKey.INITIAL_LONGITUDE, -105.27284091410579); + Configuration.setValue(AVKey.INITIAL_ALTITUDE, 4000); + Configuration.setValue(AVKey.INITIAL_PITCH, 50); + + final AppFrame af = (AppFrame) start("WorldWind COLLADA Viewer", AppFrame.class); + + new WorkerThread(new File("testData/collada/cu_macky/CU Macky.dae"), + Position.fromDegrees(40.009993372683, -105.272774533734), af).start(); + + } +} From 4b5f1ab7e8d00265436d9371a9c7c5de77b16ce2 Mon Sep 17 00:00:00 2001 From: Miguel Del Castillo Date: Wed, 16 Sep 2020 17:59:58 -0500 Subject: [PATCH 2/3] Reordered main function to make it more tutorial-like - Added link to COLLADA's official website. - Added comments to distinguish coordinates related to camera from coordinates related to the 3D model. - Changed single line comments to the corresponding bracket. - Made reference to the CU Macky Auditorium on its position. --- .../worldwindx/examples/ColladaViewer.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/gov/nasa/worldwindx/examples/ColladaViewer.java b/src/gov/nasa/worldwindx/examples/ColladaViewer.java index adc7066a5d..a3e5876786 100644 --- a/src/gov/nasa/worldwindx/examples/ColladaViewer.java +++ b/src/gov/nasa/worldwindx/examples/ColladaViewer.java @@ -42,7 +42,7 @@ import java.io.File; /** - * Shows how to load COLLADA models. + * Shows how to load {@link COLLADA 3D models. */ public class ColladaViewer extends ApplicationTemplate { @@ -83,23 +83,17 @@ protected void addColladaLayer(ColladaRoot colladaRoot) { } } - /** - * A Thread that loads a COLLADA file and displays it in an AppFrame. - */ + // A Thread that loads a COLLADA file and displays it in an AppFrame. public static class WorkerThread extends Thread { - /** - * Indicates the source of the COLLADA file loaded by this thread. Initialized during construction. - */ + // Indicates the source of the COLLADA file loaded by this thread. Initialized during construction. protected Object colladaSource; - /** - * Geographic position of the COLLADA model. - */ + + // Geographic position of the COLLADA model. protected Position position; - /** - * Indicates the AppFrame the COLLADA file content is displayed in. Initialized during - * construction. - */ + + // Indicates the AppFrame the COLLADA file content is displayed in. Initialized during + // construction. protected AppFrame appFrame; /** @@ -137,17 +131,22 @@ public void run() { } } } - + public static void main(String[] args) { + + // Set camera position and pitch angle. Configuration.setValue(AVKey.INITIAL_LATITUDE, 40.028); Configuration.setValue(AVKey.INITIAL_LONGITUDE, -105.27284091410579); Configuration.setValue(AVKey.INITIAL_ALTITUDE, 4000); Configuration.setValue(AVKey.INITIAL_PITCH, 50); - + + // Set the application frame to update, a position for the model, and a path to the COLLADA file. final AppFrame af = (AppFrame) start("WorldWind COLLADA Viewer", AppFrame.class); - - new WorkerThread(new File("testData/collada/cu_macky/CU Macky.dae"), - Position.fromDegrees(40.009993372683, -105.272774533734), af).start(); + final Position MackyAuditoriumPosition = Position.fromDegrees(40.009993372683, -105.272774533734); + final File ColladaFile = new File("testData/collada/cu_macky/CU Macky.dae"); + + // Invoque the Thread to load the COLLADA model asynchronously. + new WorkerThread(ColladaFile, MackyAuditoriumPosition, af).start(); } } From 8ff7474205f4910c8be9ee773a601253130332b6 Mon Sep 17 00:00:00 2001 From: markpet49 Date: Thu, 17 Sep 2020 11:57:07 -0500 Subject: [PATCH 3/3] Typo, javadoc fix, code format --- .../nasa/worldwindx/examples/ColladaViewer.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gov/nasa/worldwindx/examples/ColladaViewer.java b/src/gov/nasa/worldwindx/examples/ColladaViewer.java index a3e5876786..1347481433 100644 --- a/src/gov/nasa/worldwindx/examples/ColladaViewer.java +++ b/src/gov/nasa/worldwindx/examples/ColladaViewer.java @@ -42,7 +42,7 @@ import java.io.File; /** - * Shows how to load {@link COLLADA 3D models. + * Shows how to load COLLADA 3D models. */ public class ColladaViewer extends ApplicationTemplate { @@ -88,10 +88,10 @@ public static class WorkerThread extends Thread { // Indicates the source of the COLLADA file loaded by this thread. Initialized during construction. protected Object colladaSource; - + // Geographic position of the COLLADA model. protected Position position; - + // Indicates the AppFrame the COLLADA file content is displayed in. Initialized during // construction. protected AppFrame appFrame; @@ -131,21 +131,21 @@ public void run() { } } } - + public static void main(String[] args) { - + // Set camera position and pitch angle. Configuration.setValue(AVKey.INITIAL_LATITUDE, 40.028); Configuration.setValue(AVKey.INITIAL_LONGITUDE, -105.27284091410579); Configuration.setValue(AVKey.INITIAL_ALTITUDE, 4000); Configuration.setValue(AVKey.INITIAL_PITCH, 50); - + // Set the application frame to update, a position for the model, and a path to the COLLADA file. final AppFrame af = (AppFrame) start("WorldWind COLLADA Viewer", AppFrame.class); final Position MackyAuditoriumPosition = Position.fromDegrees(40.009993372683, -105.272774533734); final File ColladaFile = new File("testData/collada/cu_macky/CU Macky.dae"); - - // Invoque the Thread to load the COLLADA model asynchronously. + + // Invoke the Thread to load the COLLADA model asynchronously. new WorkerThread(ColladaFile, MackyAuditoriumPosition, af).start(); }