private void pickGamePad(Vector2f mouseLoc){ if (lastButton != null) { CollisionResults cresults = pick(cam, mouseLoc, gamepad); for (CollisionResult cr : cresults) { Node n = cr.getGeometry().getParent(); if (n != null && (n instanceof ButtonView)) { String b = ((ButtonView) n).getName().substring("Button:".length()); String name = lastButton.getJoystick().getName().replaceAll(" ", "\\\\ "); String id = lastButton.getLogicalId().replaceAll(" ", "\\\\ "); System.out.println(name + "." + id + "=" + b); return; } } } }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { if (frustums == null) { frustums = new Geometry[CAM_NUMBER]; Vector3f[] points = new Vector3f[8]; for (int i = 0; i < 8; i++) { points[i] = new Vector3f(); } for (int i = 0; i < CAM_NUMBER; i++) { ShadowUtil.updateFrustumPoints2(shadowCams[i], points); frustums[i] = createFrustum(points, i); } } if (frustums[shadowMapIndex].getParent() == null) { ((Node) viewPort.getScenes().get(0)).attachChild(frustums[shadowMapIndex]); } }
|| targetGeometry.getParent() == attachParent && targetGeometry.getLocalTransform().isIdentity()) {
float back_wheel_h = (wheelRadius * 1.7f) - 1f; float front_wheel_h = (wheelRadius * 1.9f) - 1f; player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_fl.center(); box = (BoundingBox) wheel_fl.getModelBound(); player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_br.center(); box = (BoundingBox) wheel_br.getModelBound(); player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false); wheel_bl.center(); box = (BoundingBox) wheel_bl.getModelBound(); player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Node attachParent = attachNode.getParent(); if (attachParent == null || targetGeometry == null || targetGeometry.getParent() == attachParent && targetGeometry.getLocalTransform().isIdentity()) {
Geometry g2 = (Geometry) g.deepClone(); g2.move(5, 0, 0); g.getParent().attachChild(g2);
protected Bone select(Geometry g) { Node parentNode = g.getParent(); if (parent != null) { Bone b = nodeBones.get(parentNode); if (b != null) { selectedNode = parentNode; } return b; } return null; }
protected float calculateEffectiveLayer(Geometry g) { Integer childLayer = g.getUserData(LAYER); float layer = childLayer != null ? (childLayer + 1) : 1; for( Spatial s = g.getParent(); s != null; s = s.getParent() ) { Integer i = s.getUserData(LAYER); // I'm not sure skipping a null layer is right but it's // been this way for a while without obvious issue. It // seems like skipping it might cause two separate objects // with sparse hierarchies to sort incorrectly. I'm // leaving it for now. if (i == null) continue; // Should really base the divisor on the number // of children... since right now if we exceed more // than 10 layers under a parent then we overflow layer = layer * 0.1F; layer += i != null ? (i + 1) : 1; } return layer; }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { if (frustums == null) { frustums = new Geometry[CAM_NUMBER]; Vector3f[] points = new Vector3f[8]; for (int i = 0; i < 8; i++) { points[i] = new Vector3f(); } for (int i = 0; i < CAM_NUMBER; i++) { ShadowUtil.updateFrustumPoints2(shadowCams[i], points); frustums[i] = createFrustum(points, i); } } if (frustums[shadowMapIndex].getParent() == null) { ((Node) viewPort.getScenes().get(0)).attachChild(frustums[shadowMapIndex]); } }
public double getPickDistance(Node rootNode, Vector3D normalToPack, Point3D closestPoint) { results.clear(); rootNode.collideWith(collidable, results); for (CollisionResult collisionResult : results) { Geometry geometry = collisionResult.getGeometry(); String userDataRayCastOpacity = JMERayCollisionAdapter.searchForUserData(geometry.getParent(), JMERayCastOpacity.USER_DATA_FIELD); if (DEBUG) System.out.println("JMERayCollisionAdapter: userDataRayCastOpacity = " + userDataRayCastOpacity); if (JMERayCastOpacity.OPAQUE.toString().equals(userDataRayCastOpacity)) { if (normalToPack != null) { packInSCSCoordinates(collisionResult.getContactNormal(), normalToPack); } if (closestPoint != null) { packInSCSCoordinates(collisionResult.getContactPoint(), closestPoint); } return collisionResult.getDistance(); } } return Double.NaN; }
public double getPickDistance(Node rootNode, Vector3d normalToPack, Point3d closestPoint) { results.clear(); rootNode.collideWith(collidable, results); for (CollisionResult collisionResult : results) { Geometry geometry = collisionResult.getGeometry(); String userDataRayCastOpacity = JMERayCollisionAdapter.searchForUserData(geometry.getParent(), JMERayCastOpacity.USER_DATA_FIELD); if (DEBUG) System.out.println("JMERayCollisionAdapter: userDataRayCastOpacity = " + userDataRayCastOpacity); if (JMERayCastOpacity.OPAQUE.toString().equals(userDataRayCastOpacity)) { if (normalToPack != null) { packInSCSCoordinates(collisionResult.getContactNormal(), normalToPack); } if (closestPoint != null) { packInSCSCoordinates(collisionResult.getContactPoint(), closestPoint); } return collisionResult.getDistance(); } } return Double.NaN; }
private void fixScreen(Spatial device) { List<Spatial> screens = SpatialUtils.getSpatialsByRole(device, "Screen"); if (screens.size() > 0) { Geometry geo = (Geometry) screens.get(0); Node p = geo.getParent(); geo.removeFromParent(); geo = new Geometry("Screen", new Quad(1f, 0.6f)); geo.setUserData("ID", "Screen1"); geo.setUserData("ROLE", "Screen"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Textures/FrontSmartPhone.jpg")); geo.setMaterial(mat); geo.move(-1.4f, 0f, -0.6f); geo.rotate(-FastMath.HALF_PI, 0f, 0f); geo.setLocalScale(Vector3f.UNIT_XYZ.divide(p.getWorldScale())); p.attachChild(geo); setState(State.Success); return; } }
Node parentNode = closest.getGeometry().getParent();
Node parentNode = closest.getGeometry().getParent();
@Override public void runCommand(Application app) { DevicesAppState devicesAppState = app.getStateManager().getState(DevicesAppState.class); Node device = devicesAppState.getDevice(deviceId); if (device != null) { List<Spatial> screens = SpatialUtils.getSpatialsByRole(device, "Screen"); if (screens.size() > 0) { Geometry geo = (Geometry) screens.get(0); Node p = geo.getParent(); geo.removeFromParent(); geo = new Geometry("Screen", new Quad(1f, 0.6f)); geo.setUserData("ID", "Screen1"); geo.setUserData("ROLE", "Screen"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture(imagePath)); geo.setMaterial(mat); geo.move(-1.4f, 0f, -0.6f); geo.rotate(-FastMath.HALF_PI, 0f, 0f); geo.setLocalScale(Vector3f.UNIT_XYZ.divide(p.getWorldScale())); p.attachChild(geo); setState(State.Success); return; } } setState(State.Fail); }
/** * Update the local transform of the attachments node. */ private void updateAttachNode() { Node attachParent = attachNode.getParent(); if (attachParent == null || targetGeometry == null || targetGeometry.getParent() == attachParent && targetGeometry.getLocalTransform().isIdentity()) { /* * The animated meshes are in the same coordinate system as the * attachments node: no further transforms are needed. */ attachNode.setLocalTranslation(modelPos); attachNode.setLocalRotation(modelRot); attachNode.setLocalScale(modelScale); } else { Spatial loopSpatial = targetGeometry; Transform combined = new Transform(modelPos, modelRot, modelScale); /* * Climb the scene graph applying local transforms until the * attachments node's parent is reached. */ while (loopSpatial != attachParent && loopSpatial != null) { Transform localTransform = loopSpatial.getLocalTransform(); combined.combineWithParent(localTransform); loopSpatial = loopSpatial.getParent(); } attachNode.setLocalTransform(combined); } }
FrontEndLevelControl controller = results.getCollision(i).getGeometry().getParent().getParent().getControl(FrontEndLevelControl.class); if (controller != null) {
private void updateInteractiveObjectOnCursor() { // See if we hit a creature/object CollisionResults results = new CollisionResults(); // Convert screen click to 3D position Vector3f click3d = app.getCamera().getWorldCoordinates( new Vector2f(mousePosition.x, mousePosition.y), 0f); Vector3f dir = app.getCamera().getWorldCoordinates( new Vector2f(mousePosition.x, mousePosition.y), 1f).subtractLocal(click3d); // Aim the ray from the mouse spot forwards Ray ray = new Ray(click3d, dir); // Collect intersections between ray and all nodes in results list getWorldHandler().getThingsNode().collideWith(ray, results); // See the results so we see what is going on Node object; for (int i = 0; i < results.size(); i++) { // TODO: Now just creature control, but all interaction objects object = results.getCollision(i).getGeometry().getParent().getParent(); IInteractiveControl control = object.getControl(IInteractiveControl.class); if (control != null) { setInteractiveControl(control); return; } } setInteractiveControl(null); }