New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mathicsorg/mathics-threejs-backend

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mathicsorg/mathics-threejs-backend - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

.github/workflows/gh-release.yml

4

docs/developers/polygons.md

@@ -62,5 +62,5 @@ There are 3 types of polygons:

To test the coplanarity of the polygon we create a
To test whether a polygon is coplanar we create a
[plane](https://en.wikipedia.org/wiki/Plane_(geometry)) using the 1st, 2nd
and last coordinates of the polygon (these coordinates are choosen
and last coordinates of the polygon (these coordinates are chosen
because the vectors 1st->2nd and last->2nd have different directions,

@@ -67,0 +67,0 @@ what is necessary to build the

Welcome to the mathics-threejs-backend documentation!
You can use mathics-threejs-backend in 2 ways:
- **production** — a stable release. To use either use the content-development network (CDN) or host the files in your own webserver:
- **production** — a stable release. To use either use the content-development network (CDN) or host the files in your own web-server:
- to use the CDN:

@@ -39,3 +39,3 @@ ```html

- `elements` (type: [element[]](/mathics-threejs-backend/types/color) — array of primitives, default: `[]`
- `extent` (type: object) — the size of the bounding box. This is optional, only use this if you don't want the default behaviour. This is an object with the following properties:
- `extent` (type: object) — the size of the bounding box. This is optional, only use this if you don't want the default behavior. This is an object with the following properties:
- `xmin` (type: number)

@@ -49,3 +49,3 @@ - `ymin` (type: number)

- `viewpoint` (type: number[3]) — the normalized camera coordinate (normalized means that the coordinate is going to be scaled, e.g. `[1, 1, 1]` is the upper back right corner of the bounding box independently from its size). Default: `[1.3, -2.4, 2]`
- `protocol` (type: string) — protocol version (current is `1.2`), if it isn't compatible a warning is shown instead of the graphics. Only availiable in production version
- `protocol` (type: string) — protocol version (current is `1.3`), if it isn't compatible a warning is shown instead of the graphics. Only available in production version

@@ -95,7 +95,7 @@ ## Examples

viewpoint: [2, -4, 4],
protocol: '1.2'
protocol: '1.3'
}
);
```
<div style='width: 75vw; height: 75vw; max-width: 500px; max-height: 500px;' class='center' id='graphics-container-1'></div>
<div style='width: 75vw; height: 75vw; max-width: 500px; max-height: 500px; position: relative;' class='center' id='graphics-container-1'></div>
<script>

@@ -143,3 +143,3 @@ drawGraphics3d(

viewpoint: [2, -4, 4],
protocol: '1.2'
protocol: '1.3'
},

@@ -146,0 +146,0 @@ 600, // maxSize

See our gallery:
<!--
in the examples you'll see that the path to the build file is 'build.js',
not '../build.js'. This happens because Jekyll "copy all files to the root
folder of the documentation (/docs)".
-->
<!-- each graphics container MUST have an UNIQUE id -->
<!-- filename aplhabetic order -->
- [Black point](examples/black-point)
- [Colorful sphere](examples/colorful-sphere)
- [Complex tube](examples/complex-tube)
- [Simple cone](examples/cone)
- [2 connected cones with edges](examples/cones-with-edges)
- [2 connected cylinders](examples/connected-cylinders)
- [Coplanar polygon](examples/coplanar-polygon)
- [Cube and parallelepiped](examples/cube-and-parallelepiped)
- [Cylinders with green edges](examples/cylinder-with-green-edges)
- [Dashed line](examples/dashed-line)
- [Dodecahedron](examples/dodecahedron)
- [Icosahedron](examples/icosahedron)
- [Polygon with multiple faces](examples/multi-face-polygon)
- [Objects in directional light](examples/objects-in-directional-light)
- [Octahedron](examples/octahedron)
- [White sphere with orange ambient light](examples/orange-ambient-light)
- [Polygon with custom vertex normals](examples/polygon-vertex-normals)
- [Polygon with edges](examples/polygon-with-edges)
- [Red arrow](examples/red-arrow)
- [Red cube with blue-green edges](examples/red-cube-with-blue-green-edges)
- [Simple tube](examples/simple-tube)
- [Sine points](examples/sine-points)
- [White sphere with directional light](examples/sphere-with-directional-light)
- [Spheres with center pointlight](examples/spheres-with-center-pointlight)
- [Tetrahedron](examples/tetrahedron)
- [Triangle with edges](examples/triangle-with-edges)
- [Tube, dodecahedrons and spheres](examples/tube-dodecahedrons-and-spheres)
- [Yellow line](examples/yellow-line)
- [Sphere with yellow spotlight](examples/yellow-spotlight)
- [Yellow triangle](examples/yellow-triangle)
<!-- description alphabetic order -->
- [☆ 2 connected cones with edges](examples/cones-with-edges)
- [☆ 2 connected cylinders](examples/connected-cylinders)
- [● Black point](examples/black-point)
- [△ Coplanar polygon](examples/coplanar-polygon)
- [○ Colorful sphere](examples/colorful-sphere)
- [☆ Complex tube](examples/complex-tube)
- [□ Cube and parallelepiped](examples/cube-and-parallelepiped)
- [☆ Cylinders with green edges](examples/cylinder-with-green-edges)
- [⁄ Dashed line](examples/dashed-line)
- [⬠ Dodecahedron](examples/dodecahedron)
- [⬠ Icosahedron](examples/icosahedron)
- [☆ Objects in directional light](examples/objects-in-directional-light)
- [⬠ Octahedron](examples/octahedron)
- [△ Polygon with custom vertex normals](examples/polygon-vertex-normals)
- [△ Polygon with edges](examples/polygon-with-edges)
- [△ Polygon with multiple faces](examples/multi-face-polygon)
- [➚ Red arrow](examples/red-arrow)
- [□ Red cube with blue-green edges](examples/red-cube-with-blue-green-edges)
- [☆ Simple cone](examples/cone)
- [☆ Simple tube](examples/simple-tube)
- [● Sine points](examples/sine-points)
- [○ Sphere with yellow spotlight](examples/yellow-spotlight)
- [○ Spheres with center point light](examples/spheres-with-center-pointlight)
- [⬠ Tetrahedron](examples/tetrahedron)
- [△ Triangle with edges](examples/triangle-with-edges)
- [☆ Tube, dodecahedrons and spheres](examples/tube-dodecahedrons-and-spheres)
- [○ White sphere with directional light](examples/sphere-with-directional-light)
- [○ White sphere with orange ambient light](examples/orange-ambient-light)
- [⁄ Yellow line](examples/yellow-line)
- [△ Yellow triangle](examples/yellow-triangle)

@@ -5,8 +5,10 @@ Welcome to the mathics-threejs-backend documentation and examples!

This can be used in Mathics front ends like [Mathics-Django](https://pypi.org/project/Mathics-Django/) and [Symja](https://github.com/axkr/symja_android_library) to handle 3D graphics. The code may also be useful as a guide for other kinds of Mathics/WL frontends to other kinds of JavaScript graphics engines.
This can be used in Mathics front ends like [Mathics-Django](https://pypi.org/project/Mathics-Django/) and [Symja](https://github.com/axkr/symja_android_library) to handle 3D graphics. The code may also be useful as a guide for other kinds of Mathics/WL front-ends to other kinds of JavaScript graphics engines.
See [our gallery](examples).
See [the live benchmarks](benchmarks).
See [the documentation](documentation).
[View the project on GitHub](https://github.com/Mathics3/mathics-threejs-backend).
Properties:
- `color` (type: [color/mathics-threejs-backend/types/color)) — default: white
- `coords` (type: [coord[]/mathics-threejs-backend/types/coord)) — array of cylinders' centers
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of cylinders' centers
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
- `color` (type: [color/mathics-threejs-backend/types/color)) — edges' color, default: black
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black
- `showEdges` (type: bool) — default: `true`

@@ -7,0 +7,0 @@ - `radius` (type: number) — default: `1`

Properties:
- `color` (type: [color](documentation/types/color)) — default: white
- `coords` (type: [coord[]](documentation/types/coord)) — array of the cuboids' begins and ends
- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white
- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of the cuboids' begins and ends
- `edgeForm` (type: object) — default: `{}`, object with the following properties:
- `color` (type: [color](documentation/types/color)) — edges' color, default: black
- `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black
- `showEdges` (type: bool) — default: `true`

@@ -7,0 +7,0 @@ - `opacity` (type: number) — default: `1`

@@ -56,3 +56,4 @@ Primitives are basic 3d objects that can build more complex shapes.

- [sphere](sphere)
- [text](text)
- [tube](tube)
- [uniformPolyhedron](uniformPolyhedron)

@@ -73,2 +73,2 @@ Properties:

## Notes
- Our behavor is different from Wolframs Language's Line; our lines aren't affected by the lighting and therefore don't have VertexNormals.
- Our behavior is different from Wolframs Language's Line; our lines aren't affected by the lighting and therefore don't have VertexNormals.

@@ -99,2 +99,2 @@ Properties:

## Notes
- Our behavor is different from Wolframs Language's Point, our points aren't affected by lighting and therefore don't have VertexNormals.
- Our behavior is different from Wolframs Language's Point, our points aren't affected by lighting and therefore don't have VertexNormals.

@@ -1,2 +0,2 @@

A HTML element obtained with `document.getElementById` or similars.
A HTML element obtained with `document.getElementById` or similar.

@@ -3,0 +3,0 @@ The canvas will occupy the whole container.

@@ -13,3 +13,3 @@ import puppeteer from 'puppeteer';

const page = await browser.newPage();
await page.goto(`http://localhost:8080/examples/test/${file}`);
await page.goto(`http://localhost:8080/tests/${file}`);
const image = await page.screenshot();

@@ -16,0 +16,0 @@

{
"name": "@mathicsorg/mathics-threejs-backend",
"version": "1.2.3",
"threejs_revision": 138,
"version": "1.3.0",
"threejs_revision": 146,
"description": "Mathics 3D Graphics backend using three.js",

@@ -40,10 +40,10 @@ "source": "src/index.js",

"eslint": "^8",
"eslint-plugin-jest": "^26",
"jest": "^28",
"jest-image-snapshot": "^5",
"eslint-plugin-jest": "^27",
"jest": "^29",
"jest-image-snapshot": "^6",
"jest-puppeteer": "^6",
"minify": "^9",
"rollup": "^2",
"rollup": "^3",
"typescript": "^4"
}
}

@@ -79,3 +79,3 @@ # mathics-threejs-backend

Lots of other examples can be found in the [examples](https://github.com/Mathics3/mathics-threejs-backend/tree/main/examples) folder of this repository and in the [documentation](https://mathics3.github.io/mathics-threejs-backend/examples).
Lots of other examples can be found in the [tests](https://github.com/Mathics3/mathics-threejs-backend/tree/main/tests) folder of this repository and in the [documentation](https://mathics3.github.io/mathics-threejs-backend/examples).

@@ -102,3 +102,3 @@ ## Displaying Examples

Server running at http://localhost:8080/
See our gallery in http://localhost:8080/examples/
See our gallery in http://localhost:8080/tests/

@@ -108,3 +108,3 @@ Hit CTRL-C to stop the server

Finally, look at a file that you want to see rendered, e.g. http://127.0.0.1:8080/examples/test/cone.html
Finally, look at a file that you want to see rendered, e.g. http://127.0.0.1:8080/tests/cone.html

@@ -111,0 +111,0 @@ For installing the development version from GitHub, see the [documentation](https://mathics3.github.io/mathics-threejs-backend/documentation).

@@ -6,3 +6,3 @@ const express = require('express');

app.use('/docs', express.static(__dirname + '/../docs'));
app.use('/examples', express.static(__dirname + '/../examples'));
app.use('/tests', express.static(__dirname + '/../tests'));
app.use('/src', express.static(__dirname + '/../src'));

@@ -15,5 +15,5 @@ app.use('/vendors', express.static(__dirname + '/../vendors'));

console.log(`Server running at http://localhost:${PORT}/`);
console.log(`See our gallery in http://localhost:${PORT}/examples/`);
console.log(`See our gallery in http://localhost:${PORT}/tests/`);
console.log();
console.log('Hit CTRL-C to stop the server');
});

@@ -73,3 +73,3 @@ // @ts-check

* coords to the 1st coordinate buffer and the odd-numbered ones to the 2nd.
* This is usuful when the primitive have a begin and a end coordinate.
* This is useful when the primitive have a begin and a end coordinate.
* Both can't be in the same BufferAttribute.

@@ -76,0 +76,0 @@ * @param {Array<[Coordinate, null] | [null, Coordinate]>} coords

@@ -66,3 +66,5 @@ // @ts-check

}));
} else {
} else if (element.type !== 'text') {
// Texts don't change the extent.
// The comments bellow are also valid for the 2nd pass.

@@ -116,3 +118,3 @@ // The extent isn't calculated correctly for cylinders, their extent should be transformationVector * radius.

if (needs2ndPass) {
// 2nd pass, necesary for primitives with scaled coordinates and
// 2nd pass, necessary for primitives with scaled coordinates and
// radius > extent.

@@ -119,0 +121,0 @@ elements.forEach((element) => {

@@ -140,3 +140,3 @@ // @ts-check

// Without this the initial axes postion is wrong.
// Without this the initial axes position is wrong.
updateCameraPosition();

@@ -300,4 +300,4 @@ camera.up.set(0, 0, 1);

// plot the primitives
elements.forEach(
(element) => scene.add(primitiveFunctions[element.type](
elements.forEach((element) => {
const sceneElement = primitiveFunctions[element.type](
element,

@@ -307,4 +307,7 @@ uniforms,

container
))
);
);
// Primitives like https://mathics3.github.io/mathics-threejs-backend/primitives/text
// don't add anything to the scene, but to the container.
if (sceneElement) scene.add(sceneElement);
});

@@ -311,0 +314,0 @@ const renderer = new WebGLRenderer({

@@ -52,7 +52,7 @@ // @ts-check

container.appendChild(warning);
} else if (parseInt(/** @type {RegExpMatchArray} */(versionArray)[1]) > 2) {
} else if (parseInt(/** @type {RegExpMatchArray} */(versionArray)[1]) > 3) {
const warning = document.createElement('p');
warning.style.color = 'yellow';
warning.innerText = `The minor revision version of mathics-threejs-backend is 1, but it was expected to be at least ${/** @type {RegExpMatchArray} */(versionArray)[1]}. Trying to draw the graphics.`;
warning.innerText = `The minor revision version of mathics-threejs-backend is 3, but it was expected to be at least ${/** @type {RegExpMatchArray} */(versionArray)[1]}. Trying to draw the graphics.`;

@@ -59,0 +59,0 @@ container.appendChild(warning);

@@ -203,7 +203,13 @@ // @ts-check

// Differently from cuboid's edges, the cones' ones are in a different object. It is very hard or maybe impossible to draw edges with complex shapes in the fragment shader.
// Differently from cuboid's edges, the cones' ones are in a
// different object. It is very hard or maybe impossible to draw
// edges with complex shapes in the fragment shader.
// The lines below are the cone base edges' vertices' positions.
// The magic numbers below are modified from the position attribute of a three.js EdgesGeometry of the cone.
// Differently from cylinders' edges, the cones' ones are drawed through Line, now LineSegments, so before putting them in the code we need to remove the repeated numbers. This saves RAM and increases the performance.
// The magic numbers below are modified from the position attribute
// of a three.js EdgesGeometry of the cone.
// Differently from cylinders' edges, the cones' ones are drawn
// through Line, now LineSegments, so before putting them in the
// code we need to remove the repeated numbers. This saves RAM and
// increases the performance.
// To get them: console.log(new EdgesGeometry(coneGeometry).attributes.position.array)

@@ -210,0 +216,0 @@

@@ -162,8 +162,8 @@ // @ts-check

struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

@@ -179,7 +179,2 @@ ` : ''}

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, out IncidentLight light) {
light.direction = normalize(pointLight.position + vViewPosition);
light.color = pointLight.color + 1.0;
}
` : ''}

@@ -196,14 +191,2 @@

uniform SpotLight spotLights[${uniforms.spotLights.value.length}];
void getSpotLightInfo(const in SpotLight spotLight, out IncidentLight light) {
light.direction = normalize(spotLight.position + vViewPosition);
float angleCos = dot(light.direction, spotLight.direction);
if (angleCos > 0.0) {
light.color = spotLight.color * angleCos + 1.0;
} else {
light.color = vec3(0.0);
}
}
` : ''}

@@ -228,4 +211,2 @@

IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `

@@ -238,4 +219,6 @@ for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], directLight);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
reflectedLight += saturate(dot(
normal,
normalize(pointLights[i].position + vViewPosition))
) * pointLights[i].color;
}

@@ -245,4 +228,11 @@ ` : ''}

for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLights[i], directLight);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
float angleCos = dot(
normalize(spotLights[i].position + vViewPosition),
spotLights[i].direction
);
reflectedLight += saturate(dot(
normal,
normalize(spotLights[i].position + vViewPosition))
) * spotLights[i].color * max(angleCos, 0.0);
}

@@ -249,0 +239,0 @@ ` : ''}

// @ts-check
// This file exports implmentations using three.js of Mathematica and
// This file exports implementations using three.js of Mathematica and
// Mathics Graphics3D primitives like "Sphere", or "Cuboid, etc.

@@ -32,2 +32,3 @@

* | 'sphere'
* | 'text'
* | 'tube'

@@ -54,2 +55,4 @@ * | 'uniformPolyhedron'

* subType?: 'tetrahedron' | 'octahedron' | 'dodecahedron' | 'icosahedron',
* texts?: Array<string>,
* textSize?: number,
* vertexNormals?: [number, number, number][]

@@ -63,3 +66,3 @@ * }} PrimitiveElement

* container: HTMLElement
* ) => import('../../vendors/three.js').Object3D } PrimitiveFunction
* ) => import('../../vendors/three.js').Object3D | null } PrimitiveFunction
*/

