Unigine.PhysicalNoise Class
Inherits: | Physical |
A PhysicalNoise class is used to simulate a force field affecting physical bodies and particles based on a volumetric noise texture. It creates an additional distribution flow specifying the force and the displacement direction for bodies and particles at each point of the force field.
Usage Example#
In this example a physical noise node and 50 boxes, each with a body and a shape, are created. Generated boxes fall down under the set gravity and are affected by the physical noise as they get into it.
// AppWorldLogic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unigine;
namespace UnigineApp
{
class AppWorldLogic : WorldLogic
{
// declaring a PhysicalNoise node
PhysicalNoise physical_noise;
/// function, creating a named box having a specified size, color and transformation with a body and a shape
ObjectMeshDynamic createBodyBox(string name, vec3 size, float mass, vec4 color, dmat4 transform)
{
// creating geometry and setting up its parameters (name, material and transformation)
ObjectMeshDynamic box = Primitives.createBox(size);
box.setWorldTransform(transform);
box.setMaterial("mesh_base", "*");
box.setMaterialParameterFloat4("albedo_color", color, 0);
box.setName(name);
// adding physics, i.e. a rigid body and a box shape with specified mass
BodyRigid body = new BodyRigid(box);
body.addShape(new ShapeBox(size), MathLib.Translate(new vec3(0.0f)));
box.getBody().getShape(0).setMass(mass);
// setting the physical mask for the body
body.setPhysicalMask(1);
return box;
}
/* .. */
public override bool Init()
{
// setting up physics parameters (gravity, linear and angular velocity)
Physics.Gravity = new vec3(0.0f, 0.0f, -1.0f);
Physics.FrozenLinearVelocity = 0.1f;
Physics.FrozenAngularVelocity = 0.1f;
// setting up player's parameters
Game.Player.WorldPosition = new dvec3(0.0f, 90.0f, 70.0f);
Game.Player.setDirection(new vec3(0.0f, -1.0f, -0.7f), new vec3(0.0f, 0.0f, -1.0f));
// creating a physical noise node with a size of 60x60x60
physical_noise = new PhysicalNoise(new vec3(60.0f));
// setting the force multiplier
physical_noise.setForce(50.0f);
// setting the threshold distance
physical_noise.setThreshold(new vec3(0.0f));
// setting the physical mask
physical_noise.setPhysicalMask(1);
//setting up noise texture generation parameters (scale, frequency, size)
physical_noise.setNoiseScale(0.2f);
physical_noise.setFrequency(4);
physical_noise.setImageSize(16);
// setting the sampling step equal to 20
physical_noise.setStep(new vec3(20.0f));
// enabling the Visualizer to show our physical noise
Visualizer.Enabled = true;
//generating 50 boxes with rigid bodies and shapes assigned
for (int i = 0; i < 50; i++) {
dvec3 position = new dvec3(Game.GetRandomDouble(-50.0f, 50.0f), Game.GetRandomDouble(-50.0f, 50.0f), 40.0f);
vec4 color = new vec4(Game.GetRandomFloat(0.0f, 1.0f), Game.GetRandomFloat(0.0f, 1.0f), Game.GetRandomFloat(0.0f, 1.0f), Game.GetRandomFloat(0.0f, 1.0f));
createBodyBox("box", new vec3(1.0f), 1.0f, color, MathLib.Translate(position));
}
return true;
}
// start of the main loop
public override bool Update()
{
// rendering visualizer for the physical noise node
physical_noise.RenderVisualizer();
return true;
}
/* .. */
}
}
See Also#
- Article on Physical Noise to learn more about the parameters.
- A UnigineScript API sample <UnigineSDK>/data/samples/physicals/noise_00
PhysicalNoise Class
Properties
vec3 Threshold#
The threshold distance set for the physical noise node. the threshold determines the distance of gradual change from zero to full force value.
this values are relative to the size of the physical noise box. it means that the threshold values should be less than the size of the physical noise box.
set
Sets a threshold distance set for the physical noise node.
The threshold determines the distance of gradual change from zero to full force value.
This values are relative to the size of the physical noise box. It means that the threshold values should be less than the size of the physical noise box.
set value -
Threshold distance along the X, Y and Z axes.
vec3 Step#
The sampling step that is used for pixel sampling from the noise texture.
This parameter can be used to animate a force field in run-time.
set
Sets the sampling step that is used for pixel sampling from the noise texture.
This parameter can be used to animate a force field in run-time.
set value -
Sampling step size along the X, Y and Z axes.
vec3 Size#
The current size of the physical noise node.
set
Sets the size for the physical noise node.
set value -
Size of the physical noise box in units. If a negative value is provided, 0 will be used instead.
float NoiseScale#
The scale of the noise texture.
set
Sets the scale of the noise texture.
It is not recommended to change this parameter in run-time as the noise texture will be regenerated and the performance will decrease.
set value -
Scale of the noise texture. The minimum value is 0, the maximum value is 1.
vec3 Offset#
The sampling offset that is used for pixel sampling from the noise texture.
This parameter can be used to animate a force field in run-time.
set
Sets the sampling offset that will be used for pixel sampling from the noise texture.
This parameter can be used to animate a force field in run-time.
set value -
Sampling offset along the X, Y and Z axes.
int ImageSize#
The size of the noise texture in pixels.
set
Sets the size of the noise texture in pixels.
set value -
Size of the noise texture in pixels.
int Frequency#
The number of octaves for the perlin noise texture generation.
It is not recommended to change this parameter in run-time as the noise texture will be regenerated and the performance will decrease.
set
Sets the number of octaves for the Perlin noise texture generation.
It is not recommended to change this parameter in run-time as the noise texture will be regenerated and the performance will decrease.
set value -
Number of octaves for the Perlin noise texture generation. The minimum value is 1, the maximum value is 16. The higher the value is, the more details the noise texture has.
float Force#
The value of the force multiplier.
set
Sets the value of the force multiplier.
set value -
Force multiplier. The higher the value is, the higher the value of the resulting force that affects an object inside the physical noise node will be.
Members
static PhysicalNoise ( vec3 size ) #
Constructor. Creates a physical noise node of the specified size.Arguments
- vec3 size - Physical noise box size in units.
Image GetImage ( ) #
Returns the noise texture image.Return value
Noise texture image.static int type ( ) #
Returns the type of the node.Return value
PhysicalNoise type identifier.Last update:
2020-07-31
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)