当前位置: 首页>>代码示例>>Java>>正文


Java GeometryInfo.setTextureCoordinateParams方法代码示例

本文整理汇总了Java中com.sun.j3d.utils.geometry.GeometryInfo.setTextureCoordinateParams方法的典型用法代码示例。如果您正苦于以下问题:Java GeometryInfo.setTextureCoordinateParams方法的具体用法?Java GeometryInfo.setTextureCoordinateParams怎么用?Java GeometryInfo.setTextureCoordinateParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.j3d.utils.geometry.GeometryInfo的用法示例。


在下文中一共展示了GeometryInfo.setTextureCoordinateParams方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAreaGeometry

import com.sun.j3d.utils.geometry.GeometryInfo; //导入方法依赖的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());
	}
}
 
开发者ID:valsr,项目名称:SweetHome3D,代码行数:59,代码来源:Ground3D.java

示例2: addAreaSidesGeometry

import com.sun.j3d.utils.geometry.GeometryInfo; //导入方法依赖的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());
}
 
开发者ID:valsr,项目名称:SweetHome3D,代码行数:52,代码来源:Ground3D.java

示例3: 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;
}
 
开发者ID:valsr,项目名称:SweetHome3D,代码行数:82,代码来源:HomeComponent3D.java

示例4: 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);
}
 
开发者ID:activityworkshop,项目名称:GpsPrune,代码行数:56,代码来源:Java3DWindow.java

示例5: extract

import com.sun.j3d.utils.geometry.GeometryInfo; //导入方法依赖的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);
}
 
开发者ID:nerdouille,项目名称:silvie,代码行数:79,代码来源:CHRModel.java


注:本文中的com.sun.j3d.utils.geometry.GeometryInfo.setTextureCoordinateParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。