javascript - WebGL How to render simple 3D triangle -


what want do:

render triangle (x, y, z) points:

var v1 = new three.vector3(0, 0, 0); var v2 = new three.vector3(600, 0, 0); var v3 = new three.vector3(300, 0, 600); var v4 = new three.vector3(300, 600, 300); 

what tried , not work:

    <html>     <head>     <title>my first three.js app</title>     <style>         canvas {             width: 100%;             height: 100%;         }     </style>     <!-- <script src="../../scripts/three.min.js"></script> -->     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>     <script src="https://assignments-dot-udacity-extras.appspot.com/media/js/cs291/three.min.js"></script>     <script src="https://assignments-dot-udacity-extras.appspot.com/media/js/cs291/orbitandpancontrols.js"></script>     </head>     <body>      <div id="container">     <canvas width="846" height="494" style="width: 846px; height: 494px;">    </canvas>     </div>       <script>             ////////////////////////////////////////////////////////////////////////////////     /*global three, window, document*/     var camera, scene, renderer;     var cameracontrols;     var clock = new three.clock();      function fillscene() {         scene = new three.scene();         // triangle mesh         var material, geometry, mesh;         material = new three.meshbasicmaterial({ vertexcolors: three.vertexcolors, side: three.doubleside });         geometry = new three.geometry();         // student: add colored triangle here         var v1 = new three.vector3(0, 0, 0);         var v2 = new three.vector3(600, 0, 0);         var v3 = new three.vector3(300, 0, 600);         var v4 = new three.vector3(300, 600, 300);          geometry.vertices.push(v1);         geometry.vertices.push(v2);         geometry.vertices.push(v3);         geometry.vertices.push(v4);          geometry.faces.push(new three.face3(0, 1, 2, 3));          var color1 = new three.color(0xff0000);         var color2 = new three.color(0x00ff00);         var color3 = new three.color(0x0000ff);         var color4 = new three.color(0x0000ff);          geometry.faces[0].vertexcolors = [color1, color2, color3, color4];         mesh = new three.mesh(geometry, material);         scene.add(mesh);     }      function init() {         var canvaswidth = 846;         var canvasheight = 494;         var canvasratio = canvaswidth / canvasheight;         // renderer         renderer = new three.webglrenderer({ antialias: true });         renderer.gammainput = true;         renderer.gammaoutput = true;         renderer.setsize(canvaswidth, canvasheight);         renderer.setclearcolorhex(0xaaaaaa, 1.0);         // camera         camera = new three.perspectivecamera(55, canvasratio, 1, 4000);         camera.position.set(100, 150, 130);         // controls         console.log(renderer.domelement, three.orbitandpancontrols);         cameracontrols = new three.orbitandpancontrols(camera, renderer.domelement);         cameracontrols.target.set(0, 0, 0);     }      function addtodom() {         var container = document.getelementbyid('container');         var canvas = container.getelementsbytagname('canvas');         if (canvas.length > 0) {             container.removechild(canvas[0]);         }         container.appendchild(renderer.domelement);     }      function animate() {         window.requestanimationframe(animate);         render();     }      function render() {         var delta = clock.getdelta();         cameracontrols.update(delta);         renderer.render(scene, camera);     }      try {         init();         fillscene();         addtodom();         animate();     } catch (e) {         var errorreport =             "your program encountered unrecoverable error, can not draw on canvas. error was:<br/><br/>";         $('#container').append(errorreport + e);     } </script> </body> </html> 

copy/paste code, error:

unhandled exception @ line 30, column 5 in http://localhost:5167/home/index

0x800a1391 - javascript runtime error: 'three' undefined


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -