Create 3D model of pile with points with Three.js












-2














Im developing an web-app that is supposed to create a 3d model of a gravel pile
from points measured with a laser instrument with three.js. The only problem is the
creating a hull that supposed to be the surface of the pile that includes all points. I already made a pointswarm model with the points and tried to make a hull around it with ConvexBufferGeometry but not all points get included in the hull when using ConvexBufferGeometry. Can someone please point me in the right direction?










share|improve this question






















  • Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
    – Mugen87
    Nov 15 '18 at 15:31










  • I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
    – Pei-turn
    Nov 15 '18 at 17:29










  • Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
    – prisoner849
    Nov 15 '18 at 20:27










  • @prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
    – Pei-turn
    Nov 16 '18 at 6:37










  • @Pei-turn You're welcome :)
    – prisoner849
    Nov 16 '18 at 7:19
















-2














Im developing an web-app that is supposed to create a 3d model of a gravel pile
from points measured with a laser instrument with three.js. The only problem is the
creating a hull that supposed to be the surface of the pile that includes all points. I already made a pointswarm model with the points and tried to make a hull around it with ConvexBufferGeometry but not all points get included in the hull when using ConvexBufferGeometry. Can someone please point me in the right direction?










share|improve this question






















  • Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
    – Mugen87
    Nov 15 '18 at 15:31










  • I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
    – Pei-turn
    Nov 15 '18 at 17:29










  • Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
    – prisoner849
    Nov 15 '18 at 20:27










  • @prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
    – Pei-turn
    Nov 16 '18 at 6:37










  • @Pei-turn You're welcome :)
    – prisoner849
    Nov 16 '18 at 7:19














-2












-2








-2







Im developing an web-app that is supposed to create a 3d model of a gravel pile
from points measured with a laser instrument with three.js. The only problem is the
creating a hull that supposed to be the surface of the pile that includes all points. I already made a pointswarm model with the points and tried to make a hull around it with ConvexBufferGeometry but not all points get included in the hull when using ConvexBufferGeometry. Can someone please point me in the right direction?










share|improve this question













Im developing an web-app that is supposed to create a 3d model of a gravel pile
from points measured with a laser instrument with three.js. The only problem is the
creating a hull that supposed to be the surface of the pile that includes all points. I already made a pointswarm model with the points and tried to make a hull around it with ConvexBufferGeometry but not all points get included in the hull when using ConvexBufferGeometry. Can someone please point me in the right direction?







javascript three.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 13:23









Pei-turnPei-turn

177




177












  • Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
    – Mugen87
    Nov 15 '18 at 15:31










  • I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
    – Pei-turn
    Nov 15 '18 at 17:29










  • Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
    – prisoner849
    Nov 15 '18 at 20:27










  • @prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
    – Pei-turn
    Nov 16 '18 at 6:37










  • @Pei-turn You're welcome :)
    – prisoner849
    Nov 16 '18 at 7:19


















  • Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
    – Mugen87
    Nov 15 '18 at 15:31










  • I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
    – Pei-turn
    Nov 15 '18 at 17:29










  • Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
    – prisoner849
    Nov 15 '18 at 20:27










  • @prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
    – Pei-turn
    Nov 16 '18 at 6:37










  • @Pei-turn You're welcome :)
    – prisoner849
    Nov 16 '18 at 7:19
















Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
– Mugen87
Nov 15 '18 at 15:31




Can you please demonstrate the issue with a live example. ConvexBufferGeometry uses a Quick Hull implementation in order to compute the convex hull for a given set of points. If this is not the case for your data, you have to provide more information so it's possible to investigate the issue.
– Mugen87
Nov 15 '18 at 15:31












I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
– Pei-turn
Nov 15 '18 at 17:29




I can post a sample tomorrow when i am back at work but the problem is just that convexGeometry uses quickhull and quickhull creates the smallest geometry that swallows all points but all points are part of the hull.
– Pei-turn
Nov 15 '18 at 17:29












Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
– prisoner849
Nov 15 '18 at 20:27




