use of com.ardor3d.math.Ray3 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.math.Ray3 in project energy3d by concord-consortium.
the class SceneManager method initMouse.
private void initMouse() {
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
((Component) canvas).requestFocusInWindow();
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
if (firstClickState == null) {
firstClickState = inputStates;
mousePressed(inputStates.getCurrent().getMouseState(), inputStates.getCurrent().getKeyboardState());
} else {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
// if editing object using select or resize then only mouse drag is allowed
if (operation == Operation.SELECT || operation == Operation.RESIZE) {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
} else if (firstClickState != null) {
final MouseState mouseState = inputStates.getCurrent().getMouseState();
final MouseState prevMouseState = firstClickState.getCurrent().getMouseState();
final ReadOnlyVector2 p1 = new Vector2(prevMouseState.getX(), prevMouseState.getY());
final ReadOnlyVector2 p2 = new Vector2(mouseState.getX(), mouseState.getY());
if (!(selectedPart instanceof Foundation || selectedPart instanceof Wall || selectedPart instanceof Window || selectedPart instanceof Door) || p1.distance(p2) > 10) {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
}
}
}
}));
((Component) canvas).addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (Util.isRightClick(e)) {
mouseRightClicked(e);
}
}
@Override
public void mouseReleased(final MouseEvent e) {
if (Util.isRightClick(e)) {
if (cameraChanged) {
TimeSeriesLogger.getInstance().logCamera("Pan");
cameraChanged = false;
}
}
}
});
((Component) canvas).addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
EnergyPanel.getInstance().update();
cameraChanged = true;
}
});
((Component) canvas).addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
TimeSeriesLogger.getInstance().logCamera("Zoom");
}
});
logicalLayer.registerTrigger(new InputTrigger(new MouseMovedCondition(), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
refresh = true;
mouseState = inputStates.getCurrent().getMouseState();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonClickedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
if (!isTopView() && inputStates.getCurrent().getMouseState().getClickCount(MouseButton.LEFT) == 2) {
if (PrintController.getInstance().isPrintPreview()) {
final MouseState mouse = inputStates.getCurrent().getMouseState();
final Ray3 pickRay = Camera.getCurrentCamera().getPickRay(new Vector2(mouse.getX(), mouse.getY()), false, null);
final PickResults pickResults = new PrimitivePickResults();
PickingUtil.findPick(PrintController.getInstance().getPagesRoot(), pickRay, pickResults, false);
if (pickResults.getNumber() > 0) {
cameraControl.zoomAtPoint(pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0));
}
} else {
final PickedHousePart pickedHousePart = SelectUtil.pickPart(inputStates.getCurrent().getMouseState().getX(), inputStates.getCurrent().getMouseState().getY());
if (pickedHousePart != null) {
cameraControl.zoomAtPoint(pickedHousePart.getPoint());
}
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LSHIFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
// SelectUtil.setPickLayer(0);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LSHIFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
// SelectUtil.setPickLayer(-1);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DELETE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
deleteCurrentSelection();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.BACK), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
deleteCurrentSelection();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.ESCAPE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
hideAllEditPoints();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (Config.isMac()) {
if (ks.isDown(Key.LMETA) || ks.isDown(Key.RMETA)) {
resetCamera();
}
} else {
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
resetCamera();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.I), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
System.out.println("---- Parts: ------------------------");
System.out.println("size = " + Scene.getInstance().getParts().size());
for (final HousePart part : Scene.getInstance().getParts()) {
System.out.println(part);
}
System.out.println("---- Scene: ------------------------");
System.out.println("size = " + Scene.getOriginalHouseRoot().getNumberOfChildren());
for (final Spatial mesh : Scene.getOriginalHouseRoot().getChildren()) {
System.out.println(mesh);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
Scene.getInstance().redrawAll(true);
}
}));
// Run/pause model replay
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = !PlayControl.replaying;
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.backward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 v = selectedPart.getNormal().clone();
v.crossLocal(Vector3.UNIT_Z);
moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.UP), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.backward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 n = selectedPart.getNormal().clone();
final Vector3 v = n.cross(Vector3.UNIT_Z, null);
moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.UP), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.RIGHT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.forward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 v = selectedPart.getNormal().clone();
v.crossLocal(Vector3.UNIT_Z).negateLocal();
moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.RIGHT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DOWN), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.forward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 n = selectedPart.getNormal().clone();
final Vector3 v = n.cross(Vector3.UNIT_Z, null).negateLocal();
moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.DOWN), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
PlayControl.active = false;
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.W), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.W), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.E), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.E), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.S), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.S), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.N), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.N), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
}
use of com.ardor3d.math.Ray3 in project energy3d by concord-consortium.
the class Roof method findRoofIntersection.
private ReadOnlyVector3 findRoofIntersection(final Mesh roofPart, final ReadOnlyVector3 p) {
final PickResults pickResults = new PrimitivePickResults();
PickingUtil.findPick(roofPart, new Ray3(p, Vector3.UNIT_Z), pickResults, false);
if (pickResults.getNumber() > 0) {
return pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0);
} else {
return null;
}
}
use of com.ardor3d.math.Ray3 in project energy3d by concord-consortium.
the class Sensor method drawMesh.
@Override
protected void drawMesh() {
if (container == null) {
return;
}
if (container instanceof Roof) {
final PickResults pickResults = new PrimitivePickResults();
final Ray3 ray = new Ray3(getAbsPoint(0).addLocal(0, 0, 1000), Vector3.NEG_UNIT_Z);
PickingUtil.findPick(container.getRoot(), ray, pickResults, false);
if (pickResults.getNumber() != 0) {
final PickData pickData = pickResults.getPickData(0);
final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
points.get(0).setZ(p.getZ());
final UserData userData = (UserData) ((Spatial) pickData.getTarget()).getUserData();
final int roofPartIndex = userData.getEditPointIndex();
normal = (ReadOnlyVector3) ((Roof) container).getRoofPartsRoot().getChild(roofPartIndex).getUserData();
}
} else {
normal = container.getNormal();
}
updateEditShapes();
final double annotationScale = Scene.getInstance().getAnnotationScale();
// last arg sets close to zero so the sensor doesn't cast shadow
surround.setData(Vector3.ZERO, WIDTH / 2.0 / annotationScale, HEIGHT / 2.0 / annotationScale, 0.02);
surround.updateModelBound();
final FloatBuffer boxVertexBuffer = surround.getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
final FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
final FloatBuffer outlineBuffer = outlineMesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
outlineBuffer.rewind();
textureBuffer.rewind();
int i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(1);
textureBuffer.put(0).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
mesh.updateModelBound();
outlineMesh.updateModelBound();
mesh.setTranslation(getAbsPoint(0));
if (normal != null) {
// FIXME: Sometimes normal is null
if (Util.isEqual(normal, Vector3.UNIT_Z)) {
mesh.setRotation(new Matrix3());
} else {
mesh.setRotation(new Matrix3().lookAt(normal, Vector3.UNIT_Z));
}
}
surround.setTranslation(mesh.getTranslation());
surround.setRotation(mesh.getRotation());
outlineMesh.setTranslation(mesh.getTranslation());
outlineMesh.setRotation(mesh.getRotation());
final ReadOnlyVector3 translation = mesh.getTranslation();
label.setText("" + getId());
if (normal != null) {
final double labelOffset = 1.0;
label.setTranslation(translation.getX() + labelOffset * normal.getX(), translation.getY() + labelOffset * normal.getY(), translation.getZ() + labelOffset * normal.getZ());
}
}
use of com.ardor3d.math.Ray3 in project energy3d by concord-consortium.
the class NodeWorker method reach.
// If a ray in the direction of the normal of this mesh doesn't hit anything, it is considered as an exterior face of a twin mesh. Otherwise, it is considered as the interior face.
private static void reach(final Mesh mesh, final List<Spatial> collidables) {
final UserData userData = (UserData) mesh.getUserData();
final ReadOnlyVector3 normal = userData.getRotatedNormal() == null ? userData.getNormal() : userData.getRotatedNormal();
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
final List<ReadOnlyVector3> vertices = new ArrayList<ReadOnlyVector3>(vertexBuffer.limit() / 3);
while (vertexBuffer.hasRemaining()) {
vertices.add(mesh.localToWorld(new Vector3(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get()), null));
}
final Vector3 p = new Vector3();
// use only the center
// for (final ReadOnlyVector3 v : vertices) {
// p.addLocal(v);
// }
// p.multiplyLocal(1.0 / vertices.size());
// check if the centers of the triangles can be reached, if one can, then the entire mesh is considered as an exterior face
boolean reachable = false;
final PickResults pickResults = new PrimitivePickResults();
// assuming triangular meshes
final int n = vertices.size() / 3;
for (int i = 0; i < n; i++) {
// get the center of the triangle
p.zero();
p.addLocal(vertices.get(3 * i));
p.addLocal(vertices.get(3 * i + 1));
p.addLocal(vertices.get(3 * i + 2));
p.multiplyLocal(1.0 / 3.0);
// we must apply the offset transfer as these points come from the vertex buffer that is not affected by the translation definition of the mesh
// p.addLocal(normal.multiply(node.getMeshThickness(), null));
// detect collision
pickResults.clear();
final Ray3 pickRay = new Ray3(p, normal);
for (final Spatial spatial : collidables) {
if (spatial != mesh) {
PickingUtil.findPick(spatial, pickRay, pickResults, false);
if (pickResults.getNumber() != 0) {
break;
}
}
}
if (pickResults.getNumber() == 0) {
reachable = true;
break;
}
}
userData.setReachable(reachable);
}
Aggregations