use of com.ardor3d.extension.model.collada.jdom.ColladaImporter in project energy3d by concord-consortium.
the class SceneManager method createCompass.
private Node createCompass() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
// Load the collada scene
Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
final ColladaStorage storage = colladaImporter.load(source);
final Node compass = storage.getScene();
BMText txt;
final double Z = 0.1;
txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(2, 0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(-2, -0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, 2, Z);
txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compass.attachChild(txt);
txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, -2, Z);
txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
compass.attachChild(txt);
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
compass.setRenderState(lightState);
compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
compass.updateWorldRenderStates(true);
final Node compassNode = new Node();
compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compassNode.attachChild(compass);
System.out.println("done");
compass.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
}
});
return compassNode;
}
use of com.ardor3d.extension.model.collada.jdom.ColladaImporter in project energy3d by concord-consortium.
the class SceneManager method createEarth.
private Node createEarth() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "earth.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
final ColladaStorage storage = colladaImporter.load(source);
final Node earth = storage.getScene();
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
earth.setRenderState(lightState);
earth.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
earth.updateWorldRenderStates(true);
final Node node = new Node();
node.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
node.attachChild(earth);
earth.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
earth.setRotation(new Matrix3().fromAngles(0, 0, angle));
}
});
return node;
}
use of com.ardor3d.extension.model.collada.jdom.ColladaImporter in project energy3d by concord-consortium.
the class Foundation method importCollada.
public Node importCollada(final URL file, final Vector3 position) throws Exception {
if (importedNodes == null) {
importedNodes = new ArrayList<Node>();
}
if (importedNodeStates == null) {
importedNodeStates = new ArrayList<NodeState>();
}
if (position != null) {
// when position is null, the cursor is already set to be wait by the loading method
SceneManager.getInstance().cursorWait(true);
}
File sourceFile = new File(file.toURI());
if (!sourceFile.exists() && Scene.getURL() != null) {
sourceFile = new File(new File(Scene.getURL().toURI()).getParentFile(), Util.getFileName(file.getPath()).replaceAll("%20", " "));
}
if (sourceFile.exists()) {
final double az = Math.toRadians(getAzimuth());
final boolean zeroAz = Util.isZero(az);
// 0.633 is determined by fitting the length in Energy3D to the length in SketchUp
final double scale = Scene.getInstance().getAnnotationScale() * 0.633;
final ColladaStorage storage = new ColladaImporter().load(new URLResourceSource(sourceFile.toURI().toURL()));
final Node originalNode = storage.getScene();
originalNode.setScale(scale);
if (position != null) {
// when position is null, the node uses the position saved in the associated NodeState object
final NodeState ns = new NodeState();
ns.setSourceURL(file);
ns.setAbsolutePosition(position.clone());
importedNodeStates.add(ns);
originalNode.setTranslation(position);
final Vector3 relativePosition = position.subtract(getAbsCenter().multiplyLocal(1, 1, 0), null).addLocal(0, 0, height);
// why not -getAzimuth()?
ns.setRelativePosition(zeroAz ? relativePosition : new Matrix3().fromAngles(0, 0, az).applyPost(relativePosition, null));
}
// now construct a new node that is a parent of all planar meshes
final Node newNode = new Node(originalNode.getName());
final String nodeString = "Node #" + importedNodes.size() + ", Foundation #" + id;
final List<Mesh> meshes = new ArrayList<Mesh>();
Util.getMeshes(originalNode, meshes);
String warnInfo = null;
final int nodeIndex = importedNodes.size();
int meshIndex = 0;
for (final Mesh m : meshes) {
final ReadOnlyTransform t = m.getWorldTransform();
final MeshData md = m.getMeshData();
switch(md.getIndexMode(0)) {
case Triangles:
final List<Mesh> children = TriangleMeshLib.getPlanarMeshes(m);
if (!children.isEmpty()) {
for (final Mesh s : children) {
s.setTransform(t);
final UserData ud = new UserData(this, nodeIndex, meshIndex);
ud.setNormal((Vector3) s.getUserData());
ud.setRenderState(s.getLocalRenderState(StateType.Texture));
ud.setTextureBuffer(s.getMeshData().getTextureBuffer(0));
s.setUserData(ud);
s.setName("Mesh #" + meshIndex + ", " + nodeString);
newNode.attachChild(s);
meshIndex++;
}
}
break;
case Lines:
break;
default:
warnInfo = md.getIndexMode(0).name();
break;
}
}
if (warnInfo != null) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Non-triangular mesh " + warnInfo + " is found.", "Warning", JOptionPane.WARNING_MESSAGE);
}
if (newNode.getNumberOfChildren() > 0) {
importedNodes.add(newNode);
newNode.setScale(scale);
newNode.updateWorldTransform(true);
root.attachChild(newNode);
createMeshThickness(newNode);
if (!zeroAz) {
setRotatedNormalsForImportedMeshes();
}
return newNode;
}
if (position != null) {
SceneManager.getInstance().cursorWait(false);
}
} else {
if (position != null) {
// get rid of the dead nodes no longer linked to files
for (final Iterator<NodeState> it = importedNodeStates.iterator(); it.hasNext(); ) {
if (file.equals(it.next().getSourceURL())) {
it.remove();
}
}
}
}
return null;
}
Aggregations