Skip to content

Commit 474422a

Browse files
Add default colors to primitives and lights
Update the documentation. Update CHANGES.md.
1 parent e729ef3 commit 474422a

26 files changed

+36
-35
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Improvements:
1111
- Improve performance of cones by ~6x (#64)
1212
- Improve performance of arrows (#66)
1313
- Improve performance of cylinders (#67)
14+
- Add default colors to primitives and lights (#75)
1415

1516
Documentation:
1617
- Add more examples (#59)

docs/lights/ambient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33

44
Add ambient light to the scene.
55

docs/lights/directional.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord](/mathics-threejs-backend/types/coord)) — initial light position in [spherical polar coordinates](https://en.wikipedia.org/wiki/Spherical_coordinate_system)
44

55
Add an infinitely far camera-follower light to the scene.

docs/lights/point.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord](/mathics-threejs-backend/types/coord)) — point coordinates
44

55
Add a light that gets emitted from `coords` in all directions to the scene.

docs/lights/spot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Properties:
22
- `angle` (type: number) — the maximum angle in radians of light dispersion (upper bound is pi/2), default: pi/2
3-
- `color` (type: [color](/mathics-threejs-backend/types/color))
3+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
44
- `coords` (type: [coord](/mathics-threejs-backend/types/coord))
55
- `target` (type: [coord](/mathics-threejs-backend/types/coord))
66

docs/primitives/arrow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: black
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of arrow line-segment coordinates
44
- `opacity` (type: number) — default: `1`
55

docs/primitives/cone.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Properties:
2-
- `color` (type: [color/mathics-threejs-backend/types/color))
2+
- `color` (type: [color/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord[]/mathics-threejs-backend/types/coord)) — array of cylinders' centers
44
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
5-
- `color` (type: [color/mathics-threejs-backend/types/color)) — edges' color, default: `[0, 0, 0]` (black edges)
5+
- `color` (type: [color/mathics-threejs-backend/types/color)) — edges' color, default: black
66
- `showEdges` (type: bool) — default: `true`
77
- `radius` (type: number) — default: `1`
88
- `opacity` (type: number) — default: `1`

docs/primitives/cuboid.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Properties:
2-
- `color` (type: [color](documentation/types/color))
2+
- `color` (type: [color](documentation/types/color)) — default: white
33
- `coords` (type: [coord[]](documentation/types/coord)) — array of the cuboids' begins and ends
44
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
5-
- `color` (type: [color](documentation/types/color)) — edges' color, default: `[0, 0, 0]` (black edges)
5+
- `color` (type: [color](documentation/types/color)) — edges' color, default: black
66
- `showEdges` (type: bool) — default: `true`
77
- `opacity` (type: number) — default: `1`
88

docs/primitives/cylinder.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of cylinders' centers
44
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
5-
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: `[0, 0, 0]` (black edges)
5+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black
66
- `showEdges` (type: bool) — default: `true`
77
- `radius` (type: number) — default: `1`
88
- `opacity` (type: number) — default: `1`

docs/primitives/line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: black
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of line-segment coordinates
44
- `dashed` (type: bool) — whether the line is dashed, default: `false`
55
- `gapSize` (type: number) — the size of the gaps in pixels, default: `10`

docs/primitives/point.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: black
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of each point location
44
- `opacity` (type: number) — default: `1`
55
- `pointSize` (type: number)

docs/primitives/polygon.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
3-
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of ordered points tracing the boundary of the polygon
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
3+
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of ordered points tracing the boundary of the polygon, aka. the polygon vertices
44
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
5-
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: `[0, 0, 0]` (black edges)
5+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black
66
- `showEdges` (type: bool) — default: `true`
77
- `opacity` (type: number) — default: `1`
88
- `vertexNormals` (type: number[3][]) — this is not commonly used. This changes the way the polygon reflects the light. If this is smaller than the number of total vertexNormals of the polygon, the other vertexNormals are going to be calculated in the shader. See [vertex normal in Wikipedia](https://en.wikipedia.org/wiki/Vertex_normal). Default: `[]`
99

10-
Draw a polygon with no holes in it, its vertices are `coords`, it can be non-coplanar and non-triangular.
10+
Draw a polygon with no holes in it, it can be non-coplanar and non-triangular.
1111

1212
## Examples
1313
- ```jsonc

docs/primitives/sphere.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of sphere centers
44
- `opacity` (type: number) — default: `1`
55
- `radius` (type: number) — default: `1`

docs/primitives/tube.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — draw a tube passing through these coordinates
44
- `opacity` (type: number) — default: `1`
55
- `radius` (type: number) — default: `1`

docs/primitives/uniformPolyhedron.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Properties:
2-
- `color` (type: [color](/mathics-threejs-backend/types/color))
2+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
33
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of polyhedrons' center
44
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
5-
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: `[0, 0, 0]` (black edges)
5+
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black
66
- `showEdges` (type: bool) — default: `true`
77
- `edgeLength` (type: number) — default: `1`
88
- `opacity` (type: number) — default: `1`

src/lights.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export function positionLights(lights, theta, phi, focus) {
4848
}
4949

5050
export default {
51-
ambient: ({ color }) => {
51+
ambient: ({ color = [1, 1, 1] }) => {
5252
return new AmbientLight(new Color(...color).getHex());
5353
},
54-
directional: ({ color }) => {
54+
directional: ({ color = [1, 1, 1] }) => {
5555
return new DirectionalLight(new Color(...color).getHex());
5656
},
57-
spot: ({ angle = 1.57079632679, color, coords, target }, extent) => {
57+
spot: ({ angle = 1.57079632679, color = [1, 1, 1], coords, target }, extent) => {
5858
const light = new SpotLight(new Color(...color).getHex());
5959

6060
light.position.set(
@@ -75,7 +75,7 @@ export default {
7575

7676
return group;
7777
},
78-
point: ({ color, coords }, extent) => {
78+
point: ({ color = [1, 1, 1], coords }, extent) => {
7979
const light = new PointLight(new Color(...color).getHex());
8080

8181
light.position.set(

src/primitives/arrow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getBasicMaterial } from '../shader.js';
1515

1616
// See https://reference.wolfram.com/language/ref/Arrow
1717
// for the high-level description of what is being rendered.
18-
export default function ({ color, coords, opacity = 1 }, extent) {
18+
export default function ({ color = [0, 0, 0], coords, opacity = 1 }, extent) {
1919
const material = getBasicMaterial(color, opacity);
2020

2121
const group = new Group();

src/primitives/cone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { get2CoordinatesMaterial } from '../shader.js';
1313

1414
// See https://reference.wolfram.com/language/ref/Cone
1515
// for the high-level description of what is being rendered.
16-
export default function ({ color, coords, edgeForm = {}, opacity = 1, radius = 1 }, extent) {
16+
export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1, radius = 1 }, extent) {
1717
const [coneBases, coneTips] = get2PopulatedCoordinateBuffers(coords, extent);
1818

1919
const vertexPosition0 = 0.2588 * radius,

src/primitives/cuboid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { get2PopulatedCoordinateBuffers } from '../bufferUtils.js';
1111

1212
// See https://reference.wolfram.com/language/ref/Cuboid
1313
// for the high-level description of what is being rendered.
14-
export default function ({ color, coords, edgeForm = {}, opacity = 1 }, extent) {
14+
export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1 }, extent) {
1515
// The edges of the cuboids are drawn in the fragment shader; doing this is faster than putting the edges in a different object.
1616

1717
const [cuboidsBegin, cuboidsEnd] = get2PopulatedCoordinateBuffers(coords, extent);

src/primitives/cylinder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { get2CoordinatesMaterial } from '../shader.js';
1313

1414
// See https://reference.wolfram.com/language/ref/Cylinder
1515
// for the high-level description of what is being rendered.
16-
export default function ({ color, coords, edgeForm = {}, opacity = 1, radius = 1 }, extent) {
16+
export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1, radius = 1 }, extent) {
1717
const [cylindersBegin, cylindersEnd] = get2PopulatedCoordinateBuffers(coords, extent);
1818

1919
const vertexPosition0 = 0.2588 * radius,

src/primitives/line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getBasicMaterial } from '../shader.js';
1212
// for the high-level description of what is being rendered.
1313
// Differently from WL's Line, our lines aren't affected by
1414
// lightning and therefore don't have VertexNormals.
15-
export default function ({ color, coords, dashed = false, gapSize = 10, opacity = 1 }, extent, canvasSize) {
15+
export default function ({ color = [0, 0, 0], coords, dashed = false, gapSize = 10, opacity = 1 }, extent, canvasSize) {
1616
return new Line(
1717
new BufferGeometry().setAttribute(
1818
'position',

src/primitives/point.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getPopulatedCoordinateBuffer } from '../bufferUtils.js';
1111
// for the high-level description of what is being rendered.
1212
// Differently from WL's Point, our points aren't affected by
1313
// lightning and therefore don't have VertexNormals.
14-
export default function ({ color, coords, opacity = 1, pointSize }, extent, canvasSize) {
14+
export default function ({ color = [0, 0, 0], coords, opacity = 1, pointSize }, extent, canvasSize) {
1515
return new Points(
1616
new BufferGeometry().setAttribute(
1717
'position',

src/primitives/polygon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function getCoplanarityAndNormal(coordinates, extent) {
8282

8383
// See https://reference.wolfram.com/language/ref/Polygon
8484
// for the high-level description of what is being rendered.
85-
export default function ({ color, coords, edgeForm = {}, opacity = 1, vertexNormals = {} }, extent) {
85+
export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1, vertexNormals = {} }, extent) {
8686
let geometry;
8787

8888
if (coords.length === 3) { // triangle

src/primitives/sphere.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getPopulatedCoordinateBuffer } from '../bufferUtils.js';
1111

1212
// See https://reference.wolfram.com/language/ref/Sphere
1313
// for the high-level description of what is being rendered.
14-
export default function ({ color, coords, opacity = 1, radius = 1 }, extent) {
14+
export default function ({ color = [1, 1, 1], coords, opacity = 1, radius = 1 }, extent) {
1515
const sphereGeometry = new InstancedBufferGeometry().copy(
1616
new SphereGeometry(radius, 48, 48)
1717
);

src/primitives/tube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function mergeBufferGeometries(geometries) {
6666

6767
// See https://reference.wolfram.com/language/ref/Tube.html
6868
// for the high-level description of what is being rendered.
69-
export default function ({ color, coords, opacity = 1, radius = 1 }, extent) {
69+
export default function ({ color = [1, 1, 1], coords, opacity = 1, radius = 1 }, extent) {
7070
// TubeGeometry receives a Curve, but Mathics' Tube recives an array of coordinates, so we use CatmullRomCurve3 to convert the coordinates into a Curve.
7171
// Curve.getPoint receives a flot between 0 and 1, where 0 is the 1st coordinate and 1 is the last.
7272
const curve = new CatmullRomCurve3(

src/primitives/uniformPolyhedron.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getPopulatedCoordinateBuffer } from '../bufferUtils.js';
1414

1515
// See https://reference.wolfram.com/language/ref/UniformPolyhedron
1616
// for the high-level description of what is being rendered.
17-
export default function ({ color, coords, edgeForm = {}, edgeLength = 1, opacity = 1, subType }, extent) {
17+
export default function ({ color = [1, 1, 1], coords, edgeForm = {}, edgeLength = 1, opacity = 1, subType }, extent) {
1818
const polyhedronGeometry = new InstancedBufferGeometry();
1919

2020
// The magic numbers below are modified from the position attribute of,

0 commit comments

Comments
 (0)