美文网首页
#2 绘制线条

#2 绘制线条

作者: JamesSawyer | 来源:发表于2018-08-01 14:03 被阅读7次
    // 设置渲染器
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);
    
    // 设置相机
    const camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 1, 500);
    camera.position.set(0,0,100);
    camera.lookAt(new THREE.Vector3(0, 0, 0));
    
    // 创建场景
    const scene = new THREE.Scene();
    
    // 定义材质
    // 对于线条 可以使用 LineBasicMaterial || LineDashedMaterial
    const material = new THREE.LineBasicMaterial({ color: 0x0000ff });
    
    // 添加几何体
    // 添加顶点信息
    // 可以使用 BufferGeometry 性能更好 这里为了简洁使用 Geometry
    const geometry = new THREE.Geometry();
    geometry.vertices.push(new THREE.Vector3(-10, 0, 0));
    geometry.vertices.push(new THREE.Vector3(0, 10, 0));
    geometry.vertices.push(new THREE.Vector3(10, 0, 0));
    
    const line = new THREE.Line(geometry, material);
    
    scene.add(line);
    renderer.render(scene, camera);
    
    绘制线条.png

    相关文章

      网友评论

          本文标题:#2 绘制线条

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