本文整理汇总了Java中com.sun.j3d.utils.geometry.GeometryInfo.setColors方法的典型用法代码示例。如果您正苦于以下问题:Java GeometryInfo.setColors方法的具体用法?Java GeometryInfo.setColors怎么用?Java GeometryInfo.setColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.j3d.utils.geometry.GeometryInfo
的用法示例。
在下文中一共展示了GeometryInfo.setColors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHalfSphereGeometry
import com.sun.j3d.utils.geometry.GeometryInfo; //导入方法依赖的package包/类
/**
* Returns a half sphere oriented inward and with texture ordinates
* that spread along an hemisphere.
*/
private Geometry createHalfSphereGeometry(boolean top)
{
final int divisionCount = 48;
Point3f[] coords = new Point3f[divisionCount * divisionCount];
TexCoord2f[] textureCoords = top ? new TexCoord2f[divisionCount * divisionCount] : null;
Color3f[] colors = top ? null : new Color3f[divisionCount * divisionCount];
for (int i = 0, k = 0; i < divisionCount; i++)
{
double alpha = i * 2 * Math.PI / divisionCount;
float cosAlpha = (float) Math.cos(alpha);
float sinAlpha = (float) Math.sin(alpha);
double nextAlpha = (i + 1) * 2 * Math.PI / divisionCount;
float cosNextAlpha = (float) Math.cos(nextAlpha);
float sinNextAlpha = (float) Math.sin(nextAlpha);
for (int j = 0; j < divisionCount / 4; j++)
{
double beta = 2 * j * Math.PI / divisionCount;
float cosBeta = (float) Math.cos(beta);
float sinBeta = (float) Math.sin(beta);
// Correct the bottom of the hemisphere to avoid seeing a bottom hemisphere at the horizon
float y = j != 0 ? (top ? sinBeta : -sinBeta) : -0.01f;
double nextBeta = 2 * (j + 1) * Math.PI / divisionCount;
if (!top)
{
nextBeta = -nextBeta;
}
float cosNextBeta = (float) Math.cos(nextBeta);
float sinNextBeta = (float) Math.sin(nextBeta);
if (top)
{
coords[k] = new Point3f(cosAlpha * cosBeta, y, sinAlpha * cosBeta);
textureCoords[k++] = new TexCoord2f((float) i / divisionCount, sinBeta);
coords[k] = new Point3f(cosNextAlpha * cosBeta, y, sinNextAlpha * cosBeta);
textureCoords[k++] = new TexCoord2f((float) (i + 1) / divisionCount, sinBeta);
coords[k] = new Point3f(cosNextAlpha * cosNextBeta, sinNextBeta, sinNextAlpha * cosNextBeta);
textureCoords[k++] = new TexCoord2f((float) (i + 1) / divisionCount, sinNextBeta);
coords[k] = new Point3f(cosAlpha * cosNextBeta, sinNextBeta, sinAlpha * cosNextBeta);
textureCoords[k++] = new TexCoord2f((float) i / divisionCount, sinNextBeta);
}
else
{
coords[k] = new Point3f(cosAlpha * cosBeta, y, sinAlpha * cosBeta);
float color1 = .9f + y * .5f;
colors[k++] = new Color3f(color1, color1, color1);
coords[k] = new Point3f(cosAlpha * cosNextBeta, sinNextBeta, sinAlpha * cosNextBeta);
float color2 = .9f + sinNextBeta * .5f;
colors[k++] = new Color3f(color2, color2, color2);
coords[k] = new Point3f(cosNextAlpha * cosNextBeta, sinNextBeta, sinNextAlpha * cosNextBeta);
colors[k++] = new Color3f(color2, color2, color2);
coords[k] = new Point3f(cosNextAlpha * cosBeta, y, sinNextAlpha * cosBeta);
colors[k++] = new Color3f(color1, color1, color1);
}
}
}
GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geometryInfo.setCoordinates(coords);
if (textureCoords != null)
{
geometryInfo.setTextureCoordinateParams(1, 2);
geometryInfo.setTextureCoordinates(0, textureCoords);
}
if (colors != null)
{
geometryInfo.setColors(colors);
}
geometryInfo.indexify();
geometryInfo.compact();
Geometry halfSphereGeometry = geometryInfo.getIndexedGeometryArray();
return halfSphereGeometry;
}
示例2: createTerrain
import com.sun.j3d.utils.geometry.GeometryInfo; //导入方法依赖的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);
}