Exploring color in Three.js. Code starting point is the Creating a scene introduction on the three.js documentation site.
Branch: https://github.com/mrjasonweaver/threejs-color/tree/color-basics
Adds basic color creation and manipulation examples
- Initialize a color with
Color( r : Color_Hex_or_String, g : Float, b : Float )
- Hexadecimal is recommended:
const white = new THREE.Color( 0xffffff );
- RGB string:
const white = new THREE.Color('rgb(255,255,255)');
- Separate RGB values between 0 and 1:
const white = new THREE.Color(1, 1, 1);
- Alpha transparency support:
const renderer = new THREE.WebGLRenderer({ alpha: true });
scene.background = white;
- Setting color:
cube.material.color.set(cubeColor);
- Setting
cubeColor
on keyboard user input
Branch: https://github.com/mrjasonweaver/threejs-color/tree/color-tweening
Adds color tweening example
- Defining the cube state object
- Defining
tweenColors()
function
- Using
requestAnimationFrame
Color.equals()
to test if 2 colors are the same
Branch: https://github.com/mrjasonweaver/threejs-color/tree/color-mesh-standard-material-lighting
Adds MeshStandardMaterial and directionalLighting
- Defining
MeshStandardMaterial
to use for the cube - Change the default cube color from black to grey
- Adding
directionalLight
to the scene - Adjust lighting position