美文网首页
基础材质

基础材质

作者: Codifier | 来源:发表于2019-11-12 14:15 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Basic Mesh Material</title>
    <script src="../../three-part/threejs/three.js"></script>
    <script src="../../three-part/utils/stats.min.js"></script>
    <script src="../../three-part/utils/dat.gui.min.js"></script>
    <script src="../controls/TrackballControls.js"></script>
    <script src="../util/util.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    init();
    function init() {
        // show FPS
        let stats = initStats();
        // resize
        window.addEventListener('resize', onResize, false);

        let scene = new THREE.Scene();
        let camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.x = -20;
        camera.position.y = 50;
        camera.position.z = 40;
        camera.lookAt(new THREE.Vector3(10, 0, 0));

        let renderer = new THREE.WebGLRenderer();
        renderer.setClearColor(new THREE.Color(0x000000));
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMap.enabled = true;
        document.getElementById("container").appendChild(renderer.domElement);

        // init trackball control
        let trackballControls = initTrackballControls(camera, renderer);
        let clock = new THREE.Clock();

        let groundGeom = new THREE.PlaneGeometry(100, 100, 4, 4);
        let groundMesh = new THREE.Mesh(groundGeom, new THREE.MeshBasicMaterial({
            color: 0x777777
        }));
        groundMesh.rotation.x = -Math.PI / 2;
        groundMesh.position.y = -20;
        scene.add(groundMesh);

        let cubeGeometry = new THREE.BoxGeometry(15, 15, 15);

        let meshMaterial = new THREE.MeshBasicMaterial({
            color: 0x7777ff,
            name: 'Basic Material',
            // Define whether the material is rendered with flat shading. Default is false.
            flatShading: true
        });

        let cube = new THREE.Mesh(cubeGeometry, meshMaterial);
        cube.position.set(0, 3, 2);
        scene.add(cube);

        // add ambient light
        let ambientLight = new THREE.AmbientLight(0x0c0c0c);
        scene.add(ambientLight);

        // add spotlight
        let spotLight = new THREE.SpotLight(0xffffff);
        spotLight.position.set(-40, 60, -10);
        spotLight.castShadow = true;
        scene.add(spotLight);

        // attributes which can be modified in GUI
        const controls = {
            "color" : meshMaterial.color.getStyle()
        };
        // init GUI
        initGUI();

        renderScene();

        function initGUI(){
            let gui = new dat.GUI();

            gui.addColor(controls, 'color').onChange(function (e) {
                meshMaterial.color.setStyle(e);
            });
        }

        function onResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        }

        function renderScene(){
            trackballControls.update(clock.getDelta());
            stats.update();
            requestAnimationFrame(renderScene);
            renderer.render(scene, camera);
        }
    }
</script>
</body>
</html>

运行结果:


相关文章

  • three.js(35)-金属材质

    常用材质 点材质PointsMaterial线材质LineBasicMaterial:线基础材质LineDashe...

  • 基础材质

    运行结果:

  • 2020-03-17 修改模型颜色

    场景:客户可以自行修改物体的颜色,材质常见材质包括: 1、基础材质 MeshBasicMaterial : 对光照...

  • OpenGLES5-光照

    光照基础 环境光照 漫反射光照 镜面光照 光照特性 材质属性 泛射材质 漫反射材质 镜面反射材质 发射材质 光照计...

  • C4D Octane笔记

    基础材质与材质通道材质分类: 一、漫射材质 1.漫射: 普通颜色,创建出来以后,材质的亮度比较高,一定要降一下,到...

  • 基础篇-材质

    Material(材质) 先说一下纹理与材质的区别: 纹理更偏向于“图”,而材质更偏向于“属性”。 打个比方说,对...

  • Thearender2渲染器学习笔记之七

    【前言】 材质研究。上两篇研究了Thea 的BASIC基础材质。它主要模拟哑光和塑料材质,其次也能简单模拟...

  • Thearender2渲染器学习笔记之六

    【前言】 上一篇重点介绍了Thea的五大基本材质之一:BASIC材质及其相关属性。BASIC基础材质相当于其...

  • 132 粒子信息节点

    创建一个无光环境,为球体添加粒子系统,渲染改为物体 基础材质,大球改为纯金属光滑材质,镜面材质 小球添加自发光,+...

  • 6 车充 3

    海报合成参考图片 产品先建个大概 材质分层 整体材质调整 加一点凹凸 凹凸纹理和发光 科技电路 基础材质 加发光电...

网友评论

      本文标题:基础材质

      本文链接:https://www.haomeiwen.com/subject/bptqictx.html