@@ -74,3 +77,3 @@

// we use the function name "sphere" and "uniformPolyhedron", not
// "Sphere" and "UnformPolyhedron".
// "Sphere" and "UniformPolyhedron".

@@ -103,2 +106,3 @@ // Usually the vertices are stored in the attribute "position".

import sphere from './sphere.js';
import text from './text.js';
import tube from './tube.js';

@@ -116,4 +120,5 @@ import uniformPolyhedron from './uniformPolyhedron.js';

sphere,
text,
tube,
uniformPolyhedron
};

@@ -26,4 +26,5 @@ // @ts-check

* Get the unit normal vector from the 1st, 2nd and last coordinate
* (these numbers were choosen because the vectors 1st->2nd and last->2nd
* have different directions, what is necessary for some calculations)
* (these numbers were chosen because the vectors 1st->2nd and
* last->2nd have different directions, what is necessary for some
* calculations)
* Note: a "better" way to do this is compute an approximation plane

@@ -229,8 +230,8 @@ * by taking linear least squares, but that would be way slower and

struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

@@ -245,7 +246,2 @@ ` : ''}

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, out IncidentLight light) {
light.direction = normalize(pointLight.position + vViewPosition);
light.color = pointLight.color;
}
` : ''}

@@ -262,8 +258,2 @@

