use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class Foundation method pickMesh.
public void pickMesh(final int x, final int y) {
selectedMesh = null;
if (importedNodes != null) {
final PickResults pickResults = new PrimitivePickResults();
pickResults.setCheckDistance(true);
final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
for (final Node node : importedNodes) {
for (final Spatial s : node.getChildren()) {
if (s instanceof Mesh) {
PickingUtil.findPick(s, pickRay, pickResults, false);
}
}
}
if (pickResults.getNumber() > 0) {
final Pickable pickable = pickResults.getPickData(0).getTarget();
if (pickable instanceof Mesh) {
selectedMesh = (Mesh) pickable;
drawMeshSelection(selectedMesh);
}
} else {
setMeshSelectionVisible(false);
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class Foundation method setMovePointsVisible.
public void setMovePointsVisible(final boolean visible) {
final int n = points.size();
for (int i = n - 4; i < n; i++) {
final Spatial editPoint = pointsRoot.getChild(i);
((Mesh) editPoint).setVisible(visible);
final SceneHints sceneHints = editPoint.getSceneHints();
sceneHints.setAllPickingHints(visible);
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class Foundation method drawImportedNodes.
public void drawImportedNodes() {
if (importedNodes != null) {
final int n = importedNodes.size();
if (n > 0) {
Node ni;
final Vector3 c = getAbsCenter();
// the absolute center is lifted to the center of the bounding box that includes walls when there are
c.setZ(height);
// FIXME: Why negate?
final Matrix3 matrix = new Matrix3().fromAngles(0, 0, -Math.toRadians(getAzimuth()));
for (int i = 0; i < n; i++) {
ni = importedNodes.get(i);
if (root.getChildren().contains(ni)) {
final Vector3 relativePosition = importedNodeStates.get(i).getRelativePosition();
if (relativePosition != null) {
final Vector3 vi = matrix.applyPost(relativePosition, null);
ni.setTranslation(c.add(vi, null));
ni.setRotation(matrix);
for (final Spatial s : ni.getChildren()) {
if (s instanceof Mesh) {
final Mesh m = (Mesh) s;
m.updateModelBound();
}
}
}
}
}
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class SceneManager method initCamera.
public void initCamera() {
System.out.println("initCamera()");
final Camera camera = getCamera();
cameraNode = new CameraNode("Camera Node", camera);
root.attachChild(cameraNode);
cameraNode.updateFromCamera();
Scene.getInstance().updateEditShapes();
setCameraControl(CameraMode.ORBIT);
resetCamera(ViewMode.NORMAL);
SceneManager.getInstance().getCameraControl().reset();
taskManager.update(new Callable<Object>() {
@Override
public Object call() throws Exception {
final Spatial compass = createCompass();
compass.setScale(0.1);
compass.setTranslation(-1, -0.7, 2);
cameraNode.attachChild(compass);
final Spatial earth = createEarth();
earth.setScale(0.00012);
earth.setTranslation(-1, -0.67, 2);
cameraNode.attachChild(earth);
Scene.getInstance().updateEditShapes();
return null;
}
});
}
use of com.ardor3d.scenegraph.Spatial 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;
}
Aggregations