Have a look at this forum thread. If it's what you're looking for, I can post it here as an answer.
– prisoner849
Nov 15 '18 at 20:27












@prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
– Pei-turn
Nov 16 '18 at 6:37




@prisoner849 Thanks =D that was exactly what i was looking for. Post it as a answer and i will accept it.
– Pei-turn
Nov 16 '18 at 6:37












@Pei-turn You're welcome :)
– prisoner849
Nov 16 '18 at 7:19




@Pei-turn You're welcome :)
– prisoner849
Nov 16 '18 at 7:19












1 Answer
1






active

oldest

votes


















1














You can try to combine Three.js with Delaunator library for triangulation of your points to make a surface:






var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
camera.position.setScalar(150);
var renderer = new THREE.WebGLRenderer({
antialias: true
});
var canvas = renderer.domElement;
document.body.appendChild(canvas);

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

var light = new THREE.DirectionalLight(0xffffff, 1.5);
light.position.setScalar(100);
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));

var size = { x: 200, y: 200 };
var pointsCount = 1000;
var points3d = ;
for (let i = 0; i < pointsCount; i++) {
let x = THREE.Math.randFloatSpread(size.x);
let z = THREE.Math.randFloatSpread(size.y);
let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
points3d.push(new THREE.Vector3(x, y, z));
}

var geom = new THREE.BufferGeometry().setFromPoints(points3d);
var cloud = new THREE.Points(
geom,
new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
);
scene.add(cloud);

// triangulate by [x, z]
var indexDelaunay = Delaunator.from(
points3d.map(v => {
return [v.x, v.z];
})
);

var meshIndex = ; // delaunay index => three.js index
for (let i = 0; i < indexDelaunay.triangles.length; i++){
meshIndex.push(indexDelaunay.triangles[i]);
}

geom.setIndex(meshIndex); // add three.js index to the existing geometry
geom.computeVertexNormals();
var mesh = new THREE.Mesh(
geom, // re-use the existing geometry
new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
);
scene.add(mesh);

var gui = new dat.GUI();
gui.add(mesh.material, "wireframe");

render();

function resize(renderer) {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}

function render() {
if (resize(renderer)) {
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}

html, body {
height: 100%;
margin: 0;
overflow: hidden;
font-family: Verdana;
}
canvas {
width: 100%;
height: 100%;
display; block;
}

#info{
position: absolute;
margin-left: 10px;
}

