本文整理汇总了Java中com.sun.j3d.utils.geometry.NormalGenerator.generateNormals方法的典型用法代码示例。如果您正苦于以下问题:Java NormalGenerator.generateNormals方法的具体用法?Java NormalGenerator.generateNormals怎么用?Java NormalGenerator.generateNormals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.j3d.utils.geometry.NormalGenerator
的用法示例。
在下文中一共展示了NormalGenerator.generateNormals方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例4: 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);
}
示例5: 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);
}