How to repeat the texture map like GL_REPEAT?

2020-02-12 03:59发布

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.

3条回答
啃猪蹄的小仙女
2楼-- · 2020-02-12 04:18

Image must be 8x8, 16x16, 32x32, 128x128, 256x256, 512x512 etc. And all be working. =)

查看更多
该账号已被封号
3楼-- · 2020-02-12 04:30

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...

查看更多
等我变得足够好
4楼-- · 2020-02-12 04:31

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 );      
查看更多
登录 后发表回答