Here, i have a Geometry(pyramid) with four vertices and 4 faces -
var geom = new THREE.Geometry();
geom.vertices.push(new THREE.Vector3(0,100,0), new THREE.Vector3(-100,-100,100), new THREE.Vector3(0,-100,-100), new THREE.Vector3(100,-100,100));
geom.faces.push( new THREE.Face3( 0, 2, 1), new THREE.Face3( 0, 1, 3), new THREE.Face3( 0, 3, 2), new THREE.Face3( 1, 2, 3) );
geom.computeFaceNormals();
Here is my RawShaderMaterial -
var geomMaterial = new THREE.RawShaderMaterial({
vertexShader: [
'precision highp float;',
'precision highp int;',
'uniform mat4 modelViewMatrix;',
'uniform mat4 projectionMatrix;',
'attribute vec3 position;',
'attribute vec2 uv;',
'varying vec2 interpolatedUV;',
'void main() {',
'interpolatedUV = uv;',
'gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);',
'}'
].join('\n'),
fragmentShader: [
'precision highp float;',
'precision highp int;',
'uniform sampler2D texSampler;',
'varying vec2 interpolatedUV;',
'void main() {',
'gl_FragColor = texture2D(texSampler, interpolatedUV);',
'}'
].join('\n'),
uniforms: {
texSampler: {
type: 't',
value: new THREE.ImageUtils.loadTexture("images/test.png")
}
}
});
"images/test.png" is accessible from the script. It seems pretty much trivial to me but the texture simply does not show up. All i can see is a white pyramid.
Can you please tell me what actually went wrong with it?
UPDATE:
After digging around, i have found that i have to provide the UV map for the custom geometry i have created. So i have added it this way -
var uvs = [];
uvs.push(new THREE.Vector2(0.5, 1.0));
uvs.push(new THREE.Vector2(0.5, 0.0));
uvs.push(new THREE.Vector2(0.0, 0.0));
uvs.push(new THREE.Vector2(1.0, 0.0));
geom.faces.push( new THREE.Face3( 0, 2, 1));
geom.faceVertexUvs[0].push(uvs[0], uvs[2], uvs[1]);
geom.faces.push( new THREE.Face3( 0, 1, 3));
geom.faceVertexUvs[0].push(uvs[0], uvs[1], uvs[3]);
geom.faces.push( new THREE.Face3( 0, 3, 2));
geom.faceVertexUvs[0].push(uvs[0], uvs[3], uvs[2]);
geom.faces.push( new THREE.Face3( 1, 2, 3));
geom.faceVertexUvs[0].push(uvs[1], uvs[2], uvs[3]);
But it still shows the white pyramid.And also i am getting this error now -
THREE.BufferAttribute.copyVector2sArray(): vector is undefined 0 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 1 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 2 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 3 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 4 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 5 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 6 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 7 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 8 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 9 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 10 THREE.BufferAttribute.copyVector2sArray(): vector is undefined 11
Any idea about it?