码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2019-02-10 00:03:59      阅读:778      评论:0      收藏:0      [点我收藏+]

标签:图片   技术   three.js   new   sele   head   sel   charset   pre   

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之平面纹理

标签:图片   技术   three.js   new   sele   head   sel   charset   pre   

原文地址:https://www.cnblogs.com/wsfu/p/10358513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!