uniform SpotLight spotLights[${uniforms.spotLights.value.length}];
void getSpotLightInfo(const in SpotLight spotLight, out IncidentLight light) {
light.direction = normalize(spotLight.position + vViewPosition);
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
}
` : ''}

@@ -277,4 +267,2 @@

IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `

@@ -287,10 +275,24 @@ for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], directLight);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
reflectedLight += saturate(dot(
normal,
normalize(pointLights[i].position + vViewPosition))
) * pointLights[i].color;
}
` : ''}
${uniforms.spotLights.value.length > 0 ? `
vec3 direction;
for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLight, spotLights[i]);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
direction = normalize(spotLight.position + vViewPosition);
reflectedLight += saturate(dot(normal, direction))
* spotLights[i].color
* max(
smoothstep(
spotLights[i].coneCos,
spotLights[i].coneCos,
dot(direction, spotLights[i].direction)
),
0.0
);
}

@@ -322,3 +324,3 @@ ` : ''}

// Differently from polyhedrons, polygons use a Mesh and a material
// with "wirefram: true". This is slower than LineSegments, but
// with "wireframe: true". This is slower than LineSegments, but
// creating a new BufferGeometry is also slow and uses more RAM

@@ -325,0 +327,0 @@ // (LineSegments don't support indexed BufferGeometries).

@@ -56,13 +56,8 @@ // @ts-check

struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
struct IncidentLight {
vec3 color;
vec3 direction;
};
struct GeometricContext {
vec3 position;
vec3 normal;
};
${uniforms.directionalLights.value.length > 0 ? `
uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

