protected Mesh createSelectionMesh() { final Mesh mesh = new Mesh("selectionMesh"); mesh.setRenderMaterial("ui/untextured/default_color.yaml"); final MeshData mData = mesh.getMeshData(); mData.setVertexBuffer(BufferUtils.createVector3Buffer(6)); mData.setIndexMode(IndexMode.Triangles); final BlendState blend = new BlendState(); blend.setBlendEnabled(true); blend.setSourceFunction(SourceFunction.SourceAlpha); blend.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha); mesh.setRenderState(blend); mesh.updateWorldRenderStates(false); mesh.setDefaultColor(ColorRGBA.LIGHT_GRAY); return mesh; }
public void draw(final Renderer renderer, final ReadOnlyTransform xform) { if (getSelectionLength() == 0) { return; } // set our alpha final ColorRGBA color = ColorRGBA.fetchTempInstance(); color.set(_standin.getDefaultColor()).setAlpha(UIComponent.getCurrentOpacity()); _standin.setDefaultColor(color); ColorRGBA.releaseTempInstance(color); // set our location _standin.setWorldTransform(xform); // draw _standin.render(renderer); }
public Spatial copy(final Spatial source, final AtomicBoolean recurse) { recurse.set(false); if (source instanceof Node) { recurse.set(true); return clone((Node) source); } else if (source instanceof Mesh) { final Mesh result = clone((Mesh) source); result.setMeshData(((Mesh) source).getMeshData()); result.updateModelBound(); return result; } return null; }
@Override public boolean render(final Renderer renderer) { if (isVisible()) { return render(renderer, getMeshData()); } return false; }
public Mesh getMesh() { final Mesh mesh = new Mesh("combined"); mesh.setMeshData(data); return mesh; }
/** * Sets the local bounding volume for this mesh to the given bounding volume. If autoCompute is true (default, if * not given) then we will modify the given modelBound to fit the current vertices of this mesh. This will also mark * the spatial as having dirty world bounds. * * @param modelBound * the bounding volume * @param autoCompute * if true, update the given modelBound to fit the vertices of this Mesh. */ public void setModelBound(final BoundingVolume modelBound, final boolean autoCompute) { _modelBound = modelBound != null ? modelBound.clone(_modelBound) : null; if (autoCompute) { updateModelBound(); } markDirty(DirtyType.Bounding); }
protected Mesh clone(final Mesh original) { Mesh copy = null; try { copy = original.getClass().newInstance(); } catch (final InstantiationException e) { logger.log(Level.SEVERE, "Could not access final constructor of class " + original.getClass().getCanonicalName(), e); throw new RuntimeException(e); } catch (final IllegalAccessException e) { logger.log(Level.SEVERE, "Could not access final constructor of class " + original.getClass().getCanonicalName(), e); throw new RuntimeException(e); } copy.setName(original.getName() + "_copy"); copy.getSceneHints().set(original.getSceneHints()); copy.setTransform(original.getTransform()); copy.setDefaultColor(original.getDefaultColor()); for (final StateType type : StateType.values()) { final RenderState state = original.getLocalRenderState(type); if (state != null) { copy.setRenderState(state); } } return copy; }
protected Mesh getFullScreenQuad() { if (_fsq != null) { return _fsq; } _fsq = new Mesh("fsq"); _fsq.getMeshData().setVertexBuffer(BufferUtils.createFloatBuffer(-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1)); _fsq.getMeshData().setTextureBuffer(BufferUtils.createFloatBuffer(0, 0, 1, 0, 1, 1, 0, 1), 0); _fsq.getMeshData().setIndices(BufferUtils.createIndexBufferData(new int[] { 0, 1, 3, 1, 2, 3 }, 3)); _fsq.getSceneHints().setCullHint(CullHint.Never); _fsq.getSceneHints().setLightCombineMode(LightCombineMode.Off); final ZBufferState zState = new ZBufferState(); zState.setEnabled(false); _fsq.setRenderState(zState); _fsq.updateGeometricState(0); return _fsq; }
@Override public void draw(final Renderer r) { final Camera camera = Camera.getCurrentCamera(); boolean anyAlive = false; for (int i = 0; i < _particles.length; i++) { final Particle particle = _particles[i]; if (particle.getStatus() == Particle.Status.Alive) { particle.updateVerts(camera); anyAlive = true; } } // Since we've updated our verts, update the model boundary where applicable if (getParticleGeometry().getWorldBound() != null && anyAlive) { getParticleGeometry().updateModelBound(); } if (!_particlesInWorldCoords) { getParticleGeometry().setWorldTransform(getWorldTransform()); } else { getParticleGeometry().setWorldTranslation(Vector3.ZERO); getParticleGeometry().setWorldRotation(Matrix3.IDENTITY); getParticleGeometry().setWorldScale(getWorldScale()); } getParticleGeometry().draw(r); }
final Md2Frame frame = frames[i]; meshes[i] = new Mesh(frames[i].name); mData = meshes[i].getMeshData(); mData.setIndexLengths(counts); mData.setIndexModes(modes); final Mesh mesh = meshes[0].makeCopy(false); mesh.setModelBound(new BoundingBox()); mesh.setName(resource.getName()); mesh.addController(controller); controller.setMorphingMesh(mesh); controller.setInterpTex(false); final TextureState ts = new TextureState(); ts.setTexture(tex); mesh.setRenderState(ts);
public AreaEntry(final int maxSamples, final StatType type) { this.maxSamples = maxSamples; area = new Mesh("a"); area.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(maxSamples * 2)); area.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); area.getMeshData().setIndexMode(IndexMode.LineStrip); area.setDefaultColor(getColorConfig(type, ConfigKeys.Color.name(), new ColorRGBA(ColorRGBA.LIGHT_GRAY))); if (!getBooleanConfig(type, ConfigKeys.ShowAreas.name(), true)) { area.getSceneHints().setCullHint(CullHint.Always); } } }
private void setupTable(final Mesh mesh) { _lookupTable = new int[mesh.getMeshData().getVertexCount()]; for (int x = 0; x < _lookupTable.length; x++) { _lookupTable[x] = x; } }
public void draw(final Renderer renderer, final UIComponent comp, final int height, final double xOffset, final double yOffset) { final long curr = System.currentTimeMillis(); if (curr - _lastBlink > _blinkInterval) { _lastBlink = curr; _show = !_show; comp.fireComponentDirty(); } if (!_show) { return; } final Vector3 v = Vector3.fetchTempInstance(); v.set(getPosX() + xOffset, getPosY() + yOffset, 0); final Transform t = Transform.fetchTempInstance(); t.set(comp.getWorldTransform()); t.applyForwardVector(v); t.translate(v); Vector3.releaseTempInstance(v); _strip.setWorldTransform(t); Transform.releaseTempInstance(t); _strip.setWorldScale(1, _strip.getWorldScale().getY() * height, 0); _strip.render(renderer); }
public void update(final double time, final Spatial caller) { if (_target == null) { return; } final ColorRGBA color = ColorRGBA.fetchTempInstance().set(_target.getDefaultColor()); float alpha = color.getAlpha(); alpha += _rate * time; if (_dir && alpha <= _targetAlpha) { alpha = _targetAlpha; } else if (!_dir && alpha >= _targetAlpha) { alpha = _targetAlpha; } if (alpha != 0) { _target.getSceneHints().setCullHint(CullHint.Inherit); } else { _target.getSceneHints().setCullHint(CullHint.Always); } color.setAlpha(alpha); _target.setDefaultColor(color); ColorRGBA.releaseTempInstance(color); if (alpha == _targetAlpha) { _target.removeController(this); // enable gc _target = null; } }
public void apply(final Renderable renderable) { if (renderable instanceof Mesh) { final Mesh mesh = (Mesh) renderable; isVisible = mesh.isVisible(); if (!mesh.getSceneHints().isCastsShadows()) { mesh.setVisible(false); } cullState = (CullState) mesh.getWorldRenderState(StateType.Cull); if (cullState != null) { cullFace = cullState.getCullFace(); if (cullFace != Face.None) { cullState.setCullFace(Face.Front); } } } }
public void visit(final Spatial spatial) { if (spatial instanceof Mesh) { ((Mesh) spatial).updateModelBound(); } } }
@Override public void read(final InputCapsule capsule) throws IOException { super.read(capsule); _sideLength = capsule.readInt("sideLength", 0); } }
@Override public void write(final OutputCapsule capsule) throws IOException { super.write(capsule); capsule.write(_sideLength, "sideLength", 0); }
/** * This function checks for intersection between this mesh and the given one. On the first intersection, true is * returned. * * @param toCheck * The intersection testing mesh. * @return True if they intersect. */ public static boolean hasPrimitiveCollision(final Mesh testMesh, final Mesh toCheck) { if (!testMesh.getSceneHints().isPickingHintEnabled(PickingHint.Collidable) || !toCheck.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) { return false; } final CollisionTree thisCT = CollisionTreeManager.getInstance().getCollisionTree(testMesh); final CollisionTree checkCT = CollisionTreeManager.getInstance().getCollisionTree(toCheck); if (thisCT == null || checkCT == null) { return false; } final ReadOnlyTransform worldTransform = testMesh.getWorldTransform(); thisCT.getBounds().transform(worldTransform, thisCT.getWorldBounds()); return thisCT.intersect(checkCT); }