
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@jaimebboyjt/three-scatter
Advanced tools
Inspired by a GScatter (plugin for blender) in Three.js
Spread all types of objects/models into a geometry easily
npm i @jaimebboyjt/three-scatter
Three.js already comes with MeshSurfaceSampler you can think in three-scatter
as an "extension" of it. I said it in quotes because is not quite true, three-scatter
the approach is different and it comes with method to help scatter your Meshes.
Use three-scatter
if you:
NOTE: if performance is your must, MeshSurfaceSampler is your go to, I provided a debug option to help you, but MeshSurfaceSampler is much more performance since you can (and probably should) use InstancedMesh
Additionally you can use this library to generate only the positions
import { ThreeScatter } from 'three-scatter'
// Count: Number of samples
// Surface: Geometry from which to sample
// Model: 3D model or models to scatter
const scatter = new ThreeScatter(count, surface, model);
scene.add(scatter);
You can also scatter more than one model:
const scatter = new ThreeScatter(count, surface, [model1, model2]);
three-scatter
comes with lots of handy method for you, one of the most common ones is setAll
that allow you affect all the scattered models.
const scatter = new ThreeScatter(count, surface, [model1, model2, model3]);
scatter.setAll((model, index) => {
model.scale.set(0.1, 0.1, 0.1);
});
If you don't need ThreeScatter
handle your models you can instantiate the class without any models, then get the positions:
const scatter = new ThreeScatter(count, surface);
const positions = scatter.getPositions()
you can still get different positions using the setSeeds
method but you have to update your models manually.
NOTE: Using this approach means that no other internal method will have effects in your model
scatter.setSeeds(5); // tweak it and find the right value for you
// This method will align Y+up with the normals of the surface
scatter.alignToSurfaceNormal();
// This method will remove the model that has collisions with other scattered model
scatter.removeCollisions();
// A normalize range between -1 and 1 to determine which axis to show your scattered models
scatter.setAxis(
[minX, maxX],
[minY, maxY],
[minZ, maxZ]
);
// Dispose all the geometries and material and remove all the meshes
scatter.cleanGroup();
// return all the faces of the surface sample, using a Triangle: https://threejs.org/docs/?q=triangle#api/en/math/Triangle
scatter.getFaces();
// return all the positions, useful if you want to display specifics positions in your scene
scatter.getPositions();
ThreeScatter allows you more control using optional parameters.
const scatter = new ThreeScatter(count, surface, model, {
seeds<number>: 1, // seed to begin with
useSkeletonUtils<boolean>: true // Necessary when you are scattering 3D models with rigging/animations
randomFn<() => number>: Math.random() // if you want to have control over the random function, has to return a value from 0 to 1
});
ThreeScatter
comes with a debug mode that will replace all your models with a low poly mesh, and find the right position, easily.
const scatter = new ThreeScatter(count, surface, model, {
debug<boolean>: true,
debugGeometry<Geometry>: new THREE.SphereGeometry(0.5, 3, 2) ,
debugMaterial<Material>: new THREE.MeshBasicMaterial({ color: 0x800080 }),
});
You can also use the setDebug
and removeDebug
methods to control it after ThreeScatter
is instantiated
scatter.setDebug(); // or
scatter.removeDebug();
You can now set the percentage of model distribution in case you are scattering more than one model.
const scatter = new ThreeScatter(count, surface, [model1, model2], {
distribution: [ 0.25, 0.75]
});
NOTE: In order to set the distribution property, you need to have:
distribution
property with equal length than the array of modeldistribution
property needs to sum 1We are open to contributions, please read the contributing guide to get started.
Be the first to support this project here ☺️.
FAQs
A Three.js library for scattering 3D models
We found that @jaimebboyjt/three-scatter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.