简体   繁体   English

Three.js从随机点形成

[英]Three.js shape from random points

I have a N number of random points (in this case 20), with a X,Y and Z constrains. 我有N个随机点(在这种情况下为20),具有X,Y和Z约束。

How can I create ANY (preferably closed) shape (using Three.js library) , given and starting only from N random points. 如何创建任何(最好是封闭的)形状(使用Three.js库),仅从N个随机点开始。

There are probably many variants, please share yours. 可能有很多变种,请分享你的。

var program = new Program(reset,step)
program.add('g',false)
function reset() {
  scene.clear()
  scene.add(new THREE.GridHelper(100,1))
}
function step() {

}


program.startup()



var numpoints = 20;
var dots = []; //If you want to use for other task

for (var i = 0 ; i < numpoints ; i++){
    var x = Math.random() * (80 - 1) + 1    //Math.random() * (max - min) + min
    var y = Math.random() * (80 - 1) + 1
    var z = Math.random() * (80 - 1) + 1

    var dotGeometry = new THREE.Geometry();
    dots.push(dotGeometry);
    dotGeometry.vertices.push(new THREE.Vector3( x, y, z));
    var dotMaterial = new THREE.PointsMaterial( { size: 3, sizeAttenuation: false, color: 0xFF0000 } );
    var dot = new THREE.Points( dotGeometry, dotMaterial );

    scene.add(dot);
}

Triangulation, Voronoi, I don't care, just show me ANY ideas you have, will help me learn a lot! 三角测量,Voronoi,我不在乎,只是告诉我你的任何想法,会帮助我学到很多东西!

You can create a polyhedron which is the convex hull of a set of 3D points by using a pattern like so: 您可以使用如下模式创建一个多面体,它是一组3D点的凸包:

var points = [
    new THREE.Vector3( 100, 0, 0 ),
    new THREE.Vector3( 0, 100, 0 ),
    ...
    new THREE.Vector3( 0, 0, 100 )
];

var geometry = new THREE.ConvexGeometry( points );

var material = new THREE.MeshPhongMaterial( {
    color: 0xff0000, 
    shading: THREE.FlatShading
} );

mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );

You must include the following in your project 您必须在项目中包含以下内容

<script src="/examples/js/geometries/ConvexGeometry.js"></script>

three.js r.78 three.js r.78

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM