本文整理汇总了Java中com.sun.j3d.utils.geometry.NormalGenerator类的典型用法代码示例。如果您正苦于以下问题:Java NormalGenerator类的具体用法?Java NormalGenerator怎么用?Java NormalGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NormalGenerator类属于com.sun.j3d.utils.geometry包,在下文中一共展示了NormalGenerator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHorizontalPartGeometry
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Returns the geometry of an horizontal part of a wall or a baseboard at <code>y</code>.
*/
private Geometry createHorizontalPartGeometry(float[][] points, float y, boolean reverseOrder, boolean roundWall)
{
Point3f[] coords = new Point3f[points.length];
for (int i = 0; i < points.length; i++)
{
coords[i] = new Point3f(points[i][0], y, points[i][1]);
}
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
geometryInfo.setCoordinates(coords);
geometryInfo.setStripCounts(new int[] { coords.length });
if (reverseOrder)
{
geometryInfo.reverse();
}
// Generate normals
NormalGenerator normalGenerator = new NormalGenerator();
if (roundWall)
{
normalGenerator.setCreaseAngle(0);
}
normalGenerator.generateNormals(geometryInfo);
return geometryInfo.getIndexedGeometryArray();
}
示例2: createTopPartGeometry
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Returns the geometry of the top part of a wall or a baseboard.
*/
private Geometry createTopPartGeometry(float[][] points, double cosWallYawAngle, double sinWallYawAngle,
double topLineAlpha, double topLineBeta, boolean roundWall)
{
Point3f[] coords = new Point3f[points.length];
for (int i = 0; i < points.length; i++)
{
double xTopPointWithZeroYaw = cosWallYawAngle * points[i][0] + sinWallYawAngle * points[i][1];
float topY = (float) (topLineAlpha * xTopPointWithZeroYaw + topLineBeta);
coords[i] = new Point3f(points[i][0], topY, points[i][1]);
}
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
geometryInfo.setCoordinates(coords);
geometryInfo.setStripCounts(new int[] { coords.length });
// Generate normals
NormalGenerator normalGenerator = new NormalGenerator();
if (roundWall)
{
normalGenerator.setCreaseAngle(0);
}
normalGenerator.generateNormals(geometryInfo);
return geometryInfo.getIndexedGeometryArray();
}
示例3: toGeometry
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* @param geometryInfoPrimitive
* @return GeometryArray
*/
public GeometryArray toGeometry(int geometryInfoPrimitive) {
GeometryInfo gi = new GeometryInfo(geometryInfoPrimitive);
gi.setCoordinates(toArray(new Point3d[] {}));
gi.setStripCounts(new int[] { size() });
// Noch ein paar Beschwoerungsformeln, weiss der Henker warum
new NormalGenerator().generateNormals(gi);
gi.recomputeIndices();
new Stripifier().stripify(gi);
gi.recomputeIndices();
return gi.getGeometryArray();
}
示例4: createLine
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Erzeugt eine Linie auf dem Boden Alle Postionen sind keine
* Weltkoordinaten, sondern ganzen Einheiten, wie sie aus dem ASCII-File
* kommen
*
* @param x
* Position in X-Richtung
* @param y
* Position in Y-Richtung
* @param points
* Punkte der Linie
* @param appearance
* Art der Linie
*/
private void createLine(int x, int y, float[] points, Appearance appearance) {
// zwei Polygone (Deckel und Boden) mit N Ecken
float[] p = new float[points.length];
int stripCounts[] = { points.length / 3 };
// Zaehler
int n = 0;
for (n = 0; n < points.length; n++) {
p[n] = points[n] * parcours.getBlockSizeInM();
}
createFloor(x, y, getAppearance(' '));
// Polygone in darstellbare Form umwandeln
GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
gi.setCoordinates(p);
gi.setStripCounts(stripCounts);
NormalGenerator ng = new NormalGenerator();
ng.generateNormals(gi);
gi.recomputeIndices();
Stripifier st = new Stripifier();
st.stripify(gi);
gi.recomputeIndices();
// Hinzufuegen der Ober- und Unterseite des Linien-Shape3D
Shape3D ls = new Shape3D();
ls.addGeometry(gi.getGeometryArray());
ls.setAppearance(appearance);
parcours.addFloor(ls, x + 0.5f, y + 0.5f, 0.002f);
}
示例5: getBody
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
private Shape3D getBody(Point3f[] pointArr) {
GeometryInfo ginfo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
ginfo.setCoordinates(pointArr);
NormalGenerator n = new NormalGenerator();
n.generateNormals(ginfo);
QuadArray quadArray = (QuadArray) ginfo.getGeometryArray();
return new Shape3D(quadArray);
}
示例6: addAreaGeometry
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Adds to ground shape the geometry matching the given area.
*/
private void addAreaGeometry(Shape3D groundShape, HomeTexture groundTexture, Area area, float elevation)
{
List<float[][]> areaPoints = getAreaPoints(area, 1, false);
if (!areaPoints.isEmpty())
{
int vertexCount = 0;
int[] stripCounts = new int[areaPoints.size()];
for (int i = 0; i < stripCounts.length; i++)
{
stripCounts[i] = areaPoints.get(i).length;
vertexCount += stripCounts[i];
}
Point3f[] geometryCoords = new Point3f[vertexCount];
TexCoord2f[] geometryTextureCoords = groundTexture != null ? new TexCoord2f[vertexCount] : null;
float textureWidth;
float textureHeight;
if (groundTexture != null)
{
textureWidth = TextureManager.getInstance().getRotatedTextureWidth(groundTexture);
textureHeight = TextureManager.getInstance().getRotatedTextureHeight(groundTexture);
}
else
{
textureWidth = 0;
textureHeight = 0;
}
int j = 0;
for (float[][] areaPartPoints : areaPoints)
{
for (int i = 0; i < areaPartPoints.length; i++, j++)
{
float[] point = areaPartPoints[i];
geometryCoords[j] = new Point3f(point[0], elevation, point[1]);
if (groundTexture != null)
{
geometryTextureCoords[j] = new TexCoord2f((point[0] - this.originX) / textureWidth,
(this.originY - point[1]) / textureHeight);
}
}
}
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
geometryInfo.setCoordinates(geometryCoords);
if (groundTexture != null)
{
geometryInfo.setTextureCoordinateParams(1, 2);
geometryInfo.setTextureCoordinates(0, geometryTextureCoords);
}
geometryInfo.setStripCounts(stripCounts);
new NormalGenerator(0).generateNormals(geometryInfo);
groundShape.addGeometry(geometryInfo.getIndexedGeometryArray());
}
}
示例7: addAreaSidesGeometry
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Adds to ground shape the geometry matching the given area sides.
*/
private void addAreaSidesGeometry(Shape3D groundShape, HomeTexture groundTexture, float[][] areaPoints,
float elevation, float sideHeight)
{
Point3f[] geometryCoords = new Point3f[areaPoints.length * 4];
TexCoord2f[] geometryTextureCoords = groundTexture != null ? new TexCoord2f[geometryCoords.length] : null;
float textureWidth;
float textureHeight;
if (groundTexture != null)
{
textureWidth = TextureManager.getInstance().getRotatedTextureWidth(groundTexture);
textureHeight = TextureManager.getInstance().getRotatedTextureHeight(groundTexture);
}
else
{
textureWidth = 0;
textureHeight = 0;
}
for (int i = 0, j = 0; i < areaPoints.length; i++)
{
float[] point = areaPoints[i];
float[] nextPoint = areaPoints[i < areaPoints.length - 1 ? i + 1 : 0];
geometryCoords[j++] = new Point3f(point[0], elevation, point[1]);
geometryCoords[j++] = new Point3f(point[0], elevation + sideHeight, point[1]);
geometryCoords[j++] = new Point3f(nextPoint[0], elevation + sideHeight, nextPoint[1]);
geometryCoords[j++] = new Point3f(nextPoint[0], elevation, nextPoint[1]);
if (groundTexture != null)
{
float distance = (float) Point2D.distance(point[0], point[1], nextPoint[0], nextPoint[1]);
geometryTextureCoords[j - 4] = new TexCoord2f(point[0] / textureWidth, elevation / textureHeight);
geometryTextureCoords[j - 3] = new TexCoord2f(point[0] / textureWidth,
(elevation + sideHeight) / textureHeight);
geometryTextureCoords[j - 2] = new TexCoord2f((point[0] - distance) / textureWidth,
(elevation + sideHeight) / textureHeight);
geometryTextureCoords[j - 1] = new TexCoord2f((point[0] - distance) / textureWidth,
elevation / textureHeight);
}
}
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geometryInfo.setCoordinates(geometryCoords);
if (groundTexture != null)
{
geometryInfo.setTextureCoordinateParams(1, 2);
geometryInfo.setTextureCoordinates(0, geometryTextureCoords);
}
new NormalGenerator(0).generateNormals(geometryInfo);
groundShape.addGeometry(geometryInfo.getIndexedGeometryArray());
}
示例8: createTerrain
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
/**
* Create a java3d Shape for the terrain
* @param inModel threedModel
* @param inHelper terrain helper
* @param inBaseImage base image for shape, or null for no image
* @return Shape3D object
*/
private static Shape3D createTerrain(ThreeDModel inModel, TerrainHelper inHelper, GroutedImage inBaseImage)
{
final int numNodes = inHelper.getGridSize();
final int RESULT_SIZE = numNodes * (numNodes * 2 - 2);
int[] stripData = inHelper.getStripLengths();
// Get the scaled terrainTrack coordinates (or just heights) from the model
final int nSquared = numNodes * numNodes;
Point3d[] rawPoints = new Point3d[nSquared];
for (int i=0; i<nSquared; i++)
{
double height = inModel.getScaledTerrainValue(i) * MODEL_SCALE_FACTOR;
rawPoints[i] = new Point3d(inModel.getScaledTerrainHorizValue(i) * MODEL_SCALE_FACTOR,
Math.max(height, 0.05), // make sure it's above the box
-inModel.getScaledTerrainVertValue(i) * MODEL_SCALE_FACTOR);
}
GeometryInfo gi = new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
gi.setCoordinates(inHelper.getTerrainCoordinates(rawPoints));
gi.setStripCounts(stripData);
Appearance tAppearance = new Appearance();
if (inBaseImage != null)
{
gi.setTextureCoordinateParams(1, 2); // one coord set of two dimensions
gi.setTextureCoordinates(0, inHelper.getTextureCoordinates());
Texture mapImage = new TextureLoader(inBaseImage.getImage()).getTexture();
tAppearance.setTexture(mapImage);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
tAppearance.setTextureAttributes(texAttr);
}
else
{
Color3f[] colours = new Color3f[RESULT_SIZE];
Color3f terrainColour = new Color3f(0.1f, 0.2f, 0.2f);
for (int i=0; i<RESULT_SIZE; i++) {colours[i] = terrainColour;}
gi.setColors(colours);
}
new NormalGenerator().generateNormals(gi);
Material terrnMat = new Material(new Color3f(0.4f, 0.4f, 0.4f), // ambient colour
new Color3f(0f, 0f, 0f), // emissive (none)
new Color3f(0.8f, 0.8f, 0.8f), // diffuse
new Color3f(0.2f, 0.2f, 0.2f), //specular
30f); // shinyness
tAppearance.setMaterial(terrnMat);
return new Shape3D(gi.getGeometryArray(), tAppearance);
}
示例9: extract
import com.sun.j3d.utils.geometry.NormalGenerator; //导入依赖的package包/类
@Override
public void extract() throws Exception {
/*
* Some models don't work at all (LIFT.CHR and ITEMS.CHR). They seem to
* be incomplete/garbage files that were probably included by mistake
*/
super.extract();
int rootChunkDataSize = super.resourceBytes.length - 2 * DataReader.INT_SIZE;
byte[] rootChunkData = new byte[rootChunkDataSize];
System.arraycopy(super.resourceBytes, 2 * DataReader.INT_SIZE, rootChunkData, 0, rootChunkDataSize);
AbstractChunk rootChunk = new Chunk0x8000(ROOT_CHUNK_ID, rootChunkData);
rootChunk.readContents();
Chunk0x7f01 textureOffsetsChunk = (Chunk0x7f01) rootChunk.getChunksById(TEXTURE_OFFSETS_CHUNK_ID).get(0);
List<AbstractChunk> shapeChunks = rootChunk.getChunksById(SHAPE_CHUNK_ID);
Chunk0x7f04 textureChunk = (Chunk0x7f04) rootChunk.getChunksById(TEXTURE_CHUNK_ID).get(0);
Chunk0x7f05 shapePositionsChunk = (Chunk0x7f05) rootChunk.getChunksById(SHAPE_POSITIONS_CHUNK_ID).get(0);
Chunk0x7f06 shapePositionIdsChunk = (Chunk0x7f06) rootChunk.getChunksById(SHAPE_POSITION_IDS_CHUNK_ID).get(0);
shapePositionIdsChunk.mapPositions(shapePositionsChunk);
List<Point3f> vertexList = new ArrayList<>();
List<Integer> stripCountList = new ArrayList<>();
List<TexCoord2f> texCoordList = new ArrayList<>();
int[] textureOffsets = textureOffsetsChunk.getTextureOffsets();
short[] texturePixelIndices = textureChunk.getTexturePixelIndices();
int textureWidth = textureChunk.getWidth();
int textureHeight = textureChunk.getHeight();
for (AbstractChunk chunk : shapeChunks) {
Chunk0x7f02 shape = (Chunk0x7f02) chunk;
int shapeId = shape.getShapeId();
Polygon[] polygons = shape.getPolygons();
Point3f[] shapeVertices = shape.getVertices();
for (Polygon polygon : polygons) {
int textureOffsetIndex = polygon.getTextureOffsetIndex();
int textureStartPixel = textureOffsets[textureOffsetIndex];
polygon.setPixelSearchStart(textureStartPixel);
polygon.setTexturePixelIndices(texturePixelIndices);
polygon.setTextureWidth(textureWidth);
polygon.decode();
int[] vertexIndices = polygon.getShapeVertexIndices();
// Going backwards, otherwise faces are inside out
for (int i = vertexIndices.length - 1; i >= 0; i--) {
Point3f vertex = (Point3f) shapeVertices[vertexIndices[i]].clone();
vertex.add(shapePositionIdsChunk.getShapePosition(shapeId));
vertexList.add(vertex);
}
Point[] relativeUVs = polygon.getRelativeUVs();
for (int i = relativeUVs.length - 1; i >= 0; i--) {
int texOriginX = textureStartPixel % textureWidth;
int texOriginY = textureStartPixel / textureWidth;
float u = (float) (relativeUVs[i].getX() + texOriginX);
u /= textureWidth;
float v = (float) (relativeUVs[i].getY() + texOriginY);
// The UV 0,0 is at the bottom left
v = textureHeight - v;
v /= textureHeight;
texCoordList.add(new TexCoord2f(u, v));
}
stripCountList.add(polygon.getVerticeCount());
}
}
Point3f[] vertices = vertexList.toArray(new Point3f[vertexList.size()]);
int[] stripCounts = stripCountList.stream().mapToInt(i -> i).toArray();
TexCoord2f[] texCoords = texCoordList.toArray(new TexCoord2f[texCoordList.size()]);
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
geometryInfo.setCoordinates(vertices);
geometryInfo.setStripCounts(stripCounts);
geometryInfo.setTextureCoordinateParams(1, 2);
geometryInfo.setTextureCoordinates(0, texCoords);
Appearance appearence = new Appearance();
TextureLoader textureLoader = new TextureLoader((BufferedImage) textureChunk.getTexture());
appearence.setTexture(textureLoader.getTexture());
NormalGenerator normalGenerator = new NormalGenerator();
normalGenerator.generateNormals(geometryInfo);
Stripifier stripifier = new Stripifier();
stripifier.stripify(geometryInfo);
GeometryArray geometryArray = geometryInfo.getGeometryArray();
this.shape3d = new Shape3D(geometryArray);
this.shape3d.setAppearance(appearence);
}