I am trying to apply texture on my object. But I am getting no texture applied but just colored plane surface on object means if there is wood texture image that I am applying then it just takes color of texture like brown not actual texture.
Basic code is like below:
var loader = new THREE.STLLoader();
var newMaterial = new THREE.MeshPhongMaterial( { color: colorValue, specular: 0xffffff, shininess: 100 } );
loader.load( './models/stl/binary/'+top, function ( newGeometry ) {
newMesh = new THREE.Mesh( newGeometry, newMaterial );
newMesh.position.set( 0,0.6, 0 );
newMesh.rotation.set(0,0.8,0);
newMesh.scale.set( 0.04, 0.04, 0.04 );
scene.add( newMesh );
I tried following for applying texture:
var newMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 100, map: THREE.ImageUtils.loadTexture( "textures/table/lighttexture.jpg" ),
side: THREE.DoubleSide } );
newMaterial.map.minFilter = THREE.LinearFilter;
Result of above code is same, just color of texture getting applied.
var texture = new THREE.TextureLoader().load( "textures/water.jpg" );
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 4, 4 );
var newMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 100, map: texture } );
Getting ERROR on above code:
Uncaught TypeError: Cannot set property 'wrapS' of undefined
Can anyone please tell me, how should I get the original texture on my object?
EDIT
Texture is working correctly for sphere geometry as in below code.
var sphereGeometry = new THREE.SphereGeometry(1, 10, 10);
var mat = new THREE.MeshPhongMaterial();
mat.map = new THREE.ImageUtils.loadTexture(
"textures/table/lighttexture.jpg");
mat.transparent = true;
mat.side = THREE.DoubleSide;
mat.depthWrite = false;
mat.color = new THREE.Color(0xff0000);
var sphere = new THREE.Mesh(sphereGeometry, mat);
scene.add(sphere);