THREE.js-将粒子均匀地放置在对象面上而不是顶点上 [英] THREE.js - position particles evenly on objects faces rather than verticies

查看:139
本文介绍了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对象

这是我到目前为止所拥有的:

This is what I have so far:

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 目录中.

three.js r.128

three.js r.128

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