2d texture from image
Posted: Thu 3. Dec 2009, 16:33
Hi everyone,
I want to apply a 2d texture (which will be created from some image) to a cube, i created an example like cubeunwrapped.java in tutorials section, but i can't apply the texture to the cube properly. i want to show some image for each face of the cube, i can't understand the setVertexTextureCoordinates method what coordinates i must pass to this function to set an image texture for each face. below is the part of my code which i tried to apply texture to the cube.
final double [][] vertices = new double[][]
{
{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}
};
final int [][] indices = new int [][] {
{ 0, 1, 2, 3 }, { 7, 6, 5, 4 }, { 0, 1, 5, 4 },
{ 1, 2, 6, 5 }, { 2, 3, 7, 6 }, { 3, 0, 4, 7 }
};
final double [][] TextureCoordinates = new double[][] {
{ .25, .5},{ .5, .5},{ .5, .75},{ .25, .75},
{ .25, .5},{ .5, .5},{ .5, .75},{ .25, .75}
};
final IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
ifsf.setVertexCount( 8 );
ifsf.setVertexCoordinates(vertices);
ifsf.setVertexTextureCoordinates(TextureCoordinates);
ifsf.setFaceCount( 6 );
ifsf.setFaceIndices( indices );
ifsf.setGenerateVertexNormals( true );
ifsf.setGenerateEdgesFromFaces( true );
sceneCompParent.setGeometry(ifsf.getGeometry());
Texture2D tex =TextureUtility.createTexture(sceneCompParent.getAppearance(),
"polygonShader",
ImageData.load(Input.getInput("C:/some.jpg")),
false);
tex.setTextureMatrix(MatrixBuilder.euclidean().scale(8).getMatrix());
Thanks for any help,
Kadir Ardıç
I want to apply a 2d texture (which will be created from some image) to a cube, i created an example like cubeunwrapped.java in tutorials section, but i can't apply the texture to the cube properly. i want to show some image for each face of the cube, i can't understand the setVertexTextureCoordinates method what coordinates i must pass to this function to set an image texture for each face. below is the part of my code which i tried to apply texture to the cube.
final double [][] vertices = new double[][]
{
{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}
};
final int [][] indices = new int [][] {
{ 0, 1, 2, 3 }, { 7, 6, 5, 4 }, { 0, 1, 5, 4 },
{ 1, 2, 6, 5 }, { 2, 3, 7, 6 }, { 3, 0, 4, 7 }
};
final double [][] TextureCoordinates = new double[][] {
{ .25, .5},{ .5, .5},{ .5, .75},{ .25, .75},
{ .25, .5},{ .5, .5},{ .5, .75},{ .25, .75}
};
final IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
ifsf.setVertexCount( 8 );
ifsf.setVertexCoordinates(vertices);
ifsf.setVertexTextureCoordinates(TextureCoordinates);
ifsf.setFaceCount( 6 );
ifsf.setFaceIndices( indices );
ifsf.setGenerateVertexNormals( true );
ifsf.setGenerateEdgesFromFaces( true );
sceneCompParent.setGeometry(ifsf.getGeometry());
Texture2D tex =TextureUtility.createTexture(sceneCompParent.getAppearance(),
"polygonShader",
ImageData.load(Input.getInput("C:/some.jpg")),
false);
tex.setTextureMatrix(MatrixBuilder.euclidean().scale(8).getMatrix());
Thanks for any help,
Kadir Ardıç