a{
color: yellow;
text-decoration: none;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

<!-- https://github.com/mapbox/delaunator -->
<script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

<script src="https://josephg.github.io/noisejs/perlin.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

<div id="info">
<a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
</div>








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320479%2fcreate-3d-model-of-pile-with-points-with-three-js%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can try to combine Three.js with Delaunator library for triangulation of your points to make a surface:






    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
    camera.position.setScalar(150);
    var renderer = new THREE.WebGLRenderer({
    antialias: true
    });
    var canvas = renderer.domElement;
    document.body.appendChild(canvas);

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

    var light = new THREE.DirectionalLight(0xffffff, 1.5);
    light.position.setScalar(100);
    scene.add(light);
    scene.add(new THREE.AmbientLight(0xffffff, 0.5));

    var size = { x: 200, y: 200 };
    var pointsCount = 1000;
    var points3d = ;
    for (let i = 0; i < pointsCount; i++) {
    let x = THREE.Math.randFloatSpread(size.x);
    let z = THREE.Math.randFloatSpread(size.y);
    let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
    points3d.push(new THREE.Vector3(x, y, z));
    }

    var geom = new THREE.BufferGeometry().setFromPoints(points3d);
    var cloud = new THREE.Points(
    geom,
    new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
    );
    scene.add(cloud);

    // triangulate by [x, z]
    var indexDelaunay = Delaunator.from(
    points3d.map(v => {
    return [v.x, v.z];
    })
    );

    var meshIndex = ; // delaunay index => three.js index
    for (let i = 0; i < indexDelaunay.triangles.length; i++){
    meshIndex.push(indexDelaunay.triangles[i]);
    }

    geom.setIndex(meshIndex); // add three.js index to the existing geometry
    geom.computeVertexNormals();
    var mesh = new THREE.Mesh(
    geom, // re-use the existing geometry
    new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
    );
    scene.add(mesh);

    var gui = new dat.GUI();
    gui.add(mesh.material, "wireframe");

    render();

    function resize(renderer) {
    const canvas = renderer.domElement;
    const width = canvas.clientWidth;
    const height = canvas.clientHeight;
    const needResize = canvas.width !== width || canvas.height !== height;
    if (needResize) {
    renderer.setSize(width, height, false);
    }
    return needResize;
    }

    function render() {
    if (resize(renderer)) {
    camera.aspect = canvas.clientWidth / canvas.clientHeight;
    camera.updateProjectionMatrix();
    }
    renderer.render(scene, camera);
    requestAnimationFrame(render);
    }

    html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Verdana;
    }
    canvas {
    width: 100%;
    height: 100%;
    display; block;
    }

    #info{
    position: absolute;
    margin-left: 10px;
    }

    a{
    color: yellow;
    text-decoration: none;
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
    <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

    <!-- https://github.com/mapbox/delaunator -->
    <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

    <script src="https://josephg.github.io/noisejs/perlin.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

    <div id="info">
    <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
    </div>








    share|improve this answer


























      1














      You can try to combine Three.js with Delaunator library for triangulation of your points to make a surface:






      var scene = new THREE.Scene();
      var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
      camera.position.setScalar(150);
      var renderer = new THREE.WebGLRenderer({
      antialias: true
      });
      var canvas = renderer.domElement;
      document.body.appendChild(canvas);

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

      var light = new THREE.DirectionalLight(0xffffff, 1.5);
      light.position.setScalar(100);
      scene.add(light);
      scene.add(new THREE.AmbientLight(0xffffff, 0.5));

      var size = { x: 200, y: 200 };
      var pointsCount = 1000;
      var points3d = ;
      for (let i = 0; i < pointsCount; i++) {
      let x = THREE.Math.randFloatSpread(size.x);
      let z = THREE.Math.randFloatSpread(size.y);
      let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
      points3d.push(new THREE.Vector3(x, y, z));
      }

      var geom = new THREE.BufferGeometry().setFromPoints(points3d);
      var cloud = new THREE.Points(
      geom,
      new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
      );
      scene.add(cloud);

      // triangulate by [x, z]
      var indexDelaunay = Delaunator.from(
      points3d.map(v => {
      return [v.x, v.z];
      })
      );

      var meshIndex = ; // delaunay index => three.js index
      for (let i = 0; i < indexDelaunay.triangles.length; i++){
      meshIndex.push(indexDelaunay.triangles[i]);
      }

      geom.setIndex(meshIndex); // add three.js index to the existing geometry
      geom.computeVertexNormals();
      var mesh = new THREE.Mesh(
      geom, // re-use the existing geometry
      new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
      );
      scene.add(mesh);

      var gui = new dat.GUI();
      gui.add(mesh.material, "wireframe");

      render();

      function resize(renderer) {
      const canvas = renderer.domElement;
      const width = canvas.clientWidth;
      const height = canvas.clientHeight;
      const needResize = canvas.width !== width || canvas.height !== height;
      if (needResize) {
      renderer.setSize(width, height, false);
      }
      return needResize;
      }

      function render() {
      if (resize(renderer)) {
      camera.aspect = canvas.clientWidth / canvas.clientHeight;
      camera.updateProjectionMatrix();
      }
      renderer.render(scene, camera);
      requestAnimationFrame(render);
      }

      html, body {
      height: 100%;
      margin: 0;
      overflow: hidden;
      font-family: Verdana;
      }
      canvas {
      width: 100%;
      height: 100%;
      display; block;
      }

      #info{
      position: absolute;
      margin-left: 10px;
      }

      a{
      color: yellow;
      text-decoration: none;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
      <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

      <!-- https://github.com/mapbox/delaunator -->
      <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

      <script src="https://josephg.github.io/noisejs/perlin.js"></script>

      <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

      <div id="info">
      <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
      </div>








      share|improve this answer
























        1












        1








        1






        You can try to combine Three.js with Delaunator library for triangulation of your points to make a surface:






        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
        camera.position.setScalar(150);
        var renderer = new THREE.WebGLRenderer({
        antialias: true
        });
        var canvas = renderer.domElement;
        document.body.appendChild(canvas);

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

        var light = new THREE.DirectionalLight(0xffffff, 1.5);
        light.position.setScalar(100);
        scene.add(light);
        scene.add(new THREE.AmbientLight(0xffffff, 0.5));

        var size = { x: 200, y: 200 };
        var pointsCount = 1000;
        var points3d = ;
        for (let i = 0; i < pointsCount; i++) {
        let x = THREE.Math.randFloatSpread(size.x);
        let z = THREE.Math.randFloatSpread(size.y);
        let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
        points3d.push(new THREE.Vector3(x, y, z));
        }

        var geom = new THREE.BufferGeometry().setFromPoints(points3d);
        var cloud = new THREE.Points(
        geom,
        new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
        );
        scene.add(cloud);

        // triangulate by [x, z]
        var indexDelaunay = Delaunator.from(
        points3d.map(v => {
        return [v.x, v.z];
        })
        );

        var meshIndex = ; // delaunay index => three.js index
        for (let i = 0; i < indexDelaunay.triangles.length; i++){
        meshIndex.push(indexDelaunay.triangles[i]);
        }

        geom.setIndex(meshIndex); // add three.js index to the existing geometry
        geom.computeVertexNormals();
        var mesh = new THREE.Mesh(
        geom, // re-use the existing geometry
        new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
        );
        scene.add(mesh);

        var gui = new dat.GUI();
        gui.add(mesh.material, "wireframe");

        render();

        function resize(renderer) {
        const canvas = renderer.domElement;
        const width = canvas.clientWidth;
        const height = canvas.clientHeight;
        const needResize = canvas.width !== width || canvas.height !== height;
        if (needResize) {
        renderer.setSize(width, height, false);
        }
        return needResize;
        }

        function render() {
        if (resize(renderer)) {
        camera.aspect = canvas.clientWidth / canvas.clientHeight;
        camera.updateProjectionMatrix();
        }
        renderer.render(scene, camera);
        requestAnimationFrame(render);
        }

        html, body {
        height: 100%;
        margin: 0;
        overflow: hidden;
        font-family: Verdana;
        }
        canvas {
        width: 100%;
        height: 100%;
        display; block;
        }

        #info{
        position: absolute;
        margin-left: 10px;
        }

        a{
        color: yellow;
        text-decoration: none;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
        <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

        <!-- https://github.com/mapbox/delaunator -->
        <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

        <script src="https://josephg.github.io/noisejs/perlin.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

        <div id="info">
        <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
        </div>








        share|improve this answer












        You can try to combine Three.js with Delaunator library for triangulation of your points to make a surface:






        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
        camera.position.setScalar(150);
        var renderer = new THREE.WebGLRenderer({
        antialias: true
        });
        var canvas = renderer.domElement;
        document.body.appendChild(canvas);

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

        var light = new THREE.DirectionalLight(0xffffff, 1.5);
        light.position.setScalar(100);
        scene.add(light);
        scene.add(new THREE.AmbientLight(0xffffff, 0.5));

        var size = { x: 200, y: 200 };
        var pointsCount = 1000;
        var points3d = ;
        for (let i = 0; i < pointsCount; i++) {
        let x = THREE.Math.randFloatSpread(size.x);
        let z = THREE.Math.randFloatSpread(size.y);
        let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
        points3d.push(new THREE.Vector3(x, y, z));
        }

        var geom = new THREE.BufferGeometry().setFromPoints(points3d);
        var cloud = new THREE.Points(
        geom,
        new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
        );
        scene.add(cloud);

        // triangulate by [x, z]
        var indexDelaunay = Delaunator.from(
        points3d.map(v => {
        return [v.x, v.z];
        })
        );

        var meshIndex = ; // delaunay index => three.js index
        for (let i = 0; i < indexDelaunay.triangles.length; i++){
        meshIndex.push(indexDelaunay.triangles[i]);
        }

        geom.setIndex(meshIndex); // add three.js index to the existing geometry
        geom.computeVertexNormals();
        var mesh = new THREE.Mesh(
        geom, // re-use the existing geometry
        new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
        );
        scene.add(mesh);

        var gui = new dat.GUI();
        gui.add(mesh.material, "wireframe");

        render();

        function resize(renderer) {
        const canvas = renderer.domElement;
        const width = canvas.clientWidth;
        const height = canvas.clientHeight;
        const needResize = canvas.width !== width || canvas.height !== height;
        if (needResize) {
        renderer.setSize(width, height, false);
        }
        return needResize;
        }

        function render() {
        if (resize(renderer)) {
        camera.aspect = canvas.clientWidth / canvas.clientHeight;
        camera.updateProjectionMatrix();
        }
        renderer.render(scene, camera);
        requestAnimationFrame(render);
        }

        html, body {
        height: 100%;
        margin: 0;
        overflow: hidden;
        font-family: Verdana;
        }
        canvas {
        width: 100%;
        height: 100%;
        display; block;
        }

        #info{
        position: absolute;
        margin-left: 10px;
        }

        a{
        color: yellow;
        text-decoration: none;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
        <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

        <!-- https://github.com/mapbox/delaunator -->
        <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

        <script src="https://josephg.github.io/noisejs/perlin.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

        <div id="info">
        <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
        </div>








        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
        camera.position.setScalar(150);
        var renderer = new THREE.WebGLRenderer({
        antialias: true
        });
        var canvas = renderer.domElement;
        document.body.appendChild(canvas);

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

        var light = new THREE.DirectionalLight(0xffffff, 1.5);
        light.position.setScalar(100);
        scene.add(light);
        scene.add(new THREE.AmbientLight(0xffffff, 0.5));

        var size = { x: 200, y: 200 };
        var pointsCount = 1000;
        var points3d = ;
        for (let i = 0; i < pointsCount; i++) {
        let x = THREE.Math.randFloatSpread(size.x);
        let z = THREE.Math.randFloatSpread(size.y);
        let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
        points3d.push(new THREE.Vector3(x, y, z));
        }

        var geom = new THREE.BufferGeometry().setFromPoints(points3d);
        var cloud = new THREE.Points(
        geom,
        new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
        );
        scene.add(cloud);

        // triangulate by [x, z]
        var indexDelaunay = Delaunator.from(
        points3d.map(v => {
        return [v.x, v.z];
        })
        );

        var meshIndex = ; // delaunay index => three.js index
        for (let i = 0; i < indexDelaunay.triangles.length; i++){
        meshIndex.push(indexDelaunay.triangles[i]);
        }

        geom.setIndex(meshIndex); // add three.js index to the existing geometry
        geom.computeVertexNormals();
        var mesh = new THREE.Mesh(
        geom, // re-use the existing geometry
        new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
        );
        scene.add(mesh);

        var gui = new dat.GUI();
        gui.add(mesh.material, "wireframe");

        render();

        function resize(renderer) {
        const canvas = renderer.domElement;
        const width = canvas.clientWidth;
        const height = canvas.clientHeight;
        const needResize = canvas.width !== width || canvas.height !== height;
        if (needResize) {
        renderer.setSize(width, height, false);
        }
        return needResize;
        }

        function render() {
        if (resize(renderer)) {
        camera.aspect = canvas.clientWidth / canvas.clientHeight;
        camera.updateProjectionMatrix();
        }
        renderer.render(scene, camera);
        requestAnimationFrame(render);
        }

        html, body {
        height: 100%;
        margin: 0;
        overflow: hidden;
        font-family: Verdana;
        }
        canvas {
        width: 100%;
        height: 100%;
        display; block;
        }

        #info{
        position: absolute;
        margin-left: 10px;
        }

        a{
        color: yellow;
        text-decoration: none;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
        <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

        <!-- https://github.com/mapbox/delaunator -->
        <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

        <script src="https://josephg.github.io/noisejs/perlin.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

        <div id="info">
        <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
        </div>





        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
        camera.position.setScalar(150);
        var renderer = new THREE.WebGLRenderer({
        antialias: true
        });
        var canvas = renderer.domElement;
        document.body.appendChild(canvas);

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

        var light = new THREE.DirectionalLight(0xffffff, 1.5);
        light.position.setScalar(100);
        scene.add(light);
        scene.add(new THREE.AmbientLight(0xffffff, 0.5));

        var size = { x: 200, y: 200 };
        var pointsCount = 1000;
        var points3d = ;
        for (let i = 0; i < pointsCount; i++) {
        let x = THREE.Math.randFloatSpread(size.x);
        let z = THREE.Math.randFloatSpread(size.y);
        let y = noise.perlin2(x / size.x * 5, z / size.y * 5) * 50;
        points3d.push(new THREE.Vector3(x, y, z));
        }

        var geom = new THREE.BufferGeometry().setFromPoints(points3d);
        var cloud = new THREE.Points(
        geom,
        new THREE.PointsMaterial({ color: 0x99ccff, size: 2 })
        );
        scene.add(cloud);

        // triangulate by [x, z]
        var indexDelaunay = Delaunator.from(
        points3d.map(v => {
        return [v.x, v.z];
        })
        );

        var meshIndex = ; // delaunay index => three.js index
        for (let i = 0; i < indexDelaunay.triangles.length; i++){
        meshIndex.push(indexDelaunay.triangles[i]);
        }

        geom.setIndex(meshIndex); // add three.js index to the existing geometry
        geom.computeVertexNormals();
        var mesh = new THREE.Mesh(
        geom, // re-use the existing geometry
        new THREE.MeshLambertMaterial({ color: "purple", wireframe: true })
        );
        scene.add(mesh);

        var gui = new dat.GUI();
        gui.add(mesh.material, "wireframe");

        render();

        function resize(renderer) {
        const canvas = renderer.domElement;
        const width = canvas.clientWidth;
        const height = canvas.clientHeight;
        const needResize = canvas.width !== width || canvas.height !== height;
        if (needResize) {
        renderer.setSize(width, height, false);
        }
        return needResize;
        }

        function render() {
        if (resize(renderer)) {
        camera.aspect = canvas.clientWidth / canvas.clientHeight;
        camera.updateProjectionMatrix();
        }
        renderer.render(scene, camera);
        requestAnimationFrame(render);
        }

        html, body {
        height: 100%;
        margin: 0;
        overflow: hidden;
        font-family: Verdana;
        }
        canvas {
        width: 100%;
        height: 100%;
        display; block;
        }

        #info{
        position: absolute;
        margin-left: 10px;
        }

        a{
        color: yellow;
        text-decoration: none;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/98/three.min.js"></script>
        <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

        <!-- https://github.com/mapbox/delaunator -->
        <script src="https://unpkg.com/delaunator@3.0.2/delaunator.js"></script>

        <script src="https://josephg.github.io/noisejs/perlin.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.3/dat.gui.min.js"></script>

        <div id="info">
        <a href="https://github.com/mapbox/delaunator" target="blank">Delaunator<br>(triangulation)</a>
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 7:14









        prisoner849prisoner849

        7,49321325




        7,49321325






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320479%2fcreate-3d-model-of-pile-with-points-with-three-js%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Guess what letter conforming each word