重复凹凸贴图

2024-04-23

我正在尝试使用 Three.js r55 将凹凸贴图应用到平面上,以创建一个模糊的感觉表面。

这是我的代码:

var mapHeight = THREE.ImageUtils.loadTexture("images/felt.png");
mapHeight.repeat.set(2, 2);
mapHeight.wrapS = mapHeight.wrapT = THREE.RepeatWrapping;
mapHeight.format = THREE.RGBFormat;

var groundMaterial = new THREE.MeshPhongMaterial({
    ambient: 0x008800, color: 0x008800, specular: 0x888888,
    shininess: 25, bumpMap: mapHeight, bumpScale: 10, metal: false
} );

scene.add(new THREE.Mesh(new THREE.PlaneGeometry(0.3, 0.3), groundMaterial));

请注意我如何将纹理设置为沿 x/y 轴重复两次。然而,我所看到的仅在一个象限中应用纹理:

我希望用夹子/重复包装(或任何它所谓的)来实现这一点,但我已经要求了RepeatWrapping here.

如何让凹凸贴图在平面上正确重复任意次数。


编辑 - 完整代码

我开始制作一个简单的复制案例。这是非常小的,并且再现了下面的图像(从稍微不同的相机角度)。输出具有相同的问题。

<!DOCTYPE html>
<html>
<head>
    <script src="scripts/libs/three.min.js" type="text/javascript"></script>
</head>
<body>
<div id="scene-container"></div>

<script>

    init();

    function init() {
        var camera, scene, renderer;

        scene = new THREE.Scene();
        scene.add( new THREE.AmbientLight( 0x555555 ) );

        var light = new THREE.DirectionalLight( 0x555555 );
        light.position.set( 0, 0, 10 );
        scene.add( light );

        var bumpMapTexture = THREE.ImageUtils.loadTexture( "images/felt.png", undefined, function () {
            requestAnimationFrame( function () {
                // render once texture has loaded
                renderer.render( scene, camera );
            } );
        } );
        bumpMapTexture.repeat.set( 2, 2 );
        bumpMapTexture.wrapS = bumpMapTexture.wrapT = THREE.RepeatWrapping;

        var groundMaterial = new THREE.MeshPhongMaterial( {
            ambient: 0x00AA00,
            color: 0x00AA00,
            bumpMap: bumpMapTexture
        } );

        scene.add( new THREE.Mesh( new THREE.PlaneGeometry( 3, 3 ), groundMaterial ) );

        camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.01, 100000 );
        camera.position.set( 0, 0, 3 );
        camera.lookAt( new THREE.Vector3( 0, 0, 0 ) );

        renderer = new THREE.WebGLRenderer( { antialias: true } );
        renderer.setSize( window.innerWidth, window.innerHeight );//        renderer.render(scene, camera);

        document.getElementById( 'scene-container' ).appendChild( renderer.domElement );
    }

</script>

</body>
</html>

这链接到 Three.js r55(缩小版)。

任何帮助表示赞赏。


如果您希望纹理重复,则其每个维度的像素大小必须是 2 的幂(例如 512 x 256 )。

如果你有弥漫性map and a bumpMap,他们必须有相同的offset/repeat设置。参见示例this https://stackoverflow.com/questions/14371385/can-a-three-js-material-have-separate-repeat-values-for-a-bump-map-and-a-texture/14372235#14372235 answer.

三.js r.55

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

重复凹凸贴图 的相关文章

随机推荐