@@ -78,7 +73,2 @@ ` : ''}

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(pointLight.position - geometry.position);
light.color = pointLight.color;
}
` : ''}

@@ -95,8 +85,2 @@

uniform SpotLight spotLights[${uniforms.spotLights.value.length}];
void getSpotLightInfo(const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(spotLight.position - geometry.position);
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
}
` : ''}

@@ -109,14 +93,10 @@

GeometricContext geometry = GeometricContext(
mvPosition.xyz,
normalize(normalMatrix * normal)
);
vec3 position = mvPosition.xyz;
vec3 normal = normalize(normalMatrix * normal);
vec3 light = ambientLightColor;
IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `
for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {
light += saturate(dot(geometry.normal, directionalLights[i].direction)) * directionalLights[i].color;
light += saturate(dot(normal, directionalLights[i].direction)) * directionalLights[i].color;
}

@@ -127,5 +107,3 @@ ` : ''}

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], geometry, directLight);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(normal, normalize(pointLights[i].position - position))) * pointLights[i].color;
}

@@ -135,6 +113,17 @@ ` : ''}

${uniforms.spotLights.value.length > 0 ? `
vec3 direction;
for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLights[i], geometry, directLight);
direction = normalize(spotLights[i].position - position);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(normal, direction))
* spotLights[i].color
* max(
smoothstep(
spotLights[i].coneCos,
spotLights[i].coneCos,
dot(direction, spotLights[i].direction)
),
0.0
);
}

@@ -141,0 +130,0 @@ ` : ''}

