美文网首页
通过顶点创建网格

通过顶点创建网格

作者: Codifier | 来源:发表于2019-11-07 19:30 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Create a Mesh By Vertexes</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 = -30;
        camera.position.y = 40;
        camera.position.z = 30;
        camera.lookAt(scene.position);

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

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

        let vertices = [
            new THREE.Vector3(1,3,1),
            new THREE.Vector3(1,3,-1),
            new THREE.Vector3(1,-1,1),
            new THREE.Vector3(1,-1,-1),
            new THREE.Vector3(-1,3,-1),
            new THREE.Vector3(-1,3,1),
            new THREE.Vector3(-1,-1,-1),
            new THREE.Vector3(-1,-1,1)
        ];

        let faces = [
            new THREE.Face3(0,2,1),
            new THREE.Face3(2,3,1),
            new THREE.Face3(4,6,5),
            new THREE.Face3(6,7,5),
            new THREE.Face3(4,5,1),
            new THREE.Face3(5,0,1),
            new THREE.Face3(7,6,2),
            new THREE.Face3(6,3,2),
            new THREE.Face3(5,7,0),
            new THREE.Face3(7,2,0),
            new THREE.Face3(1,3,4),
            new THREE.Face3(3,6,4),
        ];

        let geom = new THREE.Geometry();
        geom.vertices = vertices;
        geom.faces = faces;
        geom.computeFaceNormals();

        let material = new THREE.MeshLambertMaterial({
            color : 0xff0000
        });

        let mesh = new THREE.Mesh(geom, material);
        scene.add(mesh);

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

        // add a spot light
        let spotLight = new THREE.SpotLight(0xffffff, 1.2, 150, 120);
        spotLight.position.set(-40, 60, -10);
        spotLight.castShadow = true;
        scene.add(spotLight);


        // attributes which can be modified in GUI
        const controls = {

        };
        // init GUI
        initGUI();

        renderScene();

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

        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>

运行结果:


相关文章

  • 通过顶点创建网格

    运行结果:

  • 网格列表GridView组件的基本使用

    创建 GridView 网格列表的2种方式 通过 GridView.count 实现静态网格布局 通过 GridV...

  • QEM网格简化

    说明 QEM网格简化可以有效的减少复杂网格的顶点数同时保留原网格的拓扑特征,可以自定义减少后的顶点数,是十分重要的...

  • NGUI字体描边

    NGUI的UILabel中实现字体的描边是通过以方形的方式对字体网格顶点偏移一定位置后作为其描边网格。以这种方式描...

  • 编辑模式下其他操作

    网格:切割投影顶点:顶点倒角、合并顶点边:桥接循环边、边线折痕面:交集(切割)、交集(布尔) 吸附:点、边、面、物...

  • 网格

    遵守网格的协议 创建网格

  • Unity对项目性能优化的实现

    1.内容的优化 简化模型 最小化模型网格中的顶点和面的数量,避免复杂的网格。 使用纹理贴图代替复杂的网格 考虑用法...

  • LibGDX图形模块之网格

    网格是一组顶点(和可选的索引)的组合,它们描述了用于渲染的几何图形。 顶点以顶点缓冲对象(VBOs)的形式保存在V...

  • Unity UGUI 文字渐变脚本(多种颜色垂直渐变)

    Unity版本: 2020.3.0f1c1原理:增加Text的网格顶点数量,并设置顶点颜色。说明:此脚本在原有只能...

  • Flutter 基本组件之GridView

    GridView 列表组件 GridView可以创建一个二维网格列表. 构造方法 通过 GridView.buil...

网友评论

      本文标题:通过顶点创建网格

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