three.js学习:纹理Texture之平面纹理

Posted wsfu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了three.js学习:纹理Texture之平面纹理相关的知识,希望对你有一定的参考价值。

index.html

技术图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <script src="js/three.min.js"></script>
    <script src="js/stats.min.js"></script>
    <script src="js/tweenjs.min.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<canvas></canvas>
</body>
<script src="js/chapter/chapter6.1.js"></script>
</html>
View Code

chapter6.1.js

var scene, camera, renderer;

function init() {
    //init scene
    scene = new THREE.Scene();

    //init renderer
    var canvas = document.body.querySelector("canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    renderer = new THREE.WebGLRenderer({
        canvas: canvas,
        antialias: true
    });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0x000000, 1);

    //init camera
    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
    camera.position.set(0, 0, 100);
    camera.up.set(0, 1, 0);
    camera.lookAt(0, 0, 0);

    //init light
    var light = new THREE.PointLight(0xffffff);
    light.position.set(0, 0, 100);
    scene.add(light);

    var geometry = new THREE.PlaneGeometry(60, 30);
    var texture = new THREE.TextureLoader().load("images/a.jpg");
    var material = new THREE.MeshLambertMaterial({
        map: texture,
        side: THREE.DoubleSide
    });
    var mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);
}

function animate() {
//不是很明白为什么设置纹理需要用requestAnimationFrame requestAnimationFrame(animate); renderer.render(scene, camera); } init(); animate();

 


以上是关于three.js学习:纹理Texture之平面纹理的主要内容,如果未能解决你的问题,请参考以下文章

使用vue学习three.js之加载和使用纹理- 通过设置纹理的wrapSwrapTrepeat属性实现纹理的重复平铺,纹理的重复映射

three.js 纹理未显示且为黑色

three.js 改变材质上的纹理

使用vue学习three.js之加载和使用纹理-加载DDSPVRTGA格式的纹理,使用纹理材质创建模型

Three.js 从图像文件创建纹理

动画 GIF 作为 THREE.js 中的纹理