@@ -91,13 +91,8 @@ // @ts-check

struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
struct IncidentLight {
vec3 color;
vec3 direction;
};
struct GeometricContext {
vec3 position;
vec3 normal;
};
${uniforms.directionalLights.value.length > 0 ? `
uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

@@ -113,7 +108,2 @@ ` : ''}

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(spotLight.position - geometry.position);
light.color = pointLight.color;
}
` : ''}

@@ -130,8 +120,2 @@

uniform SpotLight spotLights[${uniforms.spotLights.value.length}];
void getSpotLightInfo(const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(spotLight.position - geometry.position);
light.color = spotLight.color * max(smoothstep(spotLight.coneCos, spotLight.coneCos, dot(light.direction, spotLight.direction)), 0.0);
}
` : ''}

@@ -144,14 +128,10 @@

GeometricContext geometry = GeometricContext(
mvPosition.xyz,
normalize(normalMatrix * normal)
);
vec3 position = mvPosition.xyz;
vec3 normal = normalize(normalMatrix * normal);
vec3 light = ambientLightColor;
IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `
for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {
light += saturate(dot(geometry.normal, directionalLights[i].direction)) * directionalLights[i].color;
light += saturate(dot(normal, directionalLights[i].direction)) * directionalLights[i].color;
}

@@ -162,5 +142,6 @@ ` : ''}

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], geometry, directLight);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(
normal,
normalize(spotLights[i].position - position))
) * pointLights[i].color;
}

