将粒子均匀地放置在对象的面而不是顶点上

将粒子均匀地放置在对象的面而不是顶点上

本文介绍了THREE.js - 将粒子均匀地放置在对象的面而不是顶点上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我已经设法创建了一个粒子云,粒子出现在我导入的对象的每个顶点.但是,我试图让粒子首先定位在对象的平面上,而不是它们之间的点上,然后将粒子均匀分布在这些面上.

Currently I've managed to create a particleCloud with the particles appearing at each vertex of an object I've imported. However I'm trying to get the particles to firstly position on the flat faces of the object rather than the points between them and secondly evenly distribute particles on those faces.

基本上我正在尝试用粒子制作我的 3d 对象

这是我目前所拥有的:

var loader = new THREE.JSONLoader();
loader.load('./resources/model.json', function (geometry, materials) {

    var material = new THREE.MeshFaceMaterial(materials);
    var model = new THREE.Mesh(geometry, material);

    var particleCount = geometry.vertices.length,
        particles = new THREE.Geometry(),
        pMaterial = new THREE.PointCloudMaterial({
            color: 0xFFFFFF,
            size: 1
        });

    for (var p = 0; p < particleCount; p ++) {
        particle = model.geometry.vertices[p];
        particles.vertices.push(particle);
    }
    particleSystem = new THREE.PointCloud(particles, pMaterial);
    particleSystem.position.set(0, -100, 0)
    particleSystem.scale.set(100,100,100)
    scene.add(particleSystem);

});

编辑 - 1

我附上了一张图片来尝试描述我目前拥有的以及我正在努力实现的目标.它以立方体的正面为例.我的对象会有更多的方面.

I've attached an image to try describe what i currently have and what i'm trying to achieve. Its using the front on a cube as an example. My object will have more sides to it.

推荐答案

上一个答案已经过时.

您现在可以使用 MeshSurfaceSampler 在网格表面生成随机样本.

You can now use MeshSurfaceSampler to generate random samples on the surface of a mesh.

MeshSurfaceSampler.js 文件位于 examples/jsm/math 目录中.

The MeshSurfaceSampler.js file is located in the examples/jsm/math directory.

three.js r.128

three.js r.128

这篇关于THREE.js - 将粒子均匀地放置在对象的面而不是顶点上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:31