Load positions attribute from a JSON file in Three JS Buffer Geometry Points

吃可爱长大的小学妹 提交于 2019-12-11 16:21:04

问题


I am new in using Three JS Buffer Geometry my task is to draw Buffer Geometry Points, I have position attribute and color attribute value saved in a separate JSON file, how can I use them to populate on Buffer Geometry points? I tried FileReader function to read the JSON but its a asynchronous call. I also tried Loader of Three JS but I couldn't success. My buffer geometry code init() function loop that creates position and set color:

for ( var i = 0; i < 81; i += 3 ) {

                    // positions

                    //var x = i; //x,y,z need positions from json file
                    //var y = i+1;
                    //var z = i+3;

                    var x = Math.random() * n - n2;
                    var y = Math.random() * n - n2;
                    var z = Math.random() * n - n2;

                    positions[ i ]     = x;
                    positions[ i + 1 ] = y;
                    positions[ i + 2 ] = z;

                    // colors

                    var vx = ( x / n ) + 0.5;
                    var vy = ( y / n ) + 0.5;
                    var vz = ( z / n ) + 0.5;

                    color.setRGB( vx, vy, vz );

                    colors[ i ]     = color.r; //value from json file
                    colors[ i + 1 ] = color.g;
                    colors[ i + 2 ] = color.b;

                }

来源:https://stackoverflow.com/questions/38112211/load-positions-attribute-from-a-json-file-in-three-js-buffer-geometry-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!