List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive
public static boolean[] toPrimitive(final Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null for a null input array.
From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java
private void updateBiomesGeometry() { //biomes//from www.j av a 2 s . c om ArrayList<Vector3f> posList = new ArrayList<>(); ArrayList<Integer> indexList = new ArrayList<>(); ArrayList<ColorRGBA> colorList = new ArrayList<>(); Map<Graph.Corner, Integer> cornerIndices = new HashMap<>(); for (Graph.Center c : graph.centers) { int i = posList.size(); posList.add(new Vector3f(c.location.x, c.location.y, 1)); colorList.add(c.biome.color); cornerIndices.clear(); for (Graph.Corner corner : c.corners) { cornerIndices.put(corner, posList.size()); posList.add(new Vector3f(corner.point.x, corner.point.y, 1)); colorList.add(c.biome.color); } for (Graph.Edge edge : c.borders) { indexList.add(i); indexList.add(cornerIndices.get(edge.v0)); indexList.add(cornerIndices.get(edge.v1)); } } Mesh biomesMesh = new Mesh(); biomesMesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(posList.toArray(new Vector3f[posList.size()]))); biomesMesh.setBuffer(VertexBuffer.Type.Color, 4, BufferUtils.createFloatBuffer(colorList.toArray(new ColorRGBA[colorList.size()]))); biomesMesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils .createIntBuffer(ArrayUtils.toPrimitive(indexList.toArray(new Integer[indexList.size()])))); biomesMesh.setMode(Mesh.Mode.Triangles); biomesMesh.updateCounts(); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setBoolean("VertexColor", true); mat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off); Geometry biomesGeom = new Geometry("biomesGeom", biomesMesh); biomesGeom.setMaterial(mat); biomesNode.detachAllChildren(); biomesNode.attachChild(biomesGeom); LOG.info("biomes geometry updated"); }
From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java
private void updateElevationGeometry() { //biomes/*from w w w . j av a 2 s .c o m*/ ArrayList<Vector3f> posList = new ArrayList<>(); ArrayList<Integer> indexList = new ArrayList<>(); ArrayList<ColorRGBA> colorList = new ArrayList<>(); Map<Graph.Corner, Integer> cornerIndices = new HashMap<>(); for (Graph.Center c : graph.centers) { int i = posList.size(); posList.add(new Vector3f(c.location.x, c.location.y, 1)); if (c.biome == Biome.LAKE || c.biome == Biome.OCEAN) { colorList.add(c.biome.color); } else { colorList.add(new ColorRGBA(Math.max(0, c.elevation * 2 - 1), Math.min(1, c.elevation * 2), Math.max(0, c.elevation * 2 - 1), 1)); } cornerIndices.clear(); for (Graph.Corner corner : c.corners) { cornerIndices.put(corner, posList.size()); posList.add(new Vector3f(corner.point.x, corner.point.y, 1)); if (c.biome == Biome.LAKE || c.biome == Biome.OCEAN) { colorList.add(c.biome.color); } else { colorList.add(new ColorRGBA(Math.max(0, corner.elevation * 2 - 1), Math.min(1, corner.elevation * 2), Math.max(0, corner.elevation * 2 - 1), 1)); } } for (Graph.Edge edge : c.borders) { indexList.add(i); indexList.add(cornerIndices.get(edge.v0)); indexList.add(cornerIndices.get(edge.v1)); } } Mesh elevation = new Mesh(); elevation.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(posList.toArray(new Vector3f[posList.size()]))); elevation.setBuffer(VertexBuffer.Type.Color, 4, BufferUtils.createFloatBuffer(colorList.toArray(new ColorRGBA[colorList.size()]))); elevation.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils .createIntBuffer(ArrayUtils.toPrimitive(indexList.toArray(new Integer[indexList.size()])))); elevation.setMode(Mesh.Mode.Triangles); elevation.updateCounts(); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setBoolean("VertexColor", true); mat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off); Geometry elevationGeom = new Geometry("elevationGeom", elevation); elevationGeom.setMaterial(mat); elevationNode.detachAllChildren(); elevationNode.attachChild(elevationGeom); LOG.info("elevation geometry updated"); }
From source file:org.shaman.terrain.sketch.ControlCurveMesh.java
private void updateSlope() { //buffers//ww w . java 2 s .c om ArrayList<Vector3f> positions = new ArrayList<>(7 * (SLOPE_SAMPLES + 1)); ArrayList<ColorRGBA> colors = new ArrayList<>(13 * (SLOPE_SAMPLES + 1)); ArrayList<Integer> indices = new ArrayList<>(); //create samples ControlPoint[] points = new ControlPoint[SLOPE_SAMPLES + 1]; for (int i = 0; i <= SLOPE_SAMPLES; ++i) { points[i] = curve.interpolate(i / (float) SLOPE_SAMPLES); } ColorRGBA c1 = ColorRGBA.White; ColorRGBA c2 = ColorRGBA.Gray; //add vertices for (int i = 0; i < points.length; ++i) { ControlPoint p = points[i]; Vector3f c = app.mapHeightmapToWorld(p.x, p.y, p.height); float dx, dy; if (i == 0) { dx = points[i + 1].x - points[i].x; dy = points[i + 1].y - points[i].y; } else if (i == points.length - 1) { dx = points[i].x - points[i - 1].x; dy = points[i].y - points[i - 1].y; } else { dx = (points[i + 1].x - points[i - 1].x) / 2f; dy = (points[i + 1].y - points[i - 1].y) / 2f; } float sum = (float) Math.sqrt(dx * dx + dy * dy); dx /= sum; dy /= sum; Vector3f l1 = app.mapHeightmapToWorld(p.x - p.plateau * dy, p.y + p.plateau * dx, p.height); Vector3f r1 = app.mapHeightmapToWorld(p.x + p.plateau * dy, p.y - p.plateau * dx, p.height); Vector3f l2 = app.mapHeightmapToWorld(p.x - (p.plateau + FastMath.cos(p.angle1) * p.extend1) * dy, p.y + (p.plateau + FastMath.cos(p.angle1) * p.extend1) * dx, p.height - FastMath.sin(p.angle1) * p.extend1 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); Vector3f r2 = app.mapHeightmapToWorld(p.x + (p.plateau + FastMath.cos(p.angle2) * p.extend2) * dy, p.y - (p.plateau + FastMath.cos(p.angle2) * p.extend2) * dx, p.height - FastMath.sin(p.angle2) * p.extend2 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); positions.add(c); positions.add(l1); positions.add(l1); positions.add(l2); positions.add(r1); positions.add(r1); positions.add(r2); colors.add(c1); colors.add(c1); colors.add(c2); colors.add(c2); colors.add(c1); colors.add(c2); colors.add(c2); } //add indices for (int i = 0; i < points.length; ++i) { indices.add(7 * i + 0); indices.add(7 * i + 1); indices.add(7 * i + 2); indices.add(7 * i + 3); indices.add(7 * i + 0); indices.add(7 * i + 4); indices.add(7 * i + 5); indices.add(7 * i + 6); if (i < points.length - 1) { indices.add(7 * i + 1); indices.add(7 * i + 1 + 7); indices.add(7 * i + 3); indices.add(7 * i + 3 + 7); indices.add(7 * i + 4); indices.add(7 * i + 4 + 7); indices.add(7 * i + 6); indices.add(7 * i + 6 + 7); } } //set buffers slopeMesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(positions.toArray(new Vector3f[positions.size()]))); slopeMesh.setBuffer(VertexBuffer.Type.Color, 4, BufferUtils.createFloatBuffer(colors.toArray(new ColorRGBA[colors.size()]))); slopeMesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(ArrayUtils.toPrimitive(indices.toArray(new Integer[indices.size()])))); slopeMesh.setMode(Mesh.Mode.Lines); slopeMesh.updateCounts(); }
From source file:org.shaman.terrain.sketch.ControlCurveMesh.java
private void updateSmooth() { //buffers/*from w ww . j av a 2 s. c o m*/ ArrayList<Vector3f> positions = new ArrayList<>(7 * (SLOPE_SAMPLES + 1)); ArrayList<Integer> indices = new ArrayList<>(); //create samples ControlPoint[] points = new ControlPoint[SLOPE_SAMPLES + 1]; for (int i = 0; i <= SLOPE_SAMPLES; ++i) { points[i] = curve.interpolate(i / (float) SLOPE_SAMPLES); } //add vertices for (int i = 0; i < points.length; ++i) { ControlPoint p = points[i]; Vector3f c = app.mapHeightmapToWorld(p.x, p.y, p.height); float dx, dy; if (i == 0) { dx = points[i + 1].x - points[i].x; dy = points[i + 1].y - points[i].y; } else if (i == points.length - 1) { dx = points[i].x - points[i - 1].x; dy = points[i].y - points[i - 1].y; } else { dx = (points[i + 1].x - points[i - 1].x) / 2f; dy = (points[i + 1].y - points[i - 1].y) / 2f; } float sum = (float) Math.sqrt(dx * dx + dy * dy); dx /= sum; dy /= sum; Vector3f l1 = app.mapHeightmapToWorld(p.x - (p.plateau + FastMath.cos(p.angle1) * p.extend1) * dy, p.y + (p.plateau + FastMath.cos(p.angle1) * p.extend1) * dx, p.height - FastMath.sin(p.angle1) * p.extend1 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); Vector3f r1 = app.mapHeightmapToWorld(p.x + (p.plateau + FastMath.cos(p.angle2) * p.extend2) * dy, p.y - (p.plateau + FastMath.cos(p.angle2) * p.extend2) * dx, p.height - FastMath.sin(p.angle2) * p.extend2 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); Vector3f l2 = app.mapHeightmapToWorld( p.x - ((p.plateau + FastMath.cos(p.angle1) * p.extend1) + p.smooth1) * dy, p.y + ((p.plateau + FastMath.cos(p.angle1) * p.extend1) + p.smooth1) * dx, p.height - FastMath.sin(p.angle1) * p.extend1 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); Vector3f r2 = app.mapHeightmapToWorld( p.x + ((p.plateau + FastMath.cos(p.angle2) * p.extend2) + p.smooth2) * dy, p.y - ((p.plateau + FastMath.cos(p.angle2) * p.extend2) + p.smooth2) * dx, p.height - FastMath.sin(p.angle2) * p.extend2 / TerrainHeighmapCreator.HEIGHMAP_HEIGHT_SCALE); positions.add(l1); positions.add(l2); positions.add(r1); positions.add(r2); } //add first and last ControlPoint p = points[0]; float dx = points[1].x - points[0].x; float dy = points[1].y - points[0].y; float sum = (float) Math.sqrt(dx * dx + dy * dy); dx /= sum; dy /= sum; float smooth = (p.smooth1 + p.smooth2) / 2; Vector3f l = app.mapHeightmapToWorld(p.x - p.plateau * dy - smooth * dx, p.y + p.plateau * dx - smooth * dy, p.height); Vector3f r = app.mapHeightmapToWorld(p.x + p.plateau * dy - smooth * dx, p.y - p.plateau * dx - smooth * dy, p.height); positions.add(l); positions.add(r); p = points[points.length - 1]; dx = points[points.length - 1].x - points[points.length - 2].x; dy = points[points.length - 1].y - points[points.length - 2].y; sum = (float) Math.sqrt(dx * dx + dy * dy); dx /= sum; dy /= sum; smooth = (p.smooth1 + p.smooth2) / 2; l = app.mapHeightmapToWorld(p.x - p.plateau * dy + smooth * dx, p.y + p.plateau * dx + smooth * dy, p.height); r = app.mapHeightmapToWorld(p.x + p.plateau * dy + smooth * dx, p.y - p.plateau * dx + smooth * dy, p.height); positions.add(l); positions.add(r); //add indices for (int i = 0; i < points.length; ++i) { indices.add(4 * i + 0); indices.add(4 * i + 1); indices.add(4 * i + 2); indices.add(4 * i + 3); if (i < points.length - 1) { indices.add(4 * i + 1); indices.add(4 * i + 1 + 4); indices.add(4 * i + 3); indices.add(4 * i + 3 + 4); } } indices.add(0); indices.add(positions.size() - 4); indices.add(positions.size() - 4); indices.add(1); indices.add(2); indices.add(positions.size() - 3); indices.add(positions.size() - 3); indices.add(3); indices.add(positions.size() - 4); indices.add(positions.size() - 3); indices.add(positions.size() - 8); indices.add(positions.size() - 2); indices.add(positions.size() - 2); indices.add(positions.size() - 7); indices.add(positions.size() - 6); indices.add(positions.size() - 1); indices.add(positions.size() - 1); indices.add(positions.size() - 5); indices.add(positions.size() - 2); indices.add(positions.size() - 1); //set buffers smoothMesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(positions.toArray(new Vector3f[positions.size()]))); smoothMesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(ArrayUtils.toPrimitive(indices.toArray(new Integer[indices.size()])))); smoothMesh.setMode(Mesh.Mode.Lines); smoothMesh.updateCounts(); }
From source file:org.siphon.common.js.JsTypeUtil.java
private static byte[] parseBinary(Object value) throws UnsupportedConversionException { if (value instanceof byte[]) { return (byte[]) value; } else if (value instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) value); }/* w w w. ja v a 2s .c om*/ if (value instanceof ScriptObjectMirror && ((ScriptObjectMirror) value).isArray()) { value = ((ScriptObjectMirror) value).to(NativeArray.class); } if (value instanceof NativeArray) { NativeArray arr = (NativeArray) value; byte[] r = new byte[JsTypeUtil.getArrayLength(arr)]; for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) { if (arr.get(i) instanceof Byte) { r[i] = (Byte) arr.get(i); } else if (arr.get(i) instanceof Double) { r[i] = ((Double) arr.get(i)).byteValue(); } else if (arr.get(i) instanceof Integer) { r[i] = ((Integer) arr.get(i)).byteValue(); } } return r; } else if (value instanceof String) { Decoder decoder = Base64.getDecoder(); try { return decoder.decode((String) value); } catch (Exception e) { throw new UnsupportedConversionException("cannot parse base64 binary data " + value, e); } } else { throw new UnsupportedConversionException("unkown binary data " + value + " " + value.getClass(), null); } }
From source file:org.siphon.jsmongo.MongoExecutor.java
private byte[] parseBinary(Object value) throws SqlExecutorException { if (value instanceof byte[]) { return (byte[]) value; } else if (value instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) value); }//from w w w .j av a2 s . c o m if (value instanceof ScriptObjectMirror && ((ScriptObjectMirror) value).isArray()) { value = ((ScriptObjectMirror) value).to(NativeArray.class); } if (value instanceof NativeArray) { NativeArray arr = (NativeArray) value; byte[] r = new byte[JsTypeUtil.getArrayLength(arr)]; for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) { if (arr.get(i) instanceof Byte) { r[i] = (Byte) arr.get(i); } else if (arr.get(i) instanceof Double) { r[i] = ((Double) arr.get(i)).byteValue(); } else if (arr.get(i) instanceof Integer) { r[i] = ((Integer) arr.get(i)).byteValue(); } } return r; } else if (value instanceof String) { Decoder decoder = Base64.getDecoder(); try { return decoder.decode((String) value); } catch (Exception e) { throw new SqlExecutorException("cannot parse base64 binary data " + value, e); } } else { throw new SqlExecutorException("unkown binary data " + value + " " + value.getClass()); } }
From source file:org.siphon.jssql.SqlExecutor.java
private byte[] parseBinary(Object value) throws SqlExecutorException { if (JsTypeUtil.isNull(value)) { return null; }/* w ww . jav a2s. c o m*/ if (value instanceof byte[]) { return (byte[]) value; } else if (value instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) value); } if (value instanceof ScriptObjectMirror && ((ScriptObjectMirror) value).isArray()) { value = ((ScriptObjectMirror) value).to(NativeArray.class); } if (value instanceof NativeArray) { NativeArray arr = (NativeArray) value; byte[] r = new byte[JsTypeUtil.getArrayLength(arr)]; for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) { if (arr.get(i) instanceof Byte) { r[i] = (Byte) arr.get(i); } else if (arr.get(i) instanceof Double) { r[i] = ((Double) arr.get(i)).byteValue(); } else if (arr.get(i) instanceof Integer) { r[i] = ((Integer) arr.get(i)).byteValue(); } } return r; } else if (value instanceof String) { Decoder decoder = Base64.getDecoder(); try { return decoder.decode((String) value); } catch (Exception e) { throw new SqlExecutorException("cannot parse base64 binary data " + value, e); } } else { throw new SqlExecutorException("unkown binary data " + value + " " + value.getClass()); } }
From source file:org.spongepowered.lantern.util.DataUtils.java
public static byte[] getByteArray(DataView view, DataQuery query) { Object opt = view.get(query).get(); if (opt instanceof byte[]) { return (byte[]) opt; } else if (opt instanceof Byte[]) { return ArrayUtils.toPrimitive((Byte[]) opt); }/*from ww w. ja v a 2 s. c om*/ throw new IllegalArgumentException("Object is not a byte array: " + opt); }
From source file:org.spongepowered.lantern.util.DataUtils.java
public static int[] getIntArray(DataView view, DataQuery query) { Object opt = view.get(query).get(); if (opt instanceof int[]) { return (int[]) opt; } else if (opt instanceof Integer[]) { return ArrayUtils.toPrimitive((Integer[]) opt); }//w w w. j a v a 2s . c o m throw new IllegalArgumentException("Object is not a int array: " + opt); }
From source file:org.sybila.parasim.model.verification.stl.LinearPredicate.java
private static Distance getLength(Float[] array) { float[] empty = new float[array.length]; Arrays.fill(empty, 0);/*ww w .j av a2 s . co m*/ return EUCLIDEAN_DISTANCE.distance(ArrayUtils.toPrimitive(array), empty); }