public void draw(final Spatial s) { if (s != null) { s.onDraw(this); } }
/** * Create a copy of this spatial. * * @param shareGeometricData * if true, reuse any data fields describing the geometric shape of the spatial, as applicable. * @return the copy as described. */ public Spatial makeCopy(final boolean shareGeometricData) { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat.getSceneHints().set(_sceneHints); spat.setTransform(_localTransform); // copy local render states for (final StateType type : _renderStateList.keySet()) { final RenderState state = _renderStateList.get(type); if (state != null) { spat.setRenderState(state); } } // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }
protected double calculateHandleScale(final InteractManager manager) { final Spatial target = manager.getSpatialTarget(); if (target != null && target.getWorldBound() != null) { final BoundingVolume bound = target.getWorldBound(); final ReadOnlyVector3 trans = target.getWorldTranslation(); return Math.max(AbstractInteractWidget.MIN_SCALE, bound.getRadius() + trans.subtract(bound.getCenter(), _calcVec3A).length()); } return 1.0; }
/** * Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the * screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the * current mesh and all other instances created from this spatial. * * @return an instanced copy of this node */ public Spatial makeInstanced() { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat._sceneHints = _sceneHints; spat.setTransform(_localTransform); // copy local render states spat._renderStateList = _renderStateList; // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }
void applyTo(final Spatial spatial) { spatial.setRenderState(textureState); spatial.setRenderState(blendState); spatial.setRenderState(zBuffState); if (_useBlend) { spatial.getSceneHints().setRenderBucketType(RenderBucketType.PostBucket); } else { spatial.getSceneHints().setRenderBucketType(RenderBucketType.Opaque); } }
/** * Finds a pick using the given ray starting at the scenegraph given as spatial. Results are stored in the given * results value. * * @param spatial * @param ray * @param results * @param ignoreCulled * if true, Spatials with CullHint ALWAYS will be skipped. */ public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results, final boolean ignoreCulled) { if (spatial == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable) || (ignoreCulled && spatial.getSceneHints().getCullHint() == CullHint.Always) || spatial.getWorldBound() == null || !spatial.getWorldBound().intersects(ray)) { return; } if (spatial instanceof Pickable) { results.addPick(ray, (Pickable) spatial); } else if (spatial instanceof Node) { final Node node = (Node) spatial; for (int i = node.getNumberOfChildren() - 1; i >= 0; i--) { findPick(node.getChild(i), ray, results, ignoreCulled); } } }
public void applyTo(final Spatial spat) { spat.setTransform(Transform.IDENTITY); spat.setRotation(getRotation()); spat.setScale(getScale()); spat.setTranslation(getTranslation()); }
/** * * <code>attachChildAt</code> attaches a child to this node at an index. This node becomes the child's parent. The * current number of children maintained is returned. <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. */ public int attachChildAt(final Spatial child, final int index) { if (child != null) { if (child == this || (child instanceof Node && hasAncestor((Node) child))) { throw new IllegalArgumentException("Child is already part of this hierarchy."); } if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); } child.setParent(this); _children.add(index, child); child.markDirty(DirtyType.Attached); if (logger.isLoggable(Level.FINE)) { logger.fine("Child (" + child.getName() + ") attached to this" + " node (" + getName() + ")"); } } } return _children.size(); }
public int compare(final Spatial o1, final Spatial o2) { if (o2.getSceneHints().getOrthoOrder() == o1.getSceneHints().getOrthoOrder()) { return 0; } else if (o2.getSceneHints().getOrthoOrder() < o1.getSceneHints().getOrthoOrder()) { return -1; } else { return 1; } } }
/** * Draw a single Joint using the given world-space joint transform. * * @param jntTransform * our joint transform * @param scene * @param renderer * the Renderer to draw with. */ private static void drawJoint(final Transform jntTransform, final Spatial scene, final Renderer renderer) { final BoundingVolume vol = scene.getWorldBound(); double size = 1.0; if (vol != null) { SkeletalDebugger.measureSphere.setCenter(vol.getCenter()); SkeletalDebugger.measureSphere.setRadius(0); SkeletalDebugger.measureSphere.mergeLocal(vol); size = SkeletalDebugger.BONE_RATIO * SkeletalDebugger.measureSphere.getRadius(); } scene.getWorldTransform().multiply(jntTransform, SkeletalDebugger.spTransform); SkeletalDebugger.spTransform.getMatrix().scale(new Vector3(size, size, size), SkeletalDebugger.spMatrix); SkeletalDebugger.spTransform.setRotation(SkeletalDebugger.spMatrix); SkeletalDebugger.joint.setWorldTransform(SkeletalDebugger.spTransform); SkeletalDebugger.joint.draw(renderer); }
if (spat.getWorldBound() != null) { double rSize; final BoundingVolume vol = spat.getWorldBound(); if (vol != null) { measureBox.setCenter(vol.getCenter()); rods.setTranslation(spat.getWorldBound().getCenter()); rods.setScale(rSize); } else { rods.setTranslation(spat.getWorldTranslation()); rods.setScale(spat.getWorldScale()); rods.setRotation(spat.getWorldRotation()); rods.updateGeometricState(0, false);
caller.setScale(interpolated); break; case LOCAL_TRANSLATION: caller.setTranslation(interpolated); break; case WORLD_SCALE: caller.setWorldScale(interpolated); break; case WORLD_TRANSLATION: caller.setWorldTranslation(interpolated); break; default: caller.setTranslation(interpolated);
public int compare(final Light l1, final Light l2) { final double v1 = getValueFor(l1, _sp.getWorldBound()); final double v2 = getValueFor(l2, _sp.getWorldBound()); final double cmp = v1 - v2; if (0 > cmp) { return 1; } else if (0 < cmp) { return -1; } else { return 0; } } }
/** * Get a property from this spatial, optionally inheriting values from higher in the scenegraph based upon the * {@link PropertyMode} set in our scene hints. * * @param key * property key * @return the found property, cast to T * @throws ClassCastException * if property is not correct type */ public <T> T getProperty(final String key, final T defaultValue) { final PropertyMode mode = getSceneHints().getPropertyMode(); if (mode == PropertyMode.UseOwn) { return getLocalProperty(key, defaultValue); } final Node parent = getParent(); if (mode == PropertyMode.UseParentIfUnset) { if (hasLocalProperty(key)) { return getLocalProperty(key, defaultValue); } return parent != null ? parent.getProperty(key, defaultValue) : defaultValue; } if (mode == PropertyMode.UseOursLast) { if (parent.hasProperty(key)) { return parent.getProperty(key, defaultValue); } return getLocalProperty(key, defaultValue); } return defaultValue; }
/** * @param key * property key * @return true if we have the given key somewhere reachable in the scenegraph, based on our SceneHints. */ public boolean hasProperty(final String key) { final PropertyMode mode = getSceneHints().getPropertyMode(); final boolean hasLocal = hasLocalProperty(key); if (mode == PropertyMode.UseOwn) { return hasLocal; } final Node parent = getParent(); if (mode == PropertyMode.UseParentIfUnset) { return hasLocal || parent != null && parent.hasProperty(key); } if (mode == PropertyMode.UseOursLast) { final boolean parentHasProperty = parent != null && parent.hasProperty(key); return parentHasProperty || hasLocal; } return false; }
if (child != null) { if (recurse) { child.updateWorldBound(true); worldBound.mergeLocal(child.getWorldBound()); if (child.getWorldBound() != null) { worldBound = child.getWorldBound().clone(_worldBound);
private Spatial findChild(final Spatial root, final String key) { if (_spatialCache.containsKey(key)) { return _spatialCache.get(key); } if (key.equals(root.getName())) { _spatialCache.put(key, root); return root; } else if (root instanceof Node) { final Spatial spat = ((Node) root).getChild(key); if (spat != null) { _spatialCache.put(key, spat); return spat; } } return null; }
/** * Interpolates between the given quaternions using the * {@link Quaternion#slerpLocal(ReadOnlyQuaternion, ReadOnlyQuaternion, double)} method. */ @Override protected void interpolate(final ReadOnlyQuaternion from, final ReadOnlyQuaternion to, final double delta, final Spatial caller) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; assert (null != caller) : "parameter 'caller' can not be null"; final Quaternion tempQuat = Quaternion.fetchTempInstance(); tempQuat.slerpLocal(from, to, delta); if (isLocalRotation()) { caller.setRotation(tempQuat); } else { caller.setWorldRotation(tempQuat); } Quaternion.releaseTempInstance(tempQuat); }
/** * Simple utility to turn on / off bounding volume updating on skinned mesh objects in a given scenegraph. * * @param root * the root node on the scenegraph * @param doUpdate * if true, skinned mesh objects will automatically update their model bounds when applying pose. */ public static void setAutoUpdateBounds(final Spatial root, final boolean doUpdate) { root.acceptVisitor(new Visitor() { public void visit(final Spatial spatial) { // we only care about SkinnedMesh if (spatial instanceof SkinnedMesh) { ((SkinnedMesh) spatial).setAutoUpdateSkinBounds(doUpdate); } } }, true); }