Hey,
I've seen this in a handful of other libraries and always wondered why it wasn't included. If you don't use random vectors, then what are you doing with you life? I use it so often I add it in almost all my projects, it looks like this;
THREE.Vector3.prototype.randomUnitVector = function(){
this.x = Math.random() * 2 - 1;
this.y = Math.random() * 2 - 1;
this.z = Math.random() * 2 - 1;
this.normalize();
return this;
}
You would call it like this;
let v = new THREE.Vector3().randomUnitVector();
The name is quite long, maybe in relations to other vector functions names like .randomize() (like normalize) or just .random() would be more logical?
You could also give it an argument to set the length, but I find it more logical to call .setLength() afterwards because it wouldn't be a unit vector anymore and it's easier to read.
I'm curious of what you think of it.
Kind regards, Ethan.
I've seen this in a handful of other libraries
Can you please name them and show a few code examples?
Hey Mugen,
I've edited my original post.. I forgot the this.normalize() in the function. Some examples of other software/libs that do support random unit vectors below;
In Unity you can do;
object.position = Random.insideUnitSphere;
This function comes from their random class and generates a random 3d unit vector (Random.insideUnitCircle for 2d).
https://docs.unity3d.com/ScriptReference/Random-insideUnitSphere.html
In Unreal (they use a node style 'coding') you can add a Random Unit Vector node.
https://docs.unrealengine.com/en-US/BlueprintAPI/Math/Random/RandomUnitVector/index.html
In p5.js there is a static function build in the vector class, for both 3 and 2d. You can do:
let v2 = new p5.Vector.random2D();
let v3 = new p5.Vector.random3D();
https://p5js.org/reference/#/p5.Vector/random3D
The last one does it differently than I would expect.
p5.Vector.random3D = function random3D() {
const angle = Math.random() * constants.TWO_PI;
const vz = Math.random() * 2 - 1;
const vzBase = Math.sqrt(1 - vz * vz);
const vx = vzBase * Math.cos(angle);
const vy = vzBase * Math.sin(angle);
return new p5.Vector(vx, vy, vz);
};
That's all. Thanks for listening.
Thanks for sharing this additional information! I'm okay with adding such a method as long as all vector classes (Vector2
, Vector3
and Vector4
) are enhanced.
I'm okay with adding such a method as long as all vector classes (Vector2, Vector3 and Vector4) are enhanced.
There are many sampling methods based on the use case. What use case are you assuming for your Vector4
? Is it to be used as a quaternion?
Unity has many sampling methods. It makes no sense to select just one and include that.
It _may_ be reasonable to add examples/math/jsm/Sampling.js
and add the methods there.
But in reality, this is application-specific.
Is it to be used as a quaternion?
TBH, I thought about RGBA color values. Anyway, I don't feel strong about this one. It's true that we try to avoid adding application-specific logic in the engine. Sometimes feature requests are easy to evaluate, sometimes not because they are edge cases. I leave this up to @mrdoob's preference.
Sometimes uniform sampling on the _hemisphere_ is preferred. Also, if a _sequence_ of samples will be required, Hammersley can be used to prevent clustering.
I still consider this whole topic application-specific.
If @Mugen87 supports adding examples/math/jsm/Sampling.js
, that is OK with me, but I do not feel strongly about adding that file.
@WestLangley You make a good point. I did not fully take the Vector4 in consideration. When using a Vector4 for a direction&(distance/speed) in space, or for rgba values, it would work. Using a random Vector4 as a Quaternion gives wacky results.
Sometimes uniform sampling on the hemisphere is preferred. Also, if a sequence of samples will be required, Hammersley can be used to prevent clustering.
It is true that there are multiple ways of generating random vectors, some more random than others. I'm not requesting uniform random unit vectors though. I would consider that a different topic since that actually needs a sophisticated algorithm.(more or less the application-specific logic you're talking about). In my opinion having general random unit vectors is basic needs.
That said, i do understand that it's an edge case and would understand if you leave it for what it is.
I still consider this whole topic application-specific.
You are right. Unless @mrdoob has a different opinion, I think I would prefer to wait if there are more similar feature requests in the future. Something like examples/jsm/math/Sampling.js
or examples/jsm/math/Random.js
can still be added then.
Unity has many sampling methods. It makes no sense to select just one and include that.
I now know what you are talking about, what I said before makes no sense.
It may be reasonable to add examples/math/jsm/Sampling.js and add the methods there.
You are suggesting there would be a need for whole library of methods instead of one function.. ? That's even better!
How about just a random?
THREE.Vector3.prototype.random = function(){
this.x = Math.random() * 2 - 1;
this.y = Math.random() * 2 - 1;
this.z = Math.random() * 2 - 1;
return this;
}
So then we would do this:
vector.random().normalize();
... because random()
is typically in [0, 1].
We provide Math
methods a user can use to create whatever random vector is appropriate for their specific use case.
The proposed implementation does not produce uniformly distributed vectors, if anybody cares.
The proper way to create random vectors is discussed e.g. here.
The "proper way" is application-specific.
Just to add to the choir, for random colors I almost always prefer random hsl with a random hue but not random saturation or level (or some range but not 100% random). Like I don't want something too light or too dark. In other words I agree with those claiming this is application specific.
... because
random()
is typically in [0, 1].
Right... Then, how about?
vector.random().subScalar( 0.5 ).normalize();
It's a pattern we use often (mostly my "fault" 馃槆):
css3d_periodictable.html: element.style.backgroundColor = 'rgba(0,127,127,' + ( Math.random() * 0.5 + 0.25 ) + ')';
css3d_periodictable.html: object.position.x = Math.random() * 4000 - 2000;
css3d_periodictable.html: object.position.y = Math.random() * 4000 - 2000;
css3d_periodictable.html: object.position.z = Math.random() * 4000 - 2000;
css3d_periodictable.html: .to( { x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration )
css3d_periodictable.html: .to( { x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration )
css3d_sandbox.html: element.style.background = new THREE.Color( Math.random() * 0xffffff ).getStyle();
css3d_sandbox.html: object.position.x = Math.random() * 200 - 100;
css3d_sandbox.html: object.position.y = Math.random() * 200 - 100;
css3d_sandbox.html: object.position.z = Math.random() * 200 - 100;
css3d_sandbox.html: object.rotation.x = Math.random();
css3d_sandbox.html: object.rotation.y = Math.random();
css3d_sandbox.html: object.rotation.z = Math.random();
css3d_sandbox.html: object.scale.x = Math.random() + 0.5;
css3d_sandbox.html: object.scale.y = Math.random() + 0.5;
css3d_sprites.html: object.position.x = Math.random() * 4000 - 2000,
css3d_sprites.html: object.position.y = Math.random() * 4000 - 2000,
css3d_sprites.html: object.position.z = Math.random() * 4000 - 2000;
css3d_sprites.html: Math.random() * 4000 - 2000,
css3d_sprites.html: Math.random() * 4000 - 2000,
css3d_sprites.html: Math.random() * 4000 - 2000
css3d_sprites.html: }, Math.random() * duration + duration )
grep: files: Is a directory
grep: fonts: Is a directory
grep: js: Is a directory
grep: jsm: Is a directory
misc_boxselection.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
misc_boxselection.html: object.position.x = Math.random() * 1600 - 800;
misc_boxselection.html: object.position.y = Math.random() * 900 - 450;
misc_boxselection.html: object.position.z = Math.random() * 900 - 500;
misc_boxselection.html: object.rotation.x = Math.random() * 2 * Math.PI;
misc_boxselection.html: object.rotation.y = Math.random() * 2 * Math.PI;
misc_boxselection.html: object.rotation.z = Math.random() * 2 * Math.PI;
misc_boxselection.html: object.scale.x = Math.random() * 2 + 1;
misc_boxselection.html: object.scale.y = Math.random() * 2 + 1;
misc_boxselection.html: object.scale.z = Math.random() * 2 + 1;
misc_controls_drag.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
misc_controls_drag.html: object.position.x = Math.random() * 1000 - 500;
misc_controls_drag.html: object.position.y = Math.random() * 600 - 300;
misc_controls_drag.html: object.position.z = Math.random() * 800 - 400;
misc_controls_drag.html: object.rotation.x = Math.random() * 2 * Math.PI;
misc_controls_drag.html: object.rotation.y = Math.random() * 2 * Math.PI;
misc_controls_drag.html: object.rotation.z = Math.random() * 2 * Math.PI;
misc_controls_drag.html: object.scale.x = Math.random() * 2 + 1;
misc_controls_drag.html: object.scale.y = Math.random() * 2 + 1;
misc_controls_drag.html: object.scale.z = Math.random() * 2 + 1;
misc_controls_fly.html: vertex.x = Math.random() * 2 - 1;
misc_controls_fly.html: vertex.y = Math.random() * 2 - 1;
misc_controls_fly.html: vertex.z = Math.random() * 2 - 1;
misc_controls_fly.html: vertex.x = Math.random() * 2 - 1;
misc_controls_fly.html: vertex.y = Math.random() * 2 - 1;
misc_controls_fly.html: vertex.z = Math.random() * 2 - 1;
misc_controls_fly.html: stars.rotation.x = Math.random() * 6;
misc_controls_fly.html: stars.rotation.y = Math.random() * 6;
misc_controls_fly.html: stars.rotation.z = Math.random() * 6;
misc_controls_map.html: mesh.position.x = Math.random() * 1600 - 800;
misc_controls_map.html: mesh.position.z = Math.random() * 1600 - 800;
misc_controls_map.html: mesh.scale.y = Math.random() * 80 + 10;
misc_controls_orbit.html: mesh.position.x = Math.random() * 1600 - 800;
misc_controls_orbit.html: mesh.position.z = Math.random() * 1600 - 800;
misc_controls_pointerlock.html: vertex.x += Math.random() * 20 - 10;
misc_controls_pointerlock.html: vertex.y += Math.random() * 2;
misc_controls_pointerlock.html: vertex.z += Math.random() * 20 - 10;
misc_controls_pointerlock.html: color.setHSL( Math.random() * 0.3 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
misc_controls_pointerlock.html: color.setHSL( Math.random() * 0.3 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
misc_controls_pointerlock.html: boxMaterial.color.setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
misc_controls_pointerlock.html: box.position.x = Math.floor( Math.random() * 20 - 10 ) * 20;
misc_controls_pointerlock.html: box.position.y = Math.floor( Math.random() * 20 ) * 20 + 10;
misc_controls_pointerlock.html: box.position.z = Math.floor( Math.random() * 20 - 10 ) * 20;
misc_controls_trackball.html: mesh.position.x = ( Math.random() - 0.5 ) * 1000;
misc_controls_trackball.html: mesh.position.y = ( Math.random() - 0.5 ) * 1000;
misc_controls_trackball.html: mesh.position.z = ( Math.random() - 0.5 ) * 1000;
misc_exporter_gltf.html: pointsArray[ 3 * i ] = - 50 + Math.random() * 100;
misc_exporter_gltf.html: pointsArray[ 3 * i + 1 ] = Math.random() * 100;
misc_exporter_gltf.html: pointsArray[ 3 * i + 2 ] = - 50 + Math.random() * 100;
misc_lookat.html: mesh.position.x = Math.random() * 4000 - 2000;
misc_lookat.html: mesh.position.y = Math.random() * 4000 - 2000;
misc_lookat.html: mesh.position.z = Math.random() * 4000 - 2000;
misc_lookat.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 4 + 2;
grep: models: Is a directory
grep: nodes: Is a directory
physics_ammo_break.html: return Math.floor( Math.random() * ( 1 << 24 ) );
physics_ammo_cloth.html: return Math.floor( Math.random() * ( 1 << 24 ) );
physics_ammo_rope.html: return Math.floor( Math.random() * ( 1 << 24 ) );
physics_ammo_terrain.html: var objectType = Math.ceil( Math.random() * numTypes );
physics_ammo_terrain.html: var radius = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var sx = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var sy = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var sz = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var radius = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var height = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var radius = 1 + Math.random() * objectSize;
physics_ammo_terrain.html: var height = 2 + Math.random() * objectSize;
physics_ammo_terrain.html: threeObject.position.set( ( Math.random() - 0.5 ) * terrainWidth * 0.6, terrainMaxHeight + objectSize + 2, ( Math.random() - 0.5 ) * terrainDepth * 0.6 );
physics_ammo_terrain.html: var c = Math.floor( Math.random() * ( 1 << 24 ) );
physics_cannon_instancing.html: return Math.random() * 0.1 + 0.05;
physics_cannon_instancing.html: matrix.setPosition( Math.random() - 0.5, Math.random() * 2, Math.random() - 0.5 );
physics_cannon_instancing.html: instanceColors.push( Math.random(), Math.random(), Math.random() );
physics_cannon_instancing.html: var index = Math.floor( Math.random() * mesh.count );
physics_cannon_instancing.html: position.set( 0, Math.random() * 2, 0 );
grep: screenshots: Is a directory
grep: sounds: Is a directory
svg_lines.html: color: Math.random() * 0xffffff,
svg_sandbox.html: mesh.rotation.x = Math.random();
svg_sandbox.html: mesh.rotation.y = Math.random();
svg_sandbox.html: mesh = new THREE.Mesh( cube, new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
svg_sandbox.html: mesh.rotation.x = Math.random();
svg_sandbox.html: mesh.rotation.y = Math.random();
svg_sandbox.html: mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 100, 100 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, side: THREE.DoubleSide } ) );
svg_sandbox.html: mesh = new THREE.Mesh( new THREE.CylinderBufferGeometry( 20, 100, 200, 10 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
svg_sandbox.html: Math.random() * 1000 - 500,
svg_sandbox.html: Math.random() * 1000 - 500,
svg_sandbox.html: Math.random() * 1000 - 500
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50,
svg_sandbox.html: Math.random() * 100 - 50
svg_sandbox.html: color.setHex( Math.random() * 0xffffff );
svg_sandbox.html: var material = new THREE.SpriteMaterial( { color: Math.random() * 0xffffff } );
svg_sandbox.html: sprite.position.x = Math.random() * 1000 - 500;
svg_sandbox.html: sprite.position.y = Math.random() * 1000 - 500;
svg_sandbox.html: sprite.position.z = Math.random() * 1000 - 500;
svg_sandbox.html: object.position.x = Math.random() * 1000 - 500;
svg_sandbox.html: object.position.y = Math.random() * 1000 - 500;
svg_sandbox.html: object.position.z = Math.random() * 1000 - 500;
grep: textures: Is a directory
webgl2_multisampled_renderbuffers.html: mesh.position.x = Math.random() * 600 - 300;
webgl2_multisampled_renderbuffers.html: mesh.position.y = Math.random() * 600 - 300;
webgl2_multisampled_renderbuffers.html: mesh.position.z = Math.random() * 600 - 300;
webgl2_multisampled_renderbuffers.html: mesh.rotation.x = Math.random();
webgl2_multisampled_renderbuffers.html: mesh.rotation.z = Math.random();
webgl2_multisampled_renderbuffers.html: mesh.scale.setScalar( Math.random() * 5 + 5 );
webgl2_sandbox.html: mesh.position.x = Math.random() * 10 - 5;
webgl2_sandbox.html: mesh.position.y = Math.random() * 10 - 5;
webgl2_sandbox.html: mesh.position.z = Math.random() * 10 - 5;
webgl2_sandbox.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl2_sandbox.html: mesh.scale.setScalar( Math.random() * 4 + 1 );
webgl_animation_cloth.html: pins = pinsFormation[ ~ ~ ( Math.random() * pinsFormation.length ) ];
webgl_buffergeometry.html: var x = Math.random() * n - n2;
webgl_buffergeometry.html: var y = Math.random() * n - n2;
webgl_buffergeometry.html: var z = Math.random() * n - n2;
webgl_buffergeometry.html: var ax = x + Math.random() * d - d2;
webgl_buffergeometry.html: var ay = y + Math.random() * d - d2;
webgl_buffergeometry.html: var az = z + Math.random() * d - d2;
webgl_buffergeometry.html: var bx = x + Math.random() * d - d2;
webgl_buffergeometry.html: var by = y + Math.random() * d - d2;
webgl_buffergeometry.html: var bz = z + Math.random() * d - d2;
webgl_buffergeometry.html: var cx = x + Math.random() * d - d2;
webgl_buffergeometry.html: var cy = y + Math.random() * d - d2;
webgl_buffergeometry.html: var cz = z + Math.random() * d - d2;
webgl_buffergeometry_custom_attributes_particles.html: positions.push( ( Math.random() * 2 - 1 ) * radius );
webgl_buffergeometry_custom_attributes_particles.html: positions.push( ( Math.random() * 2 - 1 ) * radius );
webgl_buffergeometry_custom_attributes_particles.html: positions.push( ( Math.random() * 2 - 1 ) * radius );
webgl_buffergeometry_drawrange.html: var x = Math.random() * r - r / 2;
webgl_buffergeometry_drawrange.html: var y = Math.random() * r - r / 2;
webgl_buffergeometry_drawrange.html: var z = Math.random() * r - r / 2;
webgl_buffergeometry_drawrange.html: velocity: new THREE.Vector3( - 1 + Math.random() * 2, - 1 + Math.random() * 2, - 1 + Math.random() * 2 ),
webgl_buffergeometry_instancing.html: offsets.push( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 );
webgl_buffergeometry_instancing.html: colors.push( Math.random(), Math.random(), Math.random(), Math.random() );
webgl_buffergeometry_instancing.html: vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
webgl_buffergeometry_instancing.html: vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
webgl_buffergeometry_instancing_billboards.html: translateArray[ i3 + 0 ] = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_billboards.html: translateArray[ i3 + 1 ] = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_billboards.html: translateArray[ i3 + 2 ] = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_interleaved.html: x = Math.random() * 100 - 50;
webgl_buffergeometry_instancing_interleaved.html: y = Math.random() * 100 - 50;
webgl_buffergeometry_instancing_interleaved.html: z = Math.random() * 100 - 50;
webgl_buffergeometry_instancing_interleaved.html: x = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_interleaved.html: y = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_interleaved.html: z = Math.random() * 2 - 1;
webgl_buffergeometry_instancing_interleaved.html: w = Math.random() * 2 - 1;
webgl_buffergeometry_lines.html: var x = Math.random() * r - r / 2;
webgl_buffergeometry_lines.html: var y = Math.random() * r - r / 2;
webgl_buffergeometry_lines.html: var z = Math.random() * r - r / 2;
webgl_buffergeometry_lines_indexed.html: colors.push( Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, 1 );
webgl_buffergeometry_points.html: var x = Math.random() * n - n2;
webgl_buffergeometry_points.html: var y = Math.random() * n - n2;
webgl_buffergeometry_points.html: var z = Math.random() * n - n2;
webgl_buffergeometry_points_interleaved.html: var x = Math.random() * n - n2;
webgl_buffergeometry_points_interleaved.html: var y = Math.random() * n - n2;
webgl_buffergeometry_points_interleaved.html: var z = Math.random() * n - n2;
webgl_buffergeometry_rawshader.html: positions.push( Math.random() - 0.5 );
webgl_buffergeometry_rawshader.html: positions.push( Math.random() - 0.5 );
webgl_buffergeometry_rawshader.html: positions.push( Math.random() - 0.5 );
webgl_buffergeometry_rawshader.html: colors.push( Math.random() * 255 );
webgl_buffergeometry_rawshader.html: colors.push( Math.random() * 255 );
webgl_buffergeometry_rawshader.html: colors.push( Math.random() * 255 );
webgl_buffergeometry_rawshader.html: colors.push( Math.random() * 255 );
webgl_buffergeometry_selective_draw.html: var lat = ( Math.random() * Math.PI ) / 50.0 + i / numLat * Math.PI;
webgl_buffergeometry_selective_draw.html: var lng = ( Math.random() * Math.PI ) / 50.0 + j / numLng * 2 * Math.PI;
webgl_buffergeometry_selective_draw.html: if ( Math.random() > 0.75 ) {
webgl_buffergeometry_uint.html: var x = Math.random() * n - n2;
webgl_buffergeometry_uint.html: var y = Math.random() * n - n2;
webgl_buffergeometry_uint.html: var z = Math.random() * n - n2;
webgl_buffergeometry_uint.html: var ax = x + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var ay = y + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var az = z + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var bx = x + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var by = y + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var bz = z + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var cx = x + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var cy = y + Math.random() * d - d2;
webgl_buffergeometry_uint.html: var cz = z + Math.random() * d - d2;
webgl_camera_cinematic.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
webgl_camera_cinematic.html: object.position.x = Math.random() * 800 - 400;
webgl_camera_cinematic.html: object.position.y = Math.random() * 800 - 400;
webgl_camera_cinematic.html: object.position.z = Math.random() * 800 - 400;
webgl_camera_logarithmicdepthbuffer.html: materialargs.color = new THREE.Color().setHSL( Math.random(), 0.5, 0.5 );
webgl_clipping_intersection.html: color: new THREE.Color().setHSL( Math.random(), 0.5, 0.5 ),
webgl_custom_attributes.html: noise[ i ] = Math.random() * 5;
webgl_custom_attributes.html: noise[ i ] += 0.5 * ( 0.5 - Math.random() );
webgl_custom_attributes_lines.html: array[ i ] += 0.3 * ( 0.5 - Math.random() );
webgl_custom_attributes_lines.html: array[ i + 1 ] += 0.3 * ( 0.5 - Math.random() );
webgl_custom_attributes_lines.html: array[ i + 2 ] += 0.3 * ( 0.5 - Math.random() );
webgl_custom_attributes_points.html: vertex.x = ( Math.random() * 2 - 1 ) * radius;
webgl_custom_attributes_points.html: vertex.y = ( Math.random() * 2 - 1 ) * radius;
webgl_custom_attributes_points.html: vertex.z = ( Math.random() * 2 - 1 ) * radius;
webgl_custom_attributes_points3.html: vertex.x = Math.random() * 2 - 1;
webgl_custom_attributes_points3.html: vertex.y = Math.random() * 2 - 1;
webgl_custom_attributes_points3.html: vertex.z = Math.random() * 2 - 1;
webgl_decals.html: if ( params.rotate ) orientation.z = Math.random() * 2 * Math.PI;
webgl_decals.html: var scale = params.minScale + Math.random() * ( params.maxScale - params.minScale );
webgl_decals.html: material.color.setHex( Math.random() * 0xffffff );
webgl_depth_texture.html: var r = Math.random() * 2.0 * Math.PI;
webgl_depth_texture.html: var z = ( Math.random() * 2.0 ) - 1.0;
webgl_depth_texture.html: mesh.rotation.set( Math.random(), Math.random(), Math.random() );
webgl_effects_anaglyph.html: mesh.position.x = Math.random() * 10 - 5;
webgl_effects_anaglyph.html: mesh.position.y = Math.random() * 10 - 5;
webgl_effects_anaglyph.html: mesh.position.z = Math.random() * 10 - 5;
webgl_effects_anaglyph.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_effects_parallaxbarrier.html: mesh.position.x = Math.random() * 10 - 5;
webgl_effects_parallaxbarrier.html: mesh.position.y = Math.random() * 10 - 5;
webgl_effects_parallaxbarrier.html: mesh.position.z = Math.random() * 10 - 5;
webgl_effects_parallaxbarrier.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_effects_peppersghost.html: color.setHex( Math.random() * 0xffffff );
webgl_effects_peppersghost.html: cube.position.x = Math.random() * 2 - 1;
webgl_effects_peppersghost.html: cube.position.y = Math.random() * 2 - 1;
webgl_effects_peppersghost.html: cube.position.z = Math.random() * 2 - 1;
webgl_effects_peppersghost.html: cube.scale.multiplyScalar( Math.random() + 0.5 );
webgl_effects_stereo.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_effects_stereo.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_effects_stereo.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_effects_stereo.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_geometry_hierarchy.html: mesh.position.x = Math.random() * 2000 - 1000;
webgl_geometry_hierarchy.html: mesh.position.y = Math.random() * 2000 - 1000;
webgl_geometry_hierarchy.html: mesh.position.z = Math.random() * 2000 - 1000;
webgl_geometry_hierarchy.html: mesh.rotation.x = Math.random() * 2 * Math.PI;
webgl_geometry_hierarchy.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_geometry_minecraft.html: size = width * height, quality = 2, z = Math.random() * 100;
webgl_geometry_minecraft_ao.html: size = width * height, quality = 2, z = Math.random() * 100;
webgl_geometry_nurbs.html: Math.random() * 400 - 200,
webgl_geometry_nurbs.html: Math.random() * 400,
webgl_geometry_nurbs.html: Math.random() * 400 - 200,
webgl_geometry_spline_editor.html: var material = new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } );
webgl_geometry_spline_editor.html: object.position.x = Math.random() * 1000 - 500;
webgl_geometry_spline_editor.html: object.position.y = Math.random() * 600;
webgl_geometry_spline_editor.html: object.position.z = Math.random() * 800 - 400;
webgl_geometry_terrain.html: perlin = new ImprovedNoise(), quality = 1, z = Math.random() * 100;
webgl_geometry_terrain.html: var v = ~ ~ ( Math.random() * 5 );
webgl_geometry_terrain_fog.html: perlin = new ImprovedNoise(), quality = 1, z = Math.random() * 100;
webgl_geometry_terrain_fog.html: var v = ~ ~ ( Math.random() * 5 );
webgl_geometry_terrain_raycast.html: perlin = new ImprovedNoise(), quality = 1, z = Math.random() * 100;
webgl_geometry_terrain_raycast.html: var v = ~ ~ ( Math.random() * 5 );
webgl_geometry_text.html: pointLight.color.setHSL( Math.random(), 1, 0.5 );
webgl_geometry_text.html: pointLight.color.setHSL( Math.random(), 1, 0.5 );
webgl_gpgpu_birds.html: var x = Math.random() * BOUNDS - BOUNDS_HALF;
webgl_gpgpu_birds.html: var y = Math.random() * BOUNDS - BOUNDS_HALF;
webgl_gpgpu_birds.html: var z = Math.random() * BOUNDS - BOUNDS_HALF;
webgl_gpgpu_birds.html: var x = Math.random() - 0.5;
webgl_gpgpu_birds.html: var y = Math.random() - 0.5;
webgl_gpgpu_birds.html: var z = Math.random() - 0.5;
webgl_gpgpu_protoplanet.html: positions[ p ++ ] = ( Math.random() * 2 - 1 ) * effectController.radius;
webgl_gpgpu_protoplanet.html: positions[ p ++ ] = 0; //( Math.random() * 2 - 1 ) * effectController.radius;
webgl_gpgpu_protoplanet.html: positions[ p ++ ] = ( Math.random() * 2 - 1 ) * effectController.radius;
webgl_gpgpu_protoplanet.html: x = ( Math.random() * 2 - 1 );
webgl_gpgpu_protoplanet.html: z = ( Math.random() * 2 - 1 );
webgl_gpgpu_protoplanet.html: var vx = vel * z + ( Math.random() * 2 - 1 ) * randVel;
webgl_gpgpu_protoplanet.html: var vy = ( Math.random() * 2 - 1 ) * randVel * 0.05;
webgl_gpgpu_protoplanet.html: var vz = - vel * x + ( Math.random() * 2 - 1 ) * randVel;
webgl_gpgpu_protoplanet.html: y = ( Math.random() * 2 - 1 ) * height;
webgl_gpgpu_protoplanet.html: var mass = Math.random() * maxMass + 1;
webgl_gpgpu_water.html: sphere.position.x = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
webgl_gpgpu_water.html: sphere.position.z = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
webgl_instancing_modified.html: instanceColors.push( Math.random() );
webgl_instancing_modified.html: instanceColors.push( Math.random() );
webgl_instancing_modified.html: instanceColors.push( Math.random() );
webgl_instancing_performance.html: position.x = Math.random() * 40 - 20;
webgl_instancing_performance.html: position.y = Math.random() * 40 - 20;
webgl_instancing_performance.html: position.z = Math.random() * 40 - 20;
webgl_instancing_performance.html: rotation.x = Math.random() * 2 * Math.PI;
webgl_instancing_performance.html: rotation.y = Math.random() * 2 * Math.PI;
webgl_instancing_performance.html: rotation.z = Math.random() * 2 * Math.PI;
webgl_instancing_performance.html: scale.x = scale.y = scale.z = Math.random() * 1;
webgl_instancing_scatter.html: _color.setHex( blossomPalette[ Math.floor( Math.random() * blossomPalette.length ) ] );
webgl_instancing_scatter.html: ages[ i ] = Math.random();
webgl_interactive_buffergeometry.html: var x = Math.random() * n - n2;
webgl_interactive_buffergeometry.html: var y = Math.random() * n - n2;
webgl_interactive_buffergeometry.html: var z = Math.random() * n - n2;
webgl_interactive_buffergeometry.html: var ax = x + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var ay = y + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var az = z + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var bx = x + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var by = y + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var bz = z + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var cx = x + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var cy = y + Math.random() * d - d2;
webgl_interactive_buffergeometry.html: var cz = z + Math.random() * d - d2;
webgl_interactive_cubes.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
webgl_interactive_cubes.html: object.position.x = Math.random() * 800 - 400;
webgl_interactive_cubes.html: object.position.y = Math.random() * 800 - 400;
webgl_interactive_cubes.html: object.position.z = Math.random() * 800 - 400;
webgl_interactive_cubes.html: object.rotation.x = Math.random() * 2 * Math.PI;
webgl_interactive_cubes.html: object.rotation.y = Math.random() * 2 * Math.PI;
webgl_interactive_cubes.html: object.rotation.z = Math.random() * 2 * Math.PI;
webgl_interactive_cubes.html: object.scale.x = Math.random() + 0.5;
webgl_interactive_cubes.html: object.scale.y = Math.random() + 0.5;
webgl_interactive_cubes.html: object.scale.z = Math.random() + 0.5;
webgl_interactive_cubes_gpu.html: position.x = Math.random() * 10000 - 5000;
webgl_interactive_cubes_gpu.html: position.y = Math.random() * 6000 - 3000;
webgl_interactive_cubes_gpu.html: position.z = Math.random() * 8000 - 4000;
webgl_interactive_cubes_gpu.html: rotation.x = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_gpu.html: rotation.y = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_gpu.html: rotation.z = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_gpu.html: scale.x = Math.random() * 200 + 100;
webgl_interactive_cubes_gpu.html: scale.y = Math.random() * 200 + 100;
webgl_interactive_cubes_gpu.html: scale.z = Math.random() * 200 + 100;
webgl_interactive_cubes_gpu.html: applyVertexColors( geometry, color.setHex( Math.random() * 0xffffff ) );
webgl_interactive_cubes_ortho.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
webgl_interactive_cubes_ortho.html: object.position.x = Math.random() * 800 - 400;
webgl_interactive_cubes_ortho.html: object.position.y = Math.random() * 800 - 400;
webgl_interactive_cubes_ortho.html: object.position.z = Math.random() * 800 - 400;
webgl_interactive_cubes_ortho.html: object.rotation.x = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_ortho.html: object.rotation.y = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_ortho.html: object.rotation.z = Math.random() * 2 * Math.PI;
webgl_interactive_cubes_ortho.html: object.scale.x = Math.random() + 0.5;
webgl_interactive_cubes_ortho.html: object.scale.y = Math.random() + 0.5;
webgl_interactive_cubes_ortho.html: object.scale.z = Math.random() + 0.5;
webgl_interactive_lines.html: direction.x += Math.random() - 0.5;
webgl_interactive_lines.html: direction.y += Math.random() - 0.5;
webgl_interactive_lines.html: direction.z += Math.random() - 0.5;
webgl_interactive_lines.html: parentTransform.position.x = Math.random() * 40 - 20;
webgl_interactive_lines.html: parentTransform.position.y = Math.random() * 40 - 20;
webgl_interactive_lines.html: parentTransform.position.z = Math.random() * 40 - 20;
webgl_interactive_lines.html: parentTransform.rotation.x = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: parentTransform.rotation.y = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: parentTransform.rotation.z = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: parentTransform.scale.x = Math.random() + 0.5;
webgl_interactive_lines.html: parentTransform.scale.y = Math.random() + 0.5;
webgl_interactive_lines.html: parentTransform.scale.z = Math.random() + 0.5;
webgl_interactive_lines.html: var lineMaterial = new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
webgl_interactive_lines.html: if ( Math.random() > 0.5 ) {
webgl_interactive_lines.html: object.position.x = Math.random() * 400 - 200;
webgl_interactive_lines.html: object.position.y = Math.random() * 400 - 200;
webgl_interactive_lines.html: object.position.z = Math.random() * 400 - 200;
webgl_interactive_lines.html: object.rotation.x = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: object.rotation.y = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: object.rotation.z = Math.random() * 2 * Math.PI;
webgl_interactive_lines.html: object.scale.x = Math.random() + 0.5;
webgl_interactive_lines.html: object.scale.y = Math.random() + 0.5;
webgl_interactive_lines.html: object.scale.z = Math.random() + 0.5;
webgl_layers.html: object.position.x = Math.random() * 800 - 400;
webgl_layers.html: object.position.y = Math.random() * 800 - 400;
webgl_layers.html: object.position.z = Math.random() * 800 - 400;
webgl_layers.html: object.rotation.x = Math.random() * 2 * Math.PI;
webgl_layers.html: object.rotation.y = Math.random() * 2 * Math.PI;
webgl_layers.html: object.rotation.z = Math.random() * 2 * Math.PI;
webgl_layers.html: object.scale.x = Math.random() + 0.5;
webgl_layers.html: object.scale.y = Math.random() + 0.5;
webgl_layers.html: object.scale.z = Math.random() + 0.5;
webgl_lensflares.html: mesh.position.x = 8000 * ( 2.0 * Math.random() - 1.0 );
webgl_lensflares.html: mesh.position.y = 8000 * ( 2.0 * Math.random() - 1.0 );
webgl_lensflares.html: mesh.position.z = 8000 * ( 2.0 * Math.random() - 1.0 );
webgl_lensflares.html: mesh.rotation.x = Math.random() * Math.PI;
webgl_lensflares.html: mesh.rotation.y = Math.random() * Math.PI;
webgl_lensflares.html: mesh.rotation.z = Math.random() * Math.PI;
webgl_lightningstrike.html: star1.rotation.y = 2 * Math.PI * Math.random();
webgl_lights_pointlights2.html: mesh.position.x = 400 * ( 0.5 - Math.random() );
webgl_lights_pointlights2.html: mesh.position.y = 50 * ( 0.5 - Math.random() ) + 25;
webgl_lights_pointlights2.html: mesh.position.z = 200 * ( 0.5 - Math.random() );
webgl_lights_pointlights2.html: mesh.rotation.y = 3.14 * ( 0.5 - Math.random() );
webgl_lights_pointlights2.html: mesh.rotation.x = 3.14 * ( 0.5 - Math.random() );
webgl_lights_spotlights.html: angle: ( Math.random() * 0.7 ) + 0.1,
webgl_lights_spotlights.html: penumbra: Math.random() + 1
webgl_lights_spotlights.html: }, Math.random() * 3000 + 2000 )
webgl_lights_spotlights.html: x: ( Math.random() * 30 ) - 15,
webgl_lights_spotlights.html: y: ( Math.random() * 10 ) + 15,
webgl_lights_spotlights.html: z: ( Math.random() * 30 ) - 15
webgl_lights_spotlights.html: }, Math.random() * 3000 + 2000 )
webgl_lines_sphere.html: line.rotation.y = Math.random() * Math.PI;
webgl_lines_sphere.html: vertex.x = Math.random() * 2 - 1;
webgl_lines_sphere.html: vertex.y = Math.random() * 2 - 1;
webgl_lines_sphere.html: vertex.z = Math.random() * 2 - 1;
webgl_lines_sphere.html: vertex.multiplyScalar( Math.random() * 0.09 + 1 );
webgl_loader_imagebitmap.html: cube.position.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
webgl_loader_imagebitmap.html: cube.rotation.set( Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI );
webgl_loader_pcd.html: points.material.color.setHex( Math.random() * 0xffffff );
webgl_loader_ttf.html: pointLight.color.setHSL( Math.random(), 1, 0.5 );
webgl_lod.html: lod.position.x = 10000 * ( 0.5 - Math.random() );
webgl_lod.html: lod.position.y = 7500 * ( 0.5 - Math.random() );
webgl_lod.html: lod.position.z = 10000 * ( 0.5 - Math.random() );
webgl_materials.html: directionalLight.position.x = Math.random() - 0.5;
webgl_materials.html: directionalLight.position.y = Math.random() - 0.5;
webgl_materials.html: directionalLight.position.z = Math.random() - 0.5;
webgl_materials.html: mesh.rotation.x = Math.random() * 200 - 100;
webgl_materials.html: mesh.rotation.y = Math.random() * 200 - 100;
webgl_materials.html: mesh.rotation.z = Math.random() * 200 - 100;
webgl_materials_compile.html: var speed = new FloatNode( Math.random() );
webgl_materials_compile.html: var color = new ColorNode( Math.random() * 0xFFFFFF );
webgl_materials_compile.html: var transformer = new ExpressionNode( "position + 0.0 * " + Math.random(), "vec3", [ ] );
webgl_materials_cubemap_balls_reflection.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_reflection.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_reflection.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_reflection.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_materials_cubemap_balls_refraction.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_refraction.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_refraction.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_materials_cubemap_balls_refraction.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_materials_grass.html: context.fillStyle = 'hsl(0,0%,' + ( Math.random() * 50 + 50 ) + '%)';
webgl_materials_grass.html: context.arc( Math.random() * canvas.width, Math.random() * canvas.height, Math.random() + 0.15, 0, Math.PI * 2, true );
webgl_materials_shaders_fresnel.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_materials_shaders_fresnel.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_materials_shaders_fresnel.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_materials_shaders_fresnel.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 3 + 1;
webgl_materials_texture_partialupdate.html: color.setHex( Math.random() * 0xffffff );
webgl_materials_video.html: mesh.dx = 0.001 * ( 0.5 - Math.random() );
webgl_materials_video.html: mesh.dy = 0.001 * ( 0.5 - Math.random() );
webgl_math_obb.html: object.position.x = Math.random() * 80 - 40;
webgl_math_obb.html: object.position.y = Math.random() * 80 - 40;
webgl_math_obb.html: object.position.z = Math.random() * 80 - 40;
webgl_math_obb.html: object.rotation.x = Math.random() * 2 * Math.PI;
webgl_math_obb.html: object.rotation.y = Math.random() * 2 * Math.PI;
webgl_math_obb.html: object.rotation.z = Math.random() * 2 * Math.PI;
webgl_math_obb.html: object.scale.x = Math.random() + 0.5;
webgl_math_obb.html: object.scale.y = Math.random() + 0.5;
webgl_math_obb.html: object.scale.z = Math.random() + 0.5;
webgl_math_orientation_transform.html: spherical.theta = Math.random() * Math.PI * 2;
webgl_math_orientation_transform.html: spherical.phi = Math.acos( ( 2 * Math.random() ) - 1 );
webgl_modifier_tessellation.html: var h = 0.2 * Math.random();
webgl_modifier_tessellation.html: var s = 0.5 + 0.5 * Math.random();
webgl_modifier_tessellation.html: var l = 0.5 + 0.5 * Math.random();
webgl_modifier_tessellation.html: var d = 10 * ( 0.5 - Math.random() );
webgl_morphtargets.html: mesh.material.color.set( Math.random() * 0xffffff );
webgl_multiple_elements.html: var geometry = geometries[ geometries.length * Math.random() | 0 ];
webgl_multiple_elements.html: color: new THREE.Color().setHSL( Math.random(), 1, 0.75 ),
webgl_multiple_elements_text.html: var i = balls * Math.random() - balls / 2;
webgl_multiple_elements_text.html: var j = balls * Math.random() - balls / 2;
webgl_multiple_elements_text.html: var k = balls * Math.random() - balls / 2;
webgl_multiple_elements_text.html: var index = Math.floor( colors.length * Math.random() );
webgl_nearestneighbour.html: positions[ x * 3 + 0 ] = Math.random() * 1000;
webgl_nearestneighbour.html: positions[ x * 3 + 1 ] = Math.random() * 1000;
webgl_nearestneighbour.html: positions[ x * 3 + 2 ] = Math.random() * 1000;
webgl_performance.html: mesh.position.x = Math.random() * 8000 - 4000;
webgl_performance.html: mesh.position.y = Math.random() * 8000 - 4000;
webgl_performance.html: mesh.position.z = Math.random() * 8000 - 4000;
webgl_performance.html: mesh.rotation.x = Math.random() * 2 * Math.PI;
webgl_performance.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_performance.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
webgl_performance_doublesided.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_performance_doublesided.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_performance_doublesided.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_performance_doublesided.html: mesh.rotation.x = Math.random() * 2 * Math.PI;
webgl_performance_doublesided.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_performance_doublesided.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
webgl_performance_nodes.html: color = 0xFFFFFF * Math.random();
webgl_performance_nodes.html: mesh.position.x = Math.random() * 1000 - 500;
webgl_performance_nodes.html: mesh.position.y = Math.random() * 1000 - 500;
webgl_performance_nodes.html: mesh.position.z = Math.random() * 1000 - 500;
webgl_performance_nodes.html: mesh.rotation.x = Math.random() * 2 * Math.PI;
webgl_performance_nodes.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_performance_nodes.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
webgl_performance_static.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_performance_static.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_performance_static.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_performance_static.html: mesh.rotation.x = Math.random() * 2 * Math.PI;
webgl_performance_static.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_performance_static.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50 + 100;
webgl_points_billboards.html: var x = 2000 * Math.random() - 1000;
webgl_points_billboards.html: var y = 2000 * Math.random() - 1000;
webgl_points_billboards.html: var z = 2000 * Math.random() - 1000;
webgl_points_dynamic.html: clonemeshes.push( { mesh: mesh, speed: 0.5 + Math.random() } );
webgl_points_dynamic.html: mesh: mesh, verticesDown: 0, verticesUp: 0, direction: 0, speed: 15, delay: Math.floor( 200 + 200 * Math.random() ),
webgl_points_dynamic.html: start: Math.floor( 100 + 200 * Math.random() ),
webgl_points_dynamic.html: px + 1.5 * ( 0.50 - Math.random() ) * data.speed * delta,
webgl_points_dynamic.html: py + 3.0 * ( 0.25 - Math.random() ) * data.speed * delta,
webgl_points_dynamic.html: pz + 1.5 * ( 0.50 - Math.random() ) * data.speed * delta
webgl_points_dynamic.html: px - ( px - ix ) / dx * data.speed * delta * ( 0.85 - Math.random() ),
webgl_points_dynamic.html: py - ( py - iy ) / dy * data.speed * delta * ( 1 + Math.random() ),
webgl_points_dynamic.html: pz - ( pz - iz ) / dz * data.speed * delta * ( 0.85 - Math.random() )
webgl_points_sprites.html: var x = Math.random() * 2000 - 1000;
webgl_points_sprites.html: var y = Math.random() * 2000 - 1000;
webgl_points_sprites.html: var z = Math.random() * 2000 - 1000;
webgl_points_sprites.html: particles.rotation.x = Math.random() * 6;
webgl_points_sprites.html: particles.rotation.y = Math.random() * 6;
webgl_points_sprites.html: particles.rotation.z = Math.random() * 6;
webgl_postprocessing.html: mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize();
webgl_postprocessing.html: mesh.position.multiplyScalar( Math.random() * 400 );
webgl_postprocessing.html: mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 );
webgl_postprocessing.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50;
webgl_postprocessing_backgrounds.html: material.roughness = 0.5 * Math.random() + 0.25;
webgl_postprocessing_backgrounds.html: material.color.setHSL( Math.random(), 1.0, 0.3 );
webgl_postprocessing_crossfade.html: position.x = Math.random() * 10000 - 5000;
webgl_postprocessing_crossfade.html: position.y = Math.random() * 6000 - 3000;
webgl_postprocessing_crossfade.html: position.z = Math.random() * 8000 - 4000;
webgl_postprocessing_crossfade.html: rotation.x = Math.random() * 2 * Math.PI;
webgl_postprocessing_crossfade.html: rotation.y = Math.random() * 2 * Math.PI;
webgl_postprocessing_crossfade.html: rotation.z = Math.random() * 2 * Math.PI;
webgl_postprocessing_crossfade.html: scale.x = Math.random() * 200 + 100;
webgl_postprocessing_crossfade.html: scale.y = Math.random() * 200 + 100;
webgl_postprocessing_crossfade.html: scale.z = Math.random() * 200 + 100;
webgl_postprocessing_crossfade.html: color.setRGB( 0, 0, 0.1 + 0.9 * Math.random() );
webgl_postprocessing_crossfade.html: color.setRGB( 0.1 + 0.9 * Math.random(), 0, 0 );
webgl_postprocessing_dof2.html: color: 0xffffff * Math.random(),
webgl_postprocessing_dof2.html: mesh.position.x = ( Math.random() - 0.5 ) * 200;
webgl_postprocessing_dof2.html: mesh.position.y = Math.random() * 50;
webgl_postprocessing_dof2.html: mesh.position.z = ( Math.random() - 0.5 ) * 200;
webgl_postprocessing_fxaa.html: mesh.position.x = Math.random() * 500 - 250;
webgl_postprocessing_fxaa.html: mesh.position.y = Math.random() * 500 - 250;
webgl_postprocessing_fxaa.html: mesh.position.z = Math.random() * 500 - 250;
webgl_postprocessing_fxaa.html: mesh.scale.setScalar( Math.random() * 2 + 1 );
webgl_postprocessing_fxaa.html: mesh.rotation.x = Math.random() * Math.PI;
webgl_postprocessing_fxaa.html: mesh.rotation.y = Math.random() * Math.PI;
webgl_postprocessing_fxaa.html: mesh.rotation.z = Math.random() * Math.PI;
webgl_postprocessing_glitch.html: var material = new THREE.MeshPhongMaterial( { color: 0xffffff * Math.random(), flatShading: true } );
webgl_postprocessing_glitch.html: mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize();
webgl_postprocessing_glitch.html: mesh.position.multiplyScalar( Math.random() * 400 );
webgl_postprocessing_glitch.html: mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 );
webgl_postprocessing_glitch.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 50;
webgl_postprocessing_nodes.html: var material = new THREE.MeshPhongMaterial( { color: 0x888888 + ( Math.random() * 0x888888 ), flatShading: true } );
webgl_postprocessing_nodes.html: mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize();
webgl_postprocessing_nodes.html: mesh.position.multiplyScalar( Math.random() * 400 );
webgl_postprocessing_nodes.html: mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 );
webgl_postprocessing_nodes.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = 10 + ( Math.random() * 40 );
webgl_postprocessing_nodes_pass.html: var material = new THREE.MeshPhongMaterial( { color: 0x888888 + ( Math.random() * 0x888888 ), flatShading: true } );
webgl_postprocessing_nodes_pass.html: mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize();
webgl_postprocessing_nodes_pass.html: mesh.position.multiplyScalar( Math.random() * 400 );
webgl_postprocessing_nodes_pass.html: mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 );
webgl_postprocessing_nodes_pass.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = 10 + ( Math.random() * 40 );
webgl_postprocessing_outline.html: material.color.setHSL( Math.random(), 1.0, 0.3 );
webgl_postprocessing_outline.html: mesh.position.x = Math.random() * 4 - 2;
webgl_postprocessing_outline.html: mesh.position.y = Math.random() * 4 - 2;
webgl_postprocessing_outline.html: mesh.position.z = Math.random() * 4 - 2;
webgl_postprocessing_outline.html: mesh.scale.multiplyScalar( Math.random() * 0.3 + 0.1 );
webgl_postprocessing_pixel.html: var geom = geometries[ Math.floor( Math.random() * geometries.length ) ];
webgl_postprocessing_pixel.html: color.setHSL( Math.random(), .7 + .2 * Math.random(), .5 + .1 * Math.random() );
webgl_postprocessing_pixel.html: var s = 4 + Math.random() * 10;
webgl_postprocessing_pixel.html: mesh.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 ).normalize();
webgl_postprocessing_pixel.html: mesh.position.multiplyScalar( Math.random() * 200 );
webgl_postprocessing_pixel.html: mesh.rotation.set( Math.random() * 2, Math.random() * 2, Math.random() * 2 );
webgl_postprocessing_rgb_halftone.html: mesh.position.set( Math.random() * 16 - 8, Math.random() * 16 - 8, Math.random() * 16 - 8 );
webgl_postprocessing_rgb_halftone.html: mesh.rotation.set( Math.random() * Math.PI * 2, Math.random() * Math.PI * 2, Math.random() * Math.PI * 2 );
webgl_postprocessing_sao.html: material.roughness = 0.5 * Math.random() + 0.25;
webgl_postprocessing_sao.html: material.color.setHSL( Math.random(), 1.0, 0.3 );
webgl_postprocessing_sao.html: mesh.position.x = Math.random() * 4 - 2;
webgl_postprocessing_sao.html: mesh.position.y = Math.random() * 4 - 2;
webgl_postprocessing_sao.html: mesh.position.z = Math.random() * 4 - 2;
webgl_postprocessing_sao.html: mesh.rotation.x = Math.random();
webgl_postprocessing_sao.html: mesh.rotation.y = Math.random();
webgl_postprocessing_sao.html: mesh.rotation.z = Math.random();
webgl_postprocessing_sao.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 0.2 + 0.05;
webgl_postprocessing_ssaa_unbiased.html: material.roughness = 0.5 * Math.random() + 0.25;
webgl_postprocessing_ssaa_unbiased.html: material.color.setHSL( Math.random(), 1.0, 0.3 );
webgl_postprocessing_ssaa_unbiased.html: mesh.position.x = Math.random() * 4 - 2;
webgl_postprocessing_ssaa_unbiased.html: mesh.position.y = Math.random() * 4 - 2;
webgl_postprocessing_ssaa_unbiased.html: mesh.position.z = Math.random() * 4 - 2;
webgl_postprocessing_ssaa_unbiased.html: mesh.rotation.x = Math.random();
webgl_postprocessing_ssaa_unbiased.html: mesh.rotation.y = Math.random();
webgl_postprocessing_ssaa_unbiased.html: mesh.rotation.z = Math.random();
webgl_postprocessing_ssaa_unbiased.html: mesh.scale.setScalar( Math.random() * 0.2 + 0.05 );
webgl_postprocessing_ssao.html: color: Math.random() * 0xffffff
webgl_postprocessing_ssao.html: mesh.position.x = Math.random() * 400 - 200;
webgl_postprocessing_ssao.html: mesh.position.y = Math.random() * 400 - 200;
webgl_postprocessing_ssao.html: mesh.position.z = Math.random() * 400 - 200;
webgl_postprocessing_ssao.html: mesh.rotation.x = Math.random();
webgl_postprocessing_ssao.html: mesh.rotation.y = Math.random();
webgl_postprocessing_ssao.html: mesh.rotation.z = Math.random();
webgl_postprocessing_ssao.html: mesh.scale.setScalar( Math.random() * 10 + 2 );
webgl_postprocessing_unreal_bloom_selective.html: color.setHSL( Math.random(), 0.7, Math.random() * 0.2 + 0.05 );
webgl_postprocessing_unreal_bloom_selective.html: sphere.position.x = Math.random() * 10 - 5;
webgl_postprocessing_unreal_bloom_selective.html: sphere.position.y = Math.random() * 10 - 5;
webgl_postprocessing_unreal_bloom_selective.html: sphere.position.z = Math.random() * 10 - 5;
webgl_postprocessing_unreal_bloom_selective.html: sphere.position.normalize().multiplyScalar( Math.random() * 4.0 + 2.0 );
webgl_postprocessing_unreal_bloom_selective.html: sphere.scale.setScalar( Math.random() * Math.random() + 0.5 );
webgl_postprocessing_unreal_bloom_selective.html: if ( Math.random() < 0.25 ) sphere.layers.enable( BLOOM_SCENE );
webgl_sandbox.html: //var index = Math.floor( Math.random() * materials.length );
webgl_sandbox.html: mesh.position.x = Math.random() * 10000 - 5000;
webgl_sandbox.html: mesh.position.y = Math.random() * 10000 - 5000;
webgl_sandbox.html: mesh.position.z = Math.random() * 10000 - 5000;
webgl_sandbox.html: //mesh.rotation.x = Math.random() * 360 * ( Math.PI / 180 );
webgl_sandbox.html: mesh.rotation.y = Math.random() * 2 * Math.PI;
webgl_sandbox.html: mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 4 + 1;
webgl_shaders_ocean.html: color.setHex( Math.random() * 0xffffff );
webgl_shadowmap.html: mesh.material.color.offsetHSL( 0, Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25 );
webgl_shadowmap.html: startAt( - duration * Math.random() ).
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, 300, true );
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, 450, true );
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, 600, true );
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, - 300, true );
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, - 450, true );
webgl_shadowmap.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 1000, FLOOR, - 600, true );
webgl_shadowmap.html: addMorph( mesh, clip, 500, 1, 500 - Math.random() * 500, FLOOR + 350, 40 );
webgl_shadowmap.html: addMorph( mesh, clip, 350, 1, 500 - Math.random() * 500, FLOOR + 350, 340 );
webgl_shadowmap.html: addMorph( mesh, clip, 450, 0.5, 500 - Math.random() * 500, FLOOR + 300, 700 );
webgl_shadowmap.html: morph.position.x = - 1000 - Math.random() * 500;
webgl_shadowmap_csm.html: cube1.scale.y = Math.random() * 2 + 6;
webgl_shadowmap_csm.html: cube2.scale.y = Math.random() * 2 + 6;
webgl_shadowmap_pcss.html: var material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );
webgl_shadowmap_pcss.html: sphere.position.x = Math.random() - 0.5;
webgl_shadowmap_pcss.html: sphere.position.z = Math.random() - 0.5;
webgl_shadowmap_pcss.html: sphere.position.multiplyScalar( Math.random() * 2 + 1 );
webgl_shadowmap_pcss.html: sphere.userData.phase = Math.random() * Math.PI;
webgl_shadowmap_performance.html: mesh.material.color.offsetHSL( 0, Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25 );
webgl_shadowmap_performance.html: var index = Math.floor( Math.random() * ANIMATION_GROUPS ),
webgl_shadowmap_performance.html: var randomness = 0.6 * Math.random() - 0.3;
webgl_shadowmap_performance.html: startAt( - duration * Math.random() ).
webgl_shadowmap_performance.html: addMorph( mesh, clip, 550, 1, 100 - Math.random() * 3000, FLOOR, i, true, true );
webgl_shadowmap_performance.html: morph.position.x = - 1000 - Math.random() * 500;
webgl_simple_gi.html: materials.push( new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, side: THREE.BackSide } ) );
webgl_sprites.html: var x = Math.random() - 0.5;
webgl_sprites.html: var y = Math.random() - 0.5;
webgl_sprites.html: var z = Math.random() - 0.5;
webgl_sprites.html: material.color.setHSL( 0.5 * Math.random(), 0.75, 0.5 );
webgl_test_memory.html: context.fillStyle = 'rgb(' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ',' + Math.floor( Math.random() * 256 ) + ')';
webgl_test_memory.html: var geometry = new THREE.SphereBufferGeometry( 50, Math.random() * 64, Math.random() * 32 );
webgl_test_memory2.html: mesh.position.x = ( 0.5 - Math.random() ) * 1000;
webgl_test_memory2.html: mesh.position.y = ( 0.5 - Math.random() ) * 1000;
webgl_test_memory2.html: mesh.position.z = ( 0.5 - Math.random() ) * 1000;
webgl_test_memory2.html: return fragmentShader.replace( "XXX", Math.random() + "," + Math.random() + "," + Math.random() );
webgl_tiled_forward.html: var tIndex = Math.round( Math.random() * 3 );
webgl_tiled_forward.html: var color = new THREE.Color().setHSL( Math.random(), 1.0, 0.5 );
webgl_tiled_forward.html: sy: Math.random(),
webgl_tiled_forward.html: sr: Math.random(),
webgl_tiled_forward.html: sc: Math.random(),
webgl_tiled_forward.html: py: Math.random() * Math.PI,
webgl_tiled_forward.html: pr: Math.random() * Math.PI,
webgl_tiled_forward.html: pc: Math.random() * Math.PI,
webgl_tiled_forward.html: dir: Math.random() > 0.5 ? 1 : - 1
webgl_trails.html: positions.push( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 );
webgl_trails.html: var clr = colorArray[ Math.floor( Math.random() * colorArray.length ) ];
webxr_ar_cones.html: var material = new THREE.MeshPhongMaterial( { color: 0xffffff * Math.random() } );
webxr_ar_hittest.html: var material = new THREE.MeshPhongMaterial( { color: 0xffffff * Math.random() } );
webxr_ar_hittest.html: mesh.scale.y = Math.random() * 2 + 1;
webxr_vr_ballshooter.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
webxr_vr_ballshooter.html: object.position.x = Math.random() * 4 - 2;
webxr_vr_ballshooter.html: object.position.y = Math.random() * 4;
webxr_vr_ballshooter.html: object.position.z = Math.random() * 4 - 2;
webxr_vr_ballshooter.html: object.userData.velocity.x = Math.random() * 0.01 - 0.005;
webxr_vr_ballshooter.html: object.userData.velocity.y = Math.random() * 0.01 - 0.005;
webxr_vr_ballshooter.html: object.userData.velocity.z = Math.random() * 0.01 - 0.005;
webxr_vr_ballshooter.html: object.userData.velocity.x = ( Math.random() - 0.5 ) * 3;
webxr_vr_ballshooter.html: object.userData.velocity.y = ( Math.random() - 0.5 ) * 3;
webxr_vr_ballshooter.html: object.userData.velocity.z = ( Math.random() - 9 );
webxr_vr_cubes.html: var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
webxr_vr_cubes.html: object.position.x = Math.random() * 4 - 2;
webxr_vr_cubes.html: object.position.y = Math.random() * 4;
webxr_vr_cubes.html: object.position.z = Math.random() * 4 - 2;
webxr_vr_cubes.html: object.rotation.x = Math.random() * 2 * Math.PI;
webxr_vr_cubes.html: object.rotation.y = Math.random() * 2 * Math.PI;
webxr_vr_cubes.html: object.rotation.z = Math.random() * 2 * Math.PI;
webxr_vr_cubes.html: object.scale.x = Math.random() + 0.5;
webxr_vr_cubes.html: object.scale.y = Math.random() + 0.5;
webxr_vr_cubes.html: object.scale.z = Math.random() + 0.5;
webxr_vr_cubes.html: object.userData.velocity.x = Math.random() * 0.01 - 0.005;
webxr_vr_cubes.html: object.userData.velocity.y = Math.random() * 0.01 - 0.005;
webxr_vr_cubes.html: object.userData.velocity.z = Math.random() * 0.01 - 0.005;
webxr_vr_cubes.html: cube.userData.velocity.x = ( Math.random() - 0.5 ) * 0.02 * delta;
webxr_vr_cubes.html: cube.userData.velocity.y = ( Math.random() - 0.5 ) * 0.02 * delta;
webxr_vr_cubes.html: cube.userData.velocity.z = ( Math.random() * 0.01 - 0.05 ) * delta;
webxr_vr_dragging.html: var geometry = geometries[ Math.floor( Math.random() * geometries.length ) ];
webxr_vr_dragging.html: color: Math.random() * 0xffffff,
webxr_vr_dragging.html: object.position.x = Math.random() * 4 - 2;
webxr_vr_dragging.html: object.position.y = Math.random() * 2;
webxr_vr_dragging.html: object.position.z = Math.random() * 4 - 2;
webxr_vr_dragging.html: object.rotation.x = Math.random() * 2 * Math.PI;
webxr_vr_dragging.html: object.rotation.y = Math.random() * 2 * Math.PI;
webxr_vr_dragging.html: object.rotation.z = Math.random() * 2 * Math.PI;
webxr_vr_dragging.html: object.scale.setScalar( Math.random() + 0.5 );
webxr_vr_lorenzattractor.html: var x = 15 * Math.random();
webxr_vr_lorenzattractor.html: var y = 15 * Math.random();
webxr_vr_lorenzattractor.html: var z = 15 * Math.random();
webxr_vr_rollercoaster.html: vertex.x += Math.random() * 10 - 5;
webxr_vr_rollercoaster.html: vertex.z += Math.random() * 10 - 5;
webxr_vr_rollercoaster.html: vertex.y = Math.random() * Math.max( 0, distance );
@mrdoob Well, that is compelling. :-)
If @EthanHermsey wants to add Vector*.random()
in [ 0, 1 ], that would be OK with me.
@EthanHermsey would you like to create a PR with the proposed approach?
@mrdoob That's a sizeable list. That's exactly what i was talking about.
If @EthanHermsey wants to add Vector*.random() in [ 0, 1 ], that would be OK with me.
That's a perfect solution. I will submit a PR.
Most helpful comment
You are right. Unless @mrdoob has a different opinion, I think I would prefer to wait if there are more similar feature requests in the future. Something like
examples/jsm/math/Sampling.js
orexamples/jsm/math/Random.js
can still be added then.