@@ -170,6 +151,17 @@ ` : ''}

${uniforms.spotLights.value.length > 0 ? `
vec3 direction;
for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLights[i], geometry, directLight);
direction = normalize(spotLights[i].position - position);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(normal, direction))
* spotLights[i].color
* max(
smoothstep(
spotLights[i].coneCos,
spotLights[i].coneCos,
dot(direction, spotLights[i].direction)
),
0.0
);
}

@@ -176,0 +168,0 @@ ` : ''}

@@ -392,8 +392,8 @@ // @ts-check

struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
struct IncidentLight {
vec3 color;
vec3 direction;
};
${uniforms.directionalLights.value.length > 0 ? `
uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

@@ -409,7 +409,2 @@ ` : ''}

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, out IncidentLight light) {
light.direction = normalize(spotLight.position + vViewPosition);
light.color = pointLight.color;
}
` : ''}

@@ -439,4 +434,2 @@

IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `

@@ -450,4 +443,6 @@ for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], directLight);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
reflectedLight += saturate(dot(
normal,
normalize(spotLights[i].position + vViewPosition)
)) * pointLights[i].color;
}

@@ -457,6 +452,17 @@ ` : ''}

${uniforms.spotLights.value.length > 0 ? `
SpotLight spotLight;
vec3 direction;
for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLights[i], directLight);
reflectedLight += saturate(dot(normal, directLight.direction)) * directLight.color;
direction = normalize(spotLights[i].position + vViewPosition);
reflectedLight += saturate(dot(normal, direction))
* spotLights[i].color
* max(
smoothstep(
spotLights[i].coneCos,
spotLights[i].coneCos,
dot(direction, spotLights[i].direction)
),
0.0
);
}

@@ -485,3 +491,3 @@ ` : ''}

