Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="viewer_canvas"></div>
              
            
!

CSS

              
                #viewer_canvas {
  float: left;
  width: 640px;
  height: 480px;
}
#scene_canvas {
  float: left;
  width: 640px;
  height: 480px;
}
              
            
!

JS

              
                var scene = new THREE.Scene();
var viewer   = document.getElementById('viewer_canvas');

var camera= new THREE.PerspectiveCamera(70, viewer.offsetWidth / viewer.offsetHeight, 1, 1000);
camera.position.y = 15;

var controls = new THREE.OrbitControls( camera, viewer );
controls.update();

renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(viewer.offsetWidth, viewer.offsetHeight);

viewer.appendChild(renderer.domElement);

var ambientLight = new THREE.AmbientLight(0xffffff , 0.5);
scene.add(ambientLight);

render();

function render() {
    requestAnimationFrame(render);
    controls.update();
    renderer.render(scene, camera);
};

var geometry = new THREE.PlaneBufferGeometry( 20, 20, 4);
geometry.rotateX(90 * (Math.PI / 180));
geometry.translate(0,-0.25,0);
var material = new THREE.MeshBasicMaterial( {color: '#CCCCCC', side: THREE.DoubleSide} );
var plane = new THREE.Mesh( geometry, material );
scene.add( plane );



let shape = {
    width: 10,
    height: 10
}
let segments = 10;
var goal = null;
var joints = [];
var skeleton = {};

generateShape(segments, shape);

function generateShape(segments, shape)
{
    let geometry       = new THREE.BufferGeometry();
    let segment_points = getSegmentPoints(shape.width, segments);
    let vertices       = generateVertices(shape, segment_points);
    let indices        = generateIndices(segments);

    geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(vertices), 3) );
    geometry.setIndex(indices);
  
    console.log('g', geometry);
    
    let material = new THREE.MeshBasicMaterial({color: 'blue', wireframe: false, side: THREE.DoubleSide});
    let mesh     = new THREE.Mesh( geometry, material );

    scene.add(mesh);
}

function getSegmentPoints(shape_width, segments)
{
    let segment_points = [];
    let segment_length = shape_width / segments;
    let origin_x = 0;
    let point = origin_x;

    for (let i = 0; i < segments; i++) {
        point += segment_length;
        segment_points.push(point);
    }

    return segment_points;
}

function generateVertices(shape, segment_points)
{
    let vertices = [];
    let origin = {
        x: 0,
        y: 0,
        z: 0
    }
    let vertex = {
        x: origin.x,
        y: origin.y,
        z: origin.z
    }

    vertices.push(vertex.x);
    vertices.push(vertex.y);
    vertices.push(vertex.z - (shape.height/2));
    vertices.push(vertex.x);
    vertices.push(vertex.y);
    vertices.push(vertex.z + (shape.height/2));

    for (let point of segment_points) {
        vertex.x = point;
        vertices.push(vertex.x);
        vertices.push(vertex.y);
        vertices.push(vertex.z - (shape.height/2));
        vertices.push(vertex.x);
        vertices.push(vertex.y);
        vertices.push(vertex.z + (shape.height/2));
    }

    return vertices;
}

function generateIndices(segments)
{
    let indices = [];

    for (let i = 0; i < segments; i++) {
        let starting_index = i * 2;

        indices.push(starting_index + 1);
        indices.push(starting_index + 3);
        indices.push(starting_index + 0);

        indices.push(starting_index + 2);
        indices.push(starting_index + 0);
        indices.push(starting_index + 3);
    }

    return indices;
}

              
            
!
999px

Console