How do I translate vertices in a THREE.PointCloud object?

Tyler

I am trying to:

  • Draw a THREE.PointCloud object with approx. 150k points where points are sent from a web application.
  • Scale the points in the THREE.PointCloud object to achieve a result similar to this (rendered using MayaVi):

MayaVi surface render

The problem is that:

  • Data passed to the THREE.PointCloud object seems to be inaccurate
  • When rendered in three.js, points are arranged into eight cubes, for unknown reasons (I'm not applying any scaling, or transformations to the points)

Example server response (I have included sample data at the bottom of this post):

{'geometry': [[-156, 65, 89],
              [268, 84, 337],
              [-205, 68, 170],
              [-87, 69, 52],
              ...
              [289, 81, 143],
              [141, 78, 280],
              [403, 75, 351]],
 'metadata': {'max': {'x': 421, 'y': 105, 'z': 458},
          'min': {'x': -335, 'y': 63, 'z': 39}}}

The three.js code used to create the point cloud:

  var container;
  var scene, camera, renderer, controls;
  var geometry, material, mesh;

  init();
  animate();

  function init() {
    scene = new THREE.Scene();
    camera = new THREE.PerspectiveCamera(27, window.innerWidth / window.innerHeight, 5, 5000);
    camera.position.z = 2750;

    //Add a buffer geometry for particle system
    var geometry = new THREE.BufferGeometry();
    var particles = {{ len(topology['geometry']) }};
    var geometry = new THREE.BufferGeometry();
    var positions = new Float32Array(particles * 3);
    var colors = new Float32Array(particles * 3);
    var color = new THREE.Color();

    var i = 0;
    {% for point in topology['geometry'] %}
      var x = {{ point[0] }};
      var y = {{ point[1] }};
      var z = {{ point[2] }};

      //Store the position of the point
      positions[i]     = x;
      positions[i + 1] = y;
      positions[i + 2] = z;

      //Assign a colour to the point
      color.setRGB(0.42, 0.42, 0.42);
      colors[i]     = color.r;
      colors[i + 1] = color.g;
      colors[i + 2] = color.b;
      i+=1;
    {% end %}

    geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
    geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
    geometry.computeBoundingSphere();

    var material = new THREE.PointCloudMaterial({ size: 15, vertexColors: THREE.VertexColors });
    particleSystem = new THREE.PointCloud(geometry, material);
    scene.add(particleSystem);

    //Lights
    light = new THREE.DirectionalLight(0xffffff);
    light.position.set(1, 1, 1);
    scene.add(light);

    //Set up renderer
    renderer = new THREE.WebGLRenderer({ antialias:false });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setPixelRatio(window.devicePixelRatio);

    //Attach renderer to #container DOM element
    container = document.getElementById('container');
    container.appendChild(renderer.domElement);

    //Add window listener for resize events
    window.addEventListener('resize', onWindowResize, false);

    //Call render loop
    animate();
  }

  function onWindowResize(){
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
    render();
  }

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

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

The scene ends up looking like this:

three.js

Any suggestions? I've used the following example code, but I'm having difficulty properly implementing scaling for the points in my dataset: http://threejs.org/examples/#webgl_buffergeometry_particles

Link to a sample of data that I am working with (2MB, 180k lines): https://gist.githubusercontent.com/TylerJFisher/659e3e233f8aa458feee/raw/889c0dd0093fd0476094af48488aab62c8666271/topology.asc

prisoner849

I used your sample data. Put it in an array, like this:

var data = [
"-156 65 89",
"268 84 337",
"-205 68 170",
"-87 69 52",
...
];

and used THREE.Geometry() for PointCloud:

            var geometry = new THREE.Geometry();
            var colors = [];

            for ( var x = 0; x < data.length; x++){
                    var pointCoord = data[ x ].split(" ");
                    if ( pointCoord.length != 3 ) continue;
                    var currentColor = new THREE.Color( 0.5, 1, 0.5 );
                    colors.push( currentColor );
                    geometry.vertices.push(
                        new THREE.Vector3(
                            pointCoord[2],
                            pointCoord[1],
                            pointCoord[0]
                        )
                    );
                };
            //

            console.log( geometry.vertices.length );

            geometry.colors = colors;

            var material = new THREE.PointCloudMaterial( { size: 1, vertexColors: THREE.VertexColors } );

            particleSystem = new THREE.PointCloud( geometry, material );
            scene.add( particleSystem );

Also, in geodata, coordinates x and y are always swapped (in this case, there are x and z). If you won't do it, you'll get mirrored object then. That's why I put it as

                        new THREE.Vector3(
                            pointCoord[2],
                            pointCoord[1],
                            pointCoord[0]
                        )

instead of

                        new THREE.Vector3(
                            pointCoord[0],
                            pointCoord[1],
                            pointCoord[2]
                        )

The result is here: geodata

And yes, some lines in your sample data seem incorrect. Means they have 1 or 2 values instead of 3.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How do I combine three observables such that

来自分类Dev

How do I render three.js in node.js?

来自分类Dev

如何转换THREE.PointCloud对象中的顶点?

来自分类Dev

three.js PointCloud中的可点击粒子

来自分类Dev

在three.js中,何时需要启用PointCloud.sortParticles?

来自分类Dev

在three.js中使用pointcloud创建平面网格

来自分类Dev

How do I disable object reference creation in the Newtonsoft JSON serializer?

来自分类Dev

How do i bind an "Entry Cell" to a custom object using Xamarin?

来自分类Dev

In F#, how do I tell if an object is an Async<_>, and how can I cast it to an Async<_>?

来自分类Dev

使用Three.js在椭圆形PointCloud中对点进行分区

来自分类Dev

PhpStorm 8 - Rename Refactoring - How do I rename a object property throughout my project?

来自分类Dev

I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

来自分类Dev

How to remove edge between two vertices?

来自分类Dev

how can I update THREE.Sprite color

来自分类Dev

How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

来自分类常见问题

How do I resolve ClassNotFoundException?

来自分类Dev

How to create Grails domain object but do not save?

来自分类Dev

How to use angular-translate within a customer filter and re-translate on $translate.use()

来自分类Dev

STL到Pointcloud

来自分类Dev

Pointcloud渲染,交错VBO

来自分类Dev

How can I return an anonymous object in Javascript?

来自分类Dev

How to translate (and replicate) the CSRF Message in Symfony?

来自分类Dev

How do i sort my listview alphabetically?

来自分类Dev

How do I parse a RestSharp response into a class?

来自分类Dev

How do I override a default keybinding in LightTable?

来自分类Dev

How do I modularize polyfills in Angular?

来自分类Dev

How do I declare a driver as global?

来自分类Dev

How do I combine lenses and functors?

来自分类Dev

How do I parse JSON in Racket?

Related 相关文章

  1. 1

    How do I combine three observables such that

  2. 2

    How do I render three.js in node.js?

  3. 3

    如何转换THREE.PointCloud对象中的顶点?

  4. 4

    three.js PointCloud中的可点击粒子

  5. 5

    在three.js中,何时需要启用PointCloud.sortParticles?

  6. 6

    在three.js中使用pointcloud创建平面网格

  7. 7

    How do I disable object reference creation in the Newtonsoft JSON serializer?

  8. 8

    How do i bind an "Entry Cell" to a custom object using Xamarin?

  9. 9

    In F#, how do I tell if an object is an Async<_>, and how can I cast it to an Async<_>?

  10. 10

    使用Three.js在椭圆形PointCloud中对点进行分区

  11. 11

    PhpStorm 8 - Rename Refactoring - How do I rename a object property throughout my project?

  12. 12

    I have a few function overloads, each of which takes a different subclass; how do I check which function to use for a given object?

  13. 13

    How to remove edge between two vertices?

  14. 14

    how can I update THREE.Sprite color

  15. 15

    How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

  16. 16

    How do I resolve ClassNotFoundException?

  17. 17

    How to create Grails domain object but do not save?

  18. 18

    How to use angular-translate within a customer filter and re-translate on $translate.use()

  19. 19

    STL到Pointcloud

  20. 20

    Pointcloud渲染,交错VBO

  21. 21

    How can I return an anonymous object in Javascript?

  22. 22

    How to translate (and replicate) the CSRF Message in Symfony?

  23. 23

    How do i sort my listview alphabetically?

  24. 24

    How do I parse a RestSharp response into a class?

  25. 25

    How do I override a default keybinding in LightTable?

  26. 26

    How do I modularize polyfills in Angular?

  27. 27

    How do I declare a driver as global?

  28. 28

    How do I combine lenses and functors?

  29. 29

    How do I parse JSON in Racket?

热门标签

归档