// The polyhedrons' edges are basicaly the same as the cylinders' ones.
// The polyhedrons' edges are basically the same as the cylinders' ones.

@@ -488,0 +494,0 @@ const edgesGeometry = new InstancedBufferGeometry();

@@ -39,7 +39,2 @@ // @ts-check

struct GeometricContext {
vec3 position;
vec3 normal;
};
${uniforms.directionalLights.value.length > 0 ? `

@@ -55,7 +50,2 @@ uniform IncidentLight directionalLights[${uniforms.directionalLights.value.length}];

uniform PointLight pointLights[${uniforms.pointLights.value.length}];
void getPointLightInfo(const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(pointLight.position - geometry.position);
light.color = pointLight.color;
}
` : ''}

@@ -72,8 +62,2 @@

uniform SpotLight spotLights[${uniforms.spotLights.value.length}];
void getSpotLightInfo(const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light) {
light.direction = normalize(spotLight.position - geometry.position);
light.color = spotLight.color * max(dot(light.direction, spotLight.direction), 0.0);
}
` : ''}

@@ -103,14 +87,10 @@

GeometricContext geometry = GeometricContext(
mvPosition.xyz,
normalize(normalMatrix * normal)
);
vec3 position = mvPosition.xyz;
vec3 normal = normalize(normalMatrix * normal);
vec3 light = ambientLightColor;
IncidentLight directLight;
${uniforms.directionalLights.value.length > 0 ? `
for (int i = 0; i < ${uniforms.directionalLights.value.length}; i++) {
light += saturate(dot(geometry.normal, directionalLights[i].direction)) * directionalLights[i].color;
light += saturate(dot(normal, directionalLights[i].direction)) * directionalLights[i].color;
}

@@ -121,5 +101,6 @@ ` : ''}

for (int i = 0; i < ${uniforms.pointLights.value.length}; i++) {
getPointLightInfo(pointLights[i], geometry, directLight);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(
normal,
normalize(pointLights[i].position - position))
) * pointLights[i].color;
}

@@ -129,6 +110,10 @@ ` : ''}

${uniforms.spotLights.value.length > 0 ? `
vec3 direction;
for (int i = 0; i < ${uniforms.spotLights.value.length}; i++) {
getSpotLightInfo(spotLights[i], geometry, directLight);
direction = normalize(spotLights[i].position - position);
light += saturate(dot(geometry.normal, directLight.direction)) * directLight.color;
light += saturate(dot(normal, direction))
* spotLights[i].color
* max(dot(direction, spotLights[i].direction), 0.0);
}

@@ -135,0 +120,0 @@ ` : ''}

@@ -178,3 +178,3 @@ export default function (data, dim = 3) {

function isValidDiagonal(a, b) {
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // doesn't intersect other edges
(locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible

@@ -181,0 +181,0 @@ (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc