Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat the texture map like GL_REPEAT?

I have a house model in my game, and I have some materials for the house geometry. There is a material for the wall of the house, and I have a texture-map-image to show the bricks.

var mat = new THREE.MeshPhongMaterial( { 
    ambient: 0x969696,
    map: THREE.ImageUtils.loadTexture( 'textures/G/G0.jpg' ), 
    overdraw: true,combine: THREE.MultiplyOperation 
} );

In this way above, the texture map appears like GL_CLAMP I want it to show like GL_REPEAT.

What should I do?

If you can not see the images check this.

like image 728
user1497753 Avatar asked Jul 03 '12 05:07

user1497753


People also ask

What is opengl texture mapping?

1.0 Introduction. Texture mapping is a process of stretching a texture onto a 3D object; the applied texture will follow the 3D object as it transforms. Texture mapping is fun and beneficial but it can be challenging for beginners. Texture can also be distorted for a visual effect.

What is Gl_repeat used for?

GL_REPEAT : The integer part of the coordinate will be ignored and a repeating pattern is formed. GL_MIRRORED_REPEAT : The texture will also be repeated, but it will be mirrored when the integer part of the coordinate is odd. GL_CLAMP_TO_EDGE : The coordinate will simply be clamped between 0 and 1 .


2 Answers

I have posted a full working example at: http://stemkoski.github.com/Three.js/Texture-Repeat.html

The relevant part of the code example is:

// for example, texture repeated twice in each direction
var lavaTexture = THREE.ImageUtils.loadTexture( 'images/lava.jpg' );
lavaTexture.wrapS = lavaTexture.wrapT = THREE.RepeatWrapping;
lavaTexture.repeat.set( 2, 2 );
var lavaMaterial = new THREE.MeshBasicMaterial( { map: lavaTexture } );
var lavaBall = new THREE.Mesh( THREE.GeometryUtils.clone(sphereGeom), lavaMaterial );
scene.add( lavaBall );      
like image 102
Stemkoski Avatar answered Oct 09 '22 23:10

Stemkoski


It's called THREE.RepeatWrapping there. The loadTexture defaults to THREE.ClampToEdgeWrapping (see ctor function from previous link). Don't know if you can use the callback (because this in JS is a bit weird (looks like it points to the created Image, not the created Texture)). Signature:

loadTexture: function ( path, mapping, callback ) {

Better you just name the texture locally and set the wrap modes manually:

var t = THREE.ImageUtils.loadTexture( 'textures/G/G0.jpg' );
t.wrapS = t.wrapT = THREE.RepeatWrapping;

Looks like you're not going far with threejs without looking at the actual code...

like image 20
Stefan Hanke Avatar answered Oct 09 '22 21:10

Stefan Hanke