├── .gitignore ├── .coveralls.yml ├── tsconfig-cjs.json ├── jest.config.js ├── .prettierrc.yaml ├── tsconfig.json ├── test ├── utils.test.ts ├── geometry.test.ts └── data │ ├── input-settings.ts │ ├── input-data-3d.ts │ └── output-data-2d.ts ├── src ├── index.ts ├── vector.ts ├── parameter-types.ts ├── geometry.ts ├── primitive-types.ts ├── axes-renderer.ts ├── utils.ts ├── data-renderer.ts ├── scene-cube.ts └── scene-cube-renderer.ts ├── .github └── workflows │ ├── test.yml │ └── manual.yml ├── package.json ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib/ 3 | .DS_Store 4 | coverage/ -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | repo_token: Szh2KtsqMqUA5lGk3WE9e7NqXa0q6Tr1d 2 | -------------------------------------------------------------------------------- /tsconfig-cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "CommonJS", 5 | "outDir": "./lib/cjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ["/test"], 3 | testMatch: ["**/__tests__/**/*.+(ts|tsx|js)", "**/?(*.)+(spec|test).+(ts|tsx|js)"], 4 | transform: { 5 | "^.+\\.(ts|tsx)$": "ts-jest", 6 | }, 7 | } 8 | -------------------------------------------------------------------------------- /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | printWidth: 90 2 | tabWidth: 4 3 | quoteProps: "consistent" 4 | arrowParens: "avoid" 5 | semi: false 6 | singleQuote: false 7 | jsxSingleQuote: false 8 | trailingComma: "es5" 9 | bracketSpacing: true 10 | jsxBracketSameLine: false -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2015", 4 | "module": "ES2020", 5 | "declaration": true, 6 | "strict": true, 7 | "esModuleInterop": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "outDir": "./lib/esm", 10 | "moduleResolution": "node" 11 | }, 12 | "include": ["./src"] 13 | } 14 | -------------------------------------------------------------------------------- /test/utils.test.ts: -------------------------------------------------------------------------------- 1 | import { renderScene } from "../src/utils" 2 | import { viewSettings, sceneSettings, sceneOptions } from "./data/input-settings" 3 | import props2d from "./data/output-data-2d" 4 | import assert from "assert" 5 | import hexapodData from "./data/input-data-3d" 6 | 7 | test("render scene", () => { 8 | const props2dResult = renderScene( 9 | viewSettings, 10 | sceneSettings, 11 | sceneOptions, 12 | hexapodData 13 | ) 14 | 15 | assert.deepStrictEqual(props2dResult, props2d) 16 | }) 17 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { renderScene, SCENE_ORIENTATION, getWorldWrtCameraMatrix } from "./utils.js" 2 | import Vector from "./vector" 3 | import AxesRenderer from "./axes-renderer" 4 | import SceneCube from "./scene-cube" 5 | import DataRenderer from "./data-renderer" 6 | import SceneCubeRenderer from "./scene-cube-renderer" 7 | import { rotateXYZmatrix, multiply4x4matrix, radians } from "./geometry" 8 | 9 | export { 10 | renderScene, 11 | SCENE_ORIENTATION, 12 | getWorldWrtCameraMatrix, 13 | AxesRenderer, 14 | SceneCube, 15 | DataRenderer, 16 | SceneCubeRenderer, 17 | Vector, 18 | rotateXYZmatrix, 19 | multiply4x4matrix, 20 | radians, 21 | } 22 | 23 | export default renderScene 24 | -------------------------------------------------------------------------------- /src/vector.ts: -------------------------------------------------------------------------------- 1 | import { matrix4x4 } from "./primitive-types" 2 | 3 | class Vector { 4 | x = 0 5 | y = 0 6 | z = 0 7 | name = "no-name-vector" 8 | 9 | constructor(x: number, y: number, z: number, name: string) { 10 | Object.assign(this, { x, y, z, name }) 11 | } 12 | 13 | transform = (tM: matrix4x4): Vector => { 14 | const [r0, r1, r2] = tM.slice(0, 3) 15 | const [r00, r01, r02, tx] = r0 16 | const [r10, r11, r12, ty] = r1 17 | const [r20, r21, r22, tz] = r2 18 | 19 | const { x, y, z, name } = this 20 | const x_ = x * r00 + y * r01 + z * r02 + tx 21 | const y_ = x * r10 + y * r11 + z * r12 + ty 22 | const z_ = x * r20 + y * r21 + z * r22 + tz 23 | return new Vector(x_, y_, z_, name) 24 | } 25 | 26 | project = (pC: number): Vector => 27 | new Vector((this.x / this.z) * pC, (this.y / this.z) * pC, pC, this.name) 28 | 29 | transformThenProject = (tM: matrix4x4, pC: number): Vector => 30 | this.transform(tM).project(pC) 31 | } 32 | 33 | export default Vector 34 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: ["push", "pull_request"] 2 | 3 | name: test 4 | 5 | jobs: 6 | build: 7 | name: Build 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v1 11 | 12 | - name: Use Node.js 10.x 13 | uses: actions/setup-node@v1 14 | with: 15 | node-version: 10.x 16 | 17 | - name: npm install 18 | run: npm install 19 | 20 | - name: Add prettier 21 | run: npm install -g prettier --dev 22 | 23 | - name: Check code style 24 | run: prettier --config ./.prettierrc.yaml --check ./src/* 25 | 26 | - name: Install jest globally 27 | run: npm install -g jest 28 | - name: Install coveralls globally 29 | run: npm install -g coveralls 30 | 31 | - name: run jest 32 | run: jest --coverage && coveralls < coverage/lcov.info 33 | - name: Coveralls 34 | uses: coverallsapp/github-action@master 35 | with: 36 | github-token: ${{ secrets.GITHUB_TOKEN }} 37 | -------------------------------------------------------------------------------- /src/parameter-types.ts: -------------------------------------------------------------------------------- 1 | interface ViewSettings { 2 | camTx: number 3 | camTy: number 4 | camTz: number 5 | camZoom: number 6 | canvasToViewRatio: number 7 | cubeRx: number 8 | cubeRy: number 9 | cubeRz: number 10 | defaultCamOrientation: string 11 | defaultCamZoffset: number 12 | } 13 | 14 | interface SceneSettings { 15 | cubeRange: number 16 | cubeZoffset: number 17 | dataXoffset: number 18 | dataYoffset: number 19 | dataZoffset: number 20 | paperXrange: number 21 | paperYrange: number 22 | } 23 | 24 | interface SceneOptions { 25 | paper: ModelOptions 26 | xyPlane?: ModelOptions 27 | sceneEdges?: ModelOptions 28 | crossLines?: ModelOptions 29 | edgeAxes?: AxesOptions 30 | worldAxes?: AxesOptions 31 | cubeAxes?: AxesOptions 32 | } 33 | 34 | interface ModelOptions { 35 | color: string 36 | opacity?: number 37 | } 38 | 39 | interface AxesOptions { 40 | intersectionPointColor: string 41 | intersectionPointSize?: number 42 | xColor: string 43 | yColor: string 44 | zColor: string 45 | lineSize?: number 46 | edgeOpacity?: number 47 | } 48 | 49 | export { ViewSettings, SceneSettings, SceneOptions, AxesOptions } 50 | -------------------------------------------------------------------------------- /.github/workflows/manual.yml: -------------------------------------------------------------------------------- 1 | name: Node.js_Package 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | # Setup .npmrc file to publish to npm 11 | - uses: actions/setup-node@v1 12 | with: 13 | node-version: "10.x" 14 | registry-url: "https://registry.npmjs.org" 15 | - run: npm install 16 | # Publish to npm 17 | - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" > ~/.npmrc 18 | - run: npm publish --access public 19 | env: 20 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 21 | # Setup .npmrc file to publish to GitHub Packages 22 | - uses: actions/setup-node@v1 23 | with: 24 | registry-url: "https://npm.pkg.github.com" 25 | # Defaults to the user or organization that owns the workflow file 26 | scope: "@mithi" 27 | # Publish to GitHub Packages 28 | - run: npm publish 29 | env: 30 | NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | -------------------------------------------------------------------------------- /test/geometry.test.ts: -------------------------------------------------------------------------------- 1 | import { matrix4x4 } from "../src/primitive-types" 2 | import { rotateXYZmatrix, multiply4x4matrix } from "../src/geometry" 3 | 4 | const expectEqualMatrix = (A: matrix4x4, B: matrix4x4): void => { 5 | for (let i = 0; i < 4; i++) { 6 | for (let j = 0; j < 4; j++) { 7 | expect(A[i][j]).toBeCloseTo(B[i][j]) 8 | } 9 | } 10 | } 11 | 12 | test("rotate XYZ matrix", () => { 13 | const C: matrix4x4 = [ 14 | [0.23419413, -0.68014914, -0.69465837, 0], 15 | [0.61901904, 0.65528985, -0.4329095, 0], 16 | [0.74964561, -0.32862189, 0.57449031, 0], 17 | [0, 0, 0, 1], 18 | ] 19 | const R = rotateXYZmatrix({ x: 37, y: -44, z: 71 }) 20 | expectEqualMatrix(C, R) 21 | }) 22 | 23 | test("multiply 4x4 matrix", () => { 24 | const A: matrix4x4 = [ 25 | [5, 7, 9, 10], 26 | [2, 3, 3, 8], 27 | [8, 10, 2, 3], 28 | [3, 3, 4, 8], 29 | ] 30 | 31 | const B: matrix4x4 = [ 32 | [3, 10, 12, 18], 33 | [12, 1, 4, 9], 34 | [9, 10, 12, 2], 35 | [3, 12, 4, 10], 36 | ] 37 | 38 | const C: matrix4x4 = [ 39 | [210, 267, 236, 271], 40 | [93, 149, 104, 149], 41 | [171, 146, 172, 268], 42 | [105, 169, 128, 169], 43 | ] 44 | const M = multiply4x4matrix(A, B) 45 | expectEqualMatrix(C, M) 46 | }) 47 | -------------------------------------------------------------------------------- /src/geometry.ts: -------------------------------------------------------------------------------- 1 | import { matrix4x4 } from "./primitive-types" 2 | 3 | const radians = (thetaDegrees: number) => (thetaDegrees * Math.PI) / 180 4 | 5 | const _returnSinAndCosine = (theta: number): [number, number] => [ 6 | Math.sin(radians(theta)), 7 | Math.cos(radians(theta)), 8 | ] 9 | 10 | const uniform4x4matrix = (d: number): matrix4x4 => [ 11 | [d, d, d, d], 12 | [d, d, d, d], 13 | [d, d, d, d], 14 | [d, d, d, d], 15 | ] 16 | 17 | const multiply4x4matrix = (mA: matrix4x4, mB: matrix4x4): matrix4x4 => { 18 | let rM: matrix4x4 = uniform4x4matrix(0) 19 | 20 | for (let i = 0; i < 4; i++) { 21 | for (let j = 0; j < 4; j++) { 22 | rM[i][j] = 23 | mA[i][0] * mB[0][j] + 24 | mA[i][1] * mB[1][j] + 25 | mA[i][2] * mB[2][j] + 26 | mA[i][3] * mB[3][j] 27 | } 28 | } 29 | 30 | return rM 31 | } 32 | 33 | const rotateXYZmatrix = (euler: { x: number; y: number; z: number }): matrix4x4 => { 34 | const [sx, cx] = _returnSinAndCosine(euler.x) 35 | const [sy, cy] = _returnSinAndCosine(euler.y) 36 | const [sz, cz] = _returnSinAndCosine(euler.z) 37 | return [ 38 | [cy * cz, -sz * cy, sy, 0], 39 | [sx * sy * cz + sz * cx, -sx * sy * sz + cx * cz, -sx * cy, 0], 40 | [sx * sz - sy * cx * cz, sx * cz + sy * sz * cx, cx * cy, 0], 41 | [0, 0, 0, 1], 42 | ] 43 | } 44 | 45 | export { rotateXYZmatrix, multiply4x4matrix, radians } 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mithi/bare-minimum-3d", 3 | "version": "0.4.0", 4 | "description": "A small package to transform declared 3d data (points, polygons, lines) to 2d data. The output is intended to be fed to a `bare-minimum-2d` plot.", 5 | "main": "./lib/cjs/index.js", 6 | "module": "./lib/esm/index.js", 7 | "files": [ 8 | "lib/" 9 | ], 10 | "scripts": { 11 | "test": "jest", 12 | "tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json", 13 | "prepublishOnly": "npm run tsc", 14 | "check-format": "prettier --config ./.prettierrc.yaml --check \"./src/*\"" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/mithi/bare-minimum-3d.git" 19 | }, 20 | "keywords": [ 21 | "data", 22 | "data-visualization", 23 | "graph", 24 | "plot", 25 | "3d", 26 | "3d-scatter-plot", 27 | "visualization", 28 | "svg", 29 | "plotly", 30 | "d3", 31 | "matplotlib" 32 | ], 33 | "author": "Mithi", 34 | "license": "Apache License 2.0", 35 | "bugs": { 36 | "url": "https://github.com/mithi/bare-minimum-3d/issues" 37 | }, 38 | "homepage": "https://github.com/mithi/bare-minimum-3d#readme", 39 | "devDependencies": { 40 | "@types/jest": "^26.0.21", 41 | "coveralls": "^3.1.0", 42 | "jest": "^26.6.3", 43 | "prettier": "2.1.1", 44 | "ts-jest": "^26.2.0", 45 | "typescript": "^4.0.2" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/data/input-settings.ts: -------------------------------------------------------------------------------- 1 | const viewSettings = { 2 | camTx: -0.2, 3 | camTy: -0.68, 4 | camTz: 1.5, 5 | cubeRx: 57, 6 | cubeRy: -4, 7 | cubeRz: 16.5, 8 | camZoom: 3.1, 9 | canvasToViewRatio: 300, 10 | defaultCamZoffset: 5, 11 | defaultCamOrientation: "z-forward-x-left", 12 | } 13 | 14 | const sceneSettings = { 15 | cubeRange: 600, 16 | cubeZoffset: 1, 17 | dataXoffset: 0, 18 | dataYoffset: 0, 19 | dataZoffset: 0, 20 | paperXrange: 600, 21 | paperYrange: 600, 22 | } 23 | 24 | const edgeAxes = { 25 | intersectionPointColor: "#FF00FF", 26 | intersectionPointSize: 5, 27 | xColor: "#E91E63", 28 | yColor: "#03A9F4", 29 | zColor: "#CDDC39", 30 | lineSize: 1, 31 | edgeOpacity: 1.0, 32 | } 33 | 34 | const worldAxes = { 35 | intersectionPointColor: "#FFFF00", 36 | intersectionPointSize: 5, 37 | xColor: "#E91E63", 38 | yColor: "#03A9F4", 39 | zColor: "#CDDC39", 40 | lineSize: 3, 41 | edgeOpacity: 1.0, 42 | } 43 | 44 | const cubeAxes = { 45 | intersectionPointColor: "#00FF00", 46 | intersectionPointSize: 5, 47 | xColor: "#E91E63", 48 | yColor: "#03A9F4", 49 | zColor: "#CDDC39", 50 | lineSize: 3, 51 | edgeOpacity: 1.0, 52 | } 53 | 54 | const sceneOptions = { 55 | paper: { color: "#17212B", opacity: 1 }, 56 | xyPlane: { color: "#0652DD", opacity: 0.1 }, 57 | sceneEdges: { color: "#607D8B", opacity: 1 }, 58 | crossLines: { color: "#795548", opacity: 1 }, 59 | edgeAxes, 60 | worldAxes, 61 | cubeAxes, 62 | } 63 | 64 | export { viewSettings, sceneSettings, sceneOptions } 65 | -------------------------------------------------------------------------------- /src/primitive-types.ts: -------------------------------------------------------------------------------- 1 | type row4 = [number, number, number, number] 2 | type matrix4x4 = [row4, row4, row4, row4] 3 | 4 | enum DataSpecType { 5 | polygon = "polygon", 6 | points = "points", 7 | lines = "lines", 8 | } 9 | 10 | interface Polygon2dSpecs { 11 | x: Array 12 | y: Array 13 | borderColor: string 14 | borderOpacity: number 15 | fillColor: string 16 | fillOpacity: number 17 | borderSize: number 18 | type: DataSpecType.polygon 19 | id: string 20 | } 21 | 22 | interface Points2dSpecs { 23 | x: Array 24 | y: Array 25 | color: string 26 | opacity: number 27 | size: number 28 | type: DataSpecType.points 29 | id: string 30 | } 31 | 32 | interface Lines2dSpecs { 33 | x0: Array 34 | y0: Array 35 | x1: Array 36 | y1: Array 37 | color: string 38 | opacity: number 39 | size: number 40 | type: DataSpecType.lines 41 | id: string 42 | } 43 | 44 | interface Lines3dSpecs extends Lines2dSpecs { 45 | z0: Array 46 | z1: Array 47 | } 48 | 49 | interface Polygon3dSpecs extends Polygon2dSpecs { 50 | z: Array 51 | } 52 | 53 | interface Points3dSpecs extends Points2dSpecs { 54 | z: Array 55 | } 56 | 57 | type Data2dSpecs = Polygon2dSpecs | Lines2dSpecs | Points2dSpecs 58 | type Data3dSpecs = Polygon3dSpecs | Lines3dSpecs | Points3dSpecs 59 | 60 | export { 61 | matrix4x4, 62 | Lines2dSpecs, 63 | Polygon2dSpecs, 64 | Points2dSpecs, 65 | Data2dSpecs, 66 | Lines3dSpecs, 67 | Polygon3dSpecs, 68 | Points3dSpecs, 69 | Data3dSpecs, 70 | DataSpecType, 71 | } 72 | -------------------------------------------------------------------------------- /src/axes-renderer.ts: -------------------------------------------------------------------------------- 1 | import { AxesOptions } from "./parameter-types" 2 | import Vector from "./vector" 3 | import { Lines2dSpecs, Points2dSpecs, DataSpecType } from "./primitive-types" 4 | 5 | /* 6 | E4------F5 y 7 | |`. | `. | 8 | | `A0-----B1 *----- x 9 | | | | | \ 10 | G6--|--H7 | \ 11 | `. | `. | z 12 | `C2-----D3 13 | */ 14 | 15 | class AxesRenderer { 16 | origin: Vector 17 | axes: Array 18 | name: string 19 | specs: AxesOptions 20 | constructor(origin: Vector, axes: Array, name: string, specs: AxesOptions) { 21 | this.axes = axes 22 | this.origin = origin 23 | this.name = name 24 | this.specs = specs 25 | } 26 | 27 | drawAxis( 28 | p: Vector, 29 | v: Vector, 30 | axisType: "x" | "y" | "z", 31 | color: string 32 | ): Lines2dSpecs { 33 | const { lineSize, edgeOpacity } = this.specs 34 | return { 35 | x0: [p.x], 36 | y0: [p.y], 37 | x1: [v.x], 38 | y1: [v.y], 39 | color, 40 | opacity: edgeOpacity || 1, 41 | size: lineSize || 3, 42 | type: DataSpecType.lines, 43 | id: `${axisType}-${this.name}`, 44 | } 45 | } 46 | 47 | get centerPoint(): Points2dSpecs { 48 | return { 49 | x: [this.origin.x], 50 | y: [this.origin.y], 51 | color: this.specs.intersectionPointColor, 52 | opacity: 1.0, 53 | size: this.specs.intersectionPointSize || 3, 54 | type: DataSpecType.points, 55 | id: `point-${this.name}`, 56 | } 57 | } 58 | 59 | render() { 60 | const p = this.origin 61 | const [vx, vy, vz] = this.axes 62 | const { xColor, yColor, zColor } = this.specs 63 | return [ 64 | this.drawAxis(p, vx, "x", xColor), 65 | this.drawAxis(p, vy, "y", yColor), 66 | this.drawAxis(p, vz, "z", zColor), 67 | this.centerPoint, 68 | ] 69 | } 70 | } 71 | 72 | export default AxesRenderer 73 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import { matrix4x4, Data3dSpecs } from "./primitive-types" 2 | import { ViewSettings, SceneSettings, SceneOptions } from "./parameter-types" 3 | import DataRenderer from "./data-renderer" 4 | import SceneCube from "./scene-cube" 5 | import SceneCubeRenderer from "./scene-cube-renderer" 6 | import { rotateXYZmatrix } from "./geometry" 7 | 8 | const getWorldWrtCameraMatrix = ( 9 | offset: { x: number; y: number; z: number }, 10 | euler: { x: number; y: number; z: number } 11 | ): matrix4x4 => { 12 | const r = rotateXYZmatrix(euler) // rotation of camera wrt world 13 | 14 | // rInverse = rTranspose = rotation of world wrt camera 15 | // tInverseMatrix = offset of world wrt camera in a matrix 16 | const t = offset // offset of camera wrt to world 17 | 18 | // world_to_camera_matrix = rotateCameraMatrixInverse * tInverseMatrix 19 | return [ 20 | [r[0][0], r[1][0], r[2][0], -t.x], 21 | [r[0][1], r[1][1], r[2][1], -t.y], 22 | [r[0][2], r[1][2], r[2][2], -t.z], 23 | [0, 0, 0, 1], 24 | ] 25 | } 26 | 27 | type SceneOrientationMap = Record 28 | 29 | const SCENE_ORIENTATION: SceneOrientationMap = { 30 | "z-forward-x-left": { x: 0, y: 0, z: 0 }, 31 | "z-up-x-left": { x: -90, y: 0, z: 0 }, 32 | "z-up-x-forward": { x: -90, y: 90, z: 0 }, 33 | "z-forward-x-right": { x: 0, y: 0, z: 180 }, 34 | } 35 | 36 | const renderScene = ( 37 | viewSettings: ViewSettings, 38 | sceneSettings: SceneSettings, 39 | sceneOptions: SceneOptions, 40 | data3d: Array 41 | ) => { 42 | // 1. compute matrix for transforming points wrt world to points wrt camera 43 | const { camTx, camTy, camTz, defaultCamZoffset, defaultCamOrientation } = viewSettings 44 | 45 | const camPosition = { 46 | x: camTx, 47 | y: camTy, 48 | z: camTz + defaultCamZoffset, 49 | } 50 | const camOrientation: { x: number; y: number; z: number } = 51 | SCENE_ORIENTATION[defaultCamOrientation] 52 | 53 | const worldWrtCameraMatrix = getWorldWrtCameraMatrix(camPosition, camOrientation) 54 | 55 | // 2. create the scene cube given parameters 56 | const { cubeRx, cubeRy, cubeRz, canvasToViewRatio, camZoom } = viewSettings 57 | const { cubeZoffset, cubeRange } = sceneSettings 58 | const projectionConstant: number = canvasToViewRatio * camZoom 59 | 60 | const cubeOrientation = { x: cubeRx, y: cubeRy, z: cubeRz } 61 | const cube = new SceneCube( 62 | cubeOrientation, 63 | worldWrtCameraMatrix, 64 | cubeZoffset, 65 | cubeRange, 66 | projectionConstant 67 | ) 68 | 69 | // 3. generate the 2d representation of the scene cube to feed to the plot 70 | const sceneData = new SceneCubeRenderer(cube, sceneOptions).render() 71 | 72 | // 4. generate the 2d representation of the passed data to feed to the plot 73 | const { dataXoffset, dataYoffset, dataZoffset } = sceneSettings 74 | 75 | const models = new DataRenderer( 76 | cube.range, 77 | dataXoffset, 78 | dataYoffset, 79 | dataZoffset, 80 | cube.wrtCameraMatrix, 81 | projectionConstant 82 | ).render(data3d) 83 | 84 | // 5. return the props to feed to our 2d plot 85 | const container = { 86 | color: sceneOptions.paper.color, 87 | opacity: sceneOptions.paper.opacity || 1, 88 | xRange: sceneSettings.paperXrange, 89 | yRange: sceneSettings.paperYrange, 90 | } 91 | 92 | return { 93 | container, 94 | data: [...sceneData, ...models], 95 | } 96 | } 97 | 98 | export { renderScene, SCENE_ORIENTATION, getWorldWrtCameraMatrix } 99 | -------------------------------------------------------------------------------- /src/data-renderer.ts: -------------------------------------------------------------------------------- 1 | import Vector from "./vector" 2 | import { 3 | matrix4x4, 4 | Polygon3dSpecs, 5 | Lines3dSpecs, 6 | Points3dSpecs, 7 | Data3dSpecs, 8 | Points2dSpecs, 9 | Polygon2dSpecs, 10 | Data2dSpecs, 11 | Lines2dSpecs, 12 | DataSpecType, 13 | } from "./primitive-types" 14 | 15 | type PolygonOrPoints3d = Points3dSpecs | Polygon3dSpecs 16 | type PolygonOrPoints2d = Points2dSpecs | Polygon2dSpecs 17 | 18 | class DataRenderer { 19 | sceneRange: number 20 | dataXoffset: number 21 | dataYoffset: number 22 | dataZoffset: number 23 | transformMatrix: matrix4x4 24 | projectionConstant: number 25 | 26 | constructor( 27 | sceneRange: number, 28 | dataXoffset: number, 29 | dataYoffset: number, 30 | dataZoffset: number, 31 | transformMatrix: matrix4x4, 32 | projectionConstant: number 33 | ) { 34 | this.sceneRange = sceneRange 35 | this.dataXoffset = dataXoffset 36 | this.dataYoffset = dataYoffset 37 | this.dataZoffset = dataZoffset 38 | this.transformMatrix = transformMatrix 39 | this.projectionConstant = projectionConstant 40 | } 41 | 42 | _projectPoint(x_: number, y_: number, z_: number, i: number): Vector { 43 | const { 44 | sceneRange, 45 | dataXoffset, 46 | dataYoffset, 47 | dataZoffset, 48 | transformMatrix, 49 | projectionConstant, 50 | } = this 51 | 52 | const x = x_ / sceneRange + dataXoffset 53 | const y = y_ / sceneRange + dataYoffset 54 | const z = z_ / sceneRange + dataZoffset 55 | 56 | return new Vector(x, y, z, `${i}`) 57 | .transform(transformMatrix) 58 | .project(projectionConstant) 59 | } 60 | 61 | _projectPolygonOrPoints(element: PolygonOrPoints3d): PolygonOrPoints2d { 62 | const xs: Array = [] 63 | const ys: Array = [] 64 | 65 | element.x.forEach((rawX: number, index: number) => { 66 | const point = this._projectPoint( 67 | rawX, 68 | element.y[index], 69 | element.z[index], 70 | index 71 | ) 72 | xs.push(point.x) 73 | ys.push(point.y) 74 | }) 75 | 76 | const { z, ...elementWithoutZ } = element 77 | return { ...elementWithoutZ, x: xs, y: ys } 78 | } 79 | 80 | _projectLines(lines: Lines3dSpecs): Lines2dSpecs { 81 | const xs0: Array = [] 82 | const ys0: Array = [] 83 | const xs1: Array = [] 84 | const ys1: Array = [] 85 | 86 | lines.x0.forEach((rawX0: number, index: number) => { 87 | const points0 = this._projectPoint( 88 | rawX0, 89 | lines.y0[index], 90 | lines.z0[index], 91 | index 92 | ) 93 | 94 | const points1 = this._projectPoint( 95 | lines.x1[index], 96 | lines.y1[index], 97 | lines.z1[index], 98 | index 99 | ) 100 | 101 | xs0.push(points0.x) 102 | ys0.push(points0.y) 103 | xs1.push(points1.x) 104 | ys1.push(points1.y) 105 | }) 106 | 107 | const { z0, z1, ...linesWithoutZ } = lines 108 | return { ...linesWithoutZ, x0: xs0, y0: ys0, x1: xs1, y1: ys1 } 109 | } 110 | 111 | render(data: Array): Array { 112 | return data.map((element: Data3dSpecs) => { 113 | switch (element.type) { 114 | case DataSpecType.polygon: 115 | case DataSpecType.points: 116 | return this._projectPolygonOrPoints(element) 117 | case DataSpecType.lines: 118 | return this._projectLines(element) 119 | } 120 | }) 121 | } 122 | } 123 | 124 | export default DataRenderer 125 | -------------------------------------------------------------------------------- /src/scene-cube.ts: -------------------------------------------------------------------------------- 1 | import { matrix4x4 } from "./primitive-types" 2 | import Vector from "./vector" 3 | import { rotateXYZmatrix, multiply4x4matrix } from "./geometry" 4 | 5 | class NormalUnitCube { 6 | CENTER = new Vector(0, 0, 0, "cube-center") // cube-center 7 | /* 8 | E4------F5 y 9 | |`. | `. | 10 | | `A0-----B1 *----- x (WORLD COORDINATE FRAME) 11 | | | | | \ 12 | G6--|--H7 | \ 13 | `. | `. | z 14 | `C2-----D3 15 | */ 16 | AXES = [ 17 | new Vector(0.25, 0, 0, "xAxis"), 18 | new Vector(0, 0.25, 0, "yAxis"), 19 | new Vector(0, 0, 0.25, "zAxis"), 20 | ] 21 | 22 | POINTS = [ 23 | new Vector(-1, +1, +1, "front-top-left"), // A0 24 | new Vector(+1, +1, +1, "front-top-right"), // B1 25 | new Vector(-1, -1, +1, "front-bottom-left"), // C2 26 | new Vector(+1, -1, +1, "front-bottom-right"), // D3 27 | new Vector(-1, +1, -1, "back-top-left"), // E4 28 | new Vector(+1, +1, -1, "back-top-right"), // F5 29 | new Vector(-1, -1, -1, "back-bottom-left"), // G6 30 | new Vector(+1, -1, -1, "back-bottom-right"), // H7 31 | ] 32 | /* 33 | i0 34 | g6 *---*---* 35 | | | | 36 | j1 *---*---* k2 37 | | | | 38 | *---*---* 39 | l3 40 | i0 41 | *----* 42 | | | 43 | j1 *----* 44 | \ | 45 | \ * l3 46 | m4 \ 47 | \ n5 48 | */ 49 | CROSS_SECTION_POINTS = [ 50 | new Vector(+0, +1, -1, "top-center"), // i0 51 | new Vector(-1, +0, -1, "left-center"), // j1 52 | new Vector(+1, +0, -1, "right-center"), // k2 53 | new Vector(+0, -1, -1, "bottom-center"), // l3 54 | new Vector(-1, +0, +1, "left-center-forward"), // m4 55 | new Vector(+0, -1, +1, "bottom-center-forward"), // n5 56 | ] 57 | } 58 | 59 | const UNIT_CUBE = new NormalUnitCube() 60 | 61 | class SceneCube { 62 | worldWrtCameraMatrix: matrix4x4 63 | wrtWorldMatrix: matrix4x4 64 | wrtCameraMatrix: matrix4x4 65 | zOffset: number 66 | range: number 67 | projectionConstant: number 68 | 69 | constructor( 70 | euler: { x: number; y: number; z: number }, 71 | worldWrtCameraMatrix: matrix4x4, 72 | zOffset: number, 73 | range: number, 74 | projectionConstant: number 75 | ) { 76 | this.wrtWorldMatrix = rotateXYZmatrix(euler) 77 | this.wrtCameraMatrix = multiply4x4matrix( 78 | worldWrtCameraMatrix, 79 | this.wrtWorldMatrix 80 | ) 81 | this.worldWrtCameraMatrix = worldWrtCameraMatrix 82 | this.zOffset = zOffset 83 | this.range = range 84 | this.projectionConstant = projectionConstant 85 | } 86 | 87 | get crossPoints2d() { 88 | return this._projectedPoints(UNIT_CUBE.CROSS_SECTION_POINTS) 89 | } 90 | 91 | get vertexPoints2d() { 92 | return this._projectedPoints(UNIT_CUBE.POINTS) 93 | } 94 | 95 | get axes2d() { 96 | return this._projectedPoints(UNIT_CUBE.AXES) 97 | } 98 | 99 | get worldAxes2d() { 100 | return this._projectedPoints(UNIT_CUBE.AXES, 0, this.worldWrtCameraMatrix) 101 | } 102 | 103 | get center2d() { 104 | const [point] = this._projectedPoints([UNIT_CUBE.CENTER]) 105 | return point 106 | } 107 | 108 | get worldOrigin2d() { 109 | const [point] = this._projectedPoints( 110 | [UNIT_CUBE.CENTER], 111 | 0, 112 | this.worldWrtCameraMatrix 113 | ) 114 | return point 115 | } 116 | 117 | _projectedPoints( 118 | points: Array, 119 | offset: number = this.zOffset, 120 | transformMatrix: matrix4x4 = this.wrtCameraMatrix 121 | ) { 122 | return points.map((point: Vector) => { 123 | return new Vector(point.x, point.y, point.z + offset, point.name) 124 | .transform(transformMatrix) 125 | .project(this.projectionConstant) 126 | }) 127 | } 128 | } 129 | 130 | export default SceneCube 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NPM](https://img.shields.io/npm/v/@mithi/bare-minimum-3d.svg)](https://www.npmjs.com/package/@mithi/bare-minimum-3d) 2 | [![MINIFIED](https://img.shields.io/bundlephobia/min/@mithi/bare-minimum-3d?color=%2300BCD4&label=minified)](https://bundlephobia.com/result?p=@mithi/bare-minimum-3d) 3 | [![GZIPPED](https://img.shields.io/bundlephobia/minzip/@mithi/bare-minimum-3d?color=%2300BCD4&label=minified%20%2B%20gzipped)](https://bundlephobia.com/result?p=bare-minimum-3d) 4 | [![Install Size](https://packagephobia.now.sh/badge?p=@mithi/bare-minimum-3d)](https://packagephobia.com/result?p=%40mithi%2Fbare-minimum-3d) 5 | [![Coverage Status](https://coveralls.io/repos/github/mithi/bare-minimum-3d/badge.svg?branch=master)](https://coveralls.io/github/mithi/bare-minimum-3d?branch=master) 6 | ![Test Passing](https://github.com/mithi/bare-minimum-3d/workflows/test/badge.svg) 7 | [![Code Climate](https://codeclimate.com/github/mithi/bare-minimum-3d/badges/gpa.svg)](https://codeclimate.com/github/mithi/bare-minimum-3d) 8 | [![technical debt](https://img.shields.io/codeclimate/tech-debt/mithi/bare-minimum-3d)](https://codeclimate.com/github/mithi/bare-minimum-3d/trends/technical_debt) 9 | [![buy me coffee](https://img.shields.io/badge/Buy%20me%20-coffee!-orange.svg?logo=buy-me-a-coffee&color=795548)](https://ko-fi.com/minimithi) 10 | 11 | # Bare Minimum 3d 12 | 13 | A small package to transform declared 3d data (points, polygons, lines) to 2d data. The output is intended to be fed to a [`BareMinimum2d`](https://github.com/mithi/bare-minimum-2d) React component. 14 | 15 | Extremely lightweight and fairly configurable, this package has zero dependencies and a relatively straightforward declarative API. See also: [why I created this project](https://github.com/mithi/bare-minimum-3d/wiki/Why-I-created-this-project). 16 | 17 | 18 | You can checkout a demo application (and play with the parameters!) at: https://mithi.github.io/hello-3d-world 19 | 20 | ![](https://user-images.githubusercontent.com/1670421/91668232-c04c9c00-eb3d-11ea-8673-c1a525c7bc27.png) 21 | 22 | ## Getting started 23 | 24 | ``` 25 | $ npm i @mithi/bare-minimum-3d 26 | $ npm i bare-minimum-2d 27 | ``` 28 | 29 | You can check out the examples of [`SceneOptions`, `SceneSettings`, `ViewSettings`](https://github.com/mithi/bare-minimum-3d/blob/master/test/data/input-settings.ts) that you can pass to the `renderScene()` function. You can pass 3d data such as this [`hexapod`](https://github.com/mithi/bare-minimum-3d/blob/master/test/data/input-data-3d.ts) or [`pyramid`](https://github.com/mithi/hello-3d-world/blob/master/src/data/input-3d-pyramid.ts). When you pass the hexapod data along with the other example parameters linked above, [`this is the corresponding 2d data`](https://github.com/mithi/bare-minimum-3d/blob/master/test/data/output-data-2d.ts) that `renderScene()` would return. 30 | 31 | ```js 32 | import BareMinimum2d from "bare-minimum-2d" 33 | import renderScene from "@mithi/bare-minimum-3d" 34 | 35 | const { container, data } = renderScene( 36 | viewSettings, sceneSettings, sceneOptions, data3d 37 | ) 38 | 39 | 40 | ``` 41 | 42 | Please check the [wiki / documentation](https://github.com/mithi/bare-minimum-3d/wiki), to learn more about the arguments that you'll need to pass to `BareMinimum3d`'s `renderScene()` function. 43 | 44 | - [`SceneOptions`](https://github.com/mithi/bare-minimum-3d/wiki/SceneOptions) 45 | - [`SceneSettings`](https://github.com/mithi/bare-minimum-3d/wiki/SceneSettings) 46 | - [`ViewSettings`](https://github.com/mithi/bare-minimum-3d/wiki/ViewSettings) 47 | 48 | ## `0.4.0` Update 49 | 50 | In Version `0.4.0` all utility functions are now exposed to the users, so you can use it however you like. With all the building blocks available to you, you can even build your own custom `renderScene` function, should you want to! 51 | 52 | ```js 53 | import { 54 | renderScene, 55 | SCENE_ORIENTATION, 56 | getWorldWrtCameraMatrix, 57 | AxesRenderer, 58 | SceneCube, 59 | DataRenderer, 60 | SceneCubeRenderer, 61 | Vector, 62 | rotateXYZmatrix, 63 | multiply4x4matrix, 64 | radians, 65 | } from "@mithi/bare-minimum-3d" 66 | ``` 67 | 68 | ## ⚠️❗ Limitations 69 | 70 | This library does NOT perform [clipping](https://www.gabrielgambetta.com/computer-graphics-from-scratch/clipping.html) or [hidden surface removal](https://www.gabrielgambetta.com/computer-graphics-from-scratch/hidden-surface-removal.html). Each element are just painted to the screen in the order that you declare them in your array of data, and the scene elements are always rendered first, meaning your data will be rendered on top of any scene element. This means that it is possible that elements will incorrectly overlap other elements that are actually nearer to the camera. There is no plan to fix this... unless someone [makes a pull request](https://github.com/mithi/bare-minimum-3d/issues/20)! :heart: 71 | 72 | ## Contributing [![PRs welcome!](https://img.shields.io/badge/PRs-welcome-orange.svg?style=flat)](./CONTRIBUTING.md) 73 | 74 | Please read the [contributing guidelines](https://github.com/mithi/hexapod/blob/master/CONTRIBUTING.md) and the recommended [commit style guide](https://github.com/mithi/hexapod/wiki/A-Commit-Style-Guide)! Thank you! 75 | -------------------------------------------------------------------------------- /src/scene-cube-renderer.ts: -------------------------------------------------------------------------------- 1 | import SceneCube from "./scene-cube" 2 | import { SceneOptions } from "./parameter-types" 3 | import Vector from "./vector" 4 | import { 5 | Polygon2dSpecs, 6 | Lines2dSpecs, 7 | Data2dSpecs, 8 | DataSpecType, 9 | } from "./primitive-types" 10 | import AxesRenderer from "./axes-renderer" 11 | 12 | class SceneCubeRenderer { 13 | cube: SceneCube 14 | sceneOptions: SceneOptions 15 | constructor(cube: SceneCube, sceneOptions: SceneOptions) { 16 | this.cube = cube 17 | this.sceneOptions = sceneOptions 18 | } 19 | 20 | render(): Array { 21 | return [ 22 | ...this.drawXYplane(), 23 | ...this.drawBox(), 24 | ...this.drawCrossSectionLines(), 25 | ...this.drawEdgeAxes(), 26 | ...this.drawWorldAxes(), 27 | ...this.drawCubeAxes(), 28 | ] 29 | } 30 | 31 | /* 32 | E4 F5 33 | *----------* 34 | | | 35 | | | y 36 | | | | 37 | *----------* *-- x 38 | G6 H7 39 | */ 40 | drawXYplane(): Array { 41 | const { xyPlane } = this.sceneOptions 42 | if (!xyPlane) { 43 | return [] 44 | } 45 | 46 | const { color, opacity } = xyPlane 47 | const p: Array = this.cube.vertexPoints2d 48 | const polygon: Polygon2dSpecs = { 49 | x: [p[4].x, p[5].x, p[7].x, p[6].x], 50 | y: [p[4].y, p[5].y, p[7].y, p[6].y], 51 | fillColor: color, 52 | fillOpacity: opacity || 1.0, 53 | borderColor: color, 54 | borderOpacity: opacity || 1.0, 55 | borderSize: 1, 56 | type: DataSpecType.polygon, 57 | id: "xy-plane", 58 | } 59 | return [polygon] 60 | } 61 | /* 62 | E4------F5 y 63 | |`. | `. | 64 | | `A0-----B1 *----- x 65 | | | | | \ 66 | G6--|--H7 | \ 67 | `. | `. | z 68 | `C2-----D3 69 | face 1 - A0, B1, D3 | C2 (front) 70 | face 2 - B1, F5, H7 | D3 (front right) 71 | face 3 - F5, E4, G6 | H7 (front left) 72 | face 4 - E4, A0, C2 | G6 (back) 73 | face 5 - E4, F5, B1 | A0 (top) 74 | face 6 - C2 , D3, H7 | G6 |(bottom) 75 | */ 76 | 77 | drawBox(): Array { 78 | const { sceneEdges } = this.sceneOptions 79 | if (!sceneEdges) { 80 | return [] 81 | } 82 | 83 | const start: Array = [0, 1, 3, 2, 5, 7, 6, 4, 1, 0, 3, 2] 84 | const end: Array = [1, 3, 2, 0, 7, 6, 4, 5, 5, 4, 7, 6] 85 | const p: Array = this.cube.vertexPoints2d 86 | const { color, opacity } = sceneEdges 87 | 88 | const lines: Lines2dSpecs = { 89 | x0: start.map(i => p[i].x), 90 | y0: start.map(i => p[i].y), 91 | x1: end.map(i => p[i].x), 92 | y1: end.map(i => p[i].y), 93 | color: color, 94 | opacity: opacity || 1.0, 95 | size: 1, 96 | type: DataSpecType.lines, 97 | id: "scene-edges-cube-box", 98 | } 99 | 100 | return [lines] 101 | } 102 | 103 | /* 104 | (y)^ 105 | i0 | 106 | *---*---* +1 | 107 | | | | 0 |---------->(x) 108 | j1 *---*---* k2 -1 | -1, 0, 1 109 | | | | 110 | *---*---* 111 | l3 112 | i0 113 | *----* 114 | | | 115 | j1 *----* 116 | \ | 117 | \ * l3 118 | m4 \ 119 | \ n5 120 | E4 F5 121 | *----------* 122 | | | 123 | | | y 124 | | | | 125 | *----------* *-- x 126 | G6 H7 127 | */ 128 | 129 | drawCrossSectionLines(): Array { 130 | const { crossLines } = this.sceneOptions 131 | if (!crossLines) { 132 | return [] 133 | } 134 | 135 | const p: Array = this.cube.crossPoints2d 136 | const t: Array = this.cube.vertexPoints2d 137 | 138 | const { color, opacity } = crossLines 139 | 140 | const lines: Lines2dSpecs = { 141 | x0: [p[0].x, p[1].x, p[1].x, p[3].x, t[6].x, t[4].x, t[5].x, t[7].x], 142 | y0: [p[0].y, p[1].y, p[1].y, p[3].y, t[6].y, t[4].y, t[5].y, t[7].y], 143 | x1: [p[3].x, p[2].x, p[4].x, p[5].x, t[4].x, t[5].x, t[7].x, t[6].x], 144 | y1: [p[3].y, p[2].y, p[4].y, p[5].y, t[4].y, t[5].y, t[7].y, t[6].y], 145 | color: color, 146 | opacity: opacity || 1.0, 147 | size: 1, 148 | type: DataSpecType.lines, 149 | id: "cross-section-lines", 150 | } 151 | return [lines] 152 | } 153 | 154 | /* 155 | E4 y 156 | | | 157 | | *----- x (WORLD COORDINATE FRAME) 158 | | \ 159 | G6-------H7 \ 160 | \ z 161 | \C2 162 | xEdge=red 163 | yEdge=blue 164 | zEdge=green 165 | intersectionPoint=white (G6) 166 | */ 167 | 168 | drawEdgeAxes(): Array { 169 | const { edgeAxes } = this.sceneOptions 170 | if (!edgeAxes) { 171 | return [] 172 | } 173 | const p: Array = this.cube.vertexPoints2d 174 | return new AxesRenderer(p[6], [p[7], p[4], p[2]], "edge-axes", edgeAxes).render() 175 | } 176 | 177 | drawWorldAxes(): Array { 178 | const { worldAxes } = this.sceneOptions 179 | if (!worldAxes) { 180 | return [] 181 | } 182 | 183 | return new AxesRenderer( 184 | this.cube.worldOrigin2d, 185 | this.cube.worldAxes2d, 186 | "world-axes", 187 | worldAxes 188 | ).render() 189 | } 190 | 191 | drawCubeAxes(): Array { 192 | const { cubeAxes } = this.sceneOptions 193 | if (!cubeAxes) { 194 | return [] 195 | } 196 | 197 | return new AxesRenderer( 198 | this.cube.center2d, 199 | this.cube.axes2d, 200 | "cube-axes", 201 | cubeAxes 202 | ).render() 203 | } 204 | } 205 | export default SceneCubeRenderer 206 | -------------------------------------------------------------------------------- /test/data/input-data-3d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Polygon3dSpecs, 3 | Points3dSpecs, 4 | Lines3dSpecs, 5 | DataSpecType, 6 | } from "../../src/primitive-types" 7 | 8 | const BODY_MESH_COLOR = "#ff6348" 9 | const BODY_COLOR = "#FC427B" 10 | const COG_COLOR = "#32ff7e" 11 | const LEG_COLOR = "#EE5A24" 12 | const SUPPORT_POLYGON_MESH_COLOR = "#3c6382" 13 | const NORMAL_POINT_SIZE = 8 14 | const BODY_MESH_OPACITY = 0.3 15 | const BODY_OUTLINE_WIDTH = 5 16 | const COG_SIZE = 14 17 | const HEAD_SIZE = 14 18 | const LEG_OUTLINE_WIDTH = 5 19 | const SUPPORT_POLYGON_MESH_OPACITY = 0.2 20 | 21 | const BODY: Polygon3dSpecs = { 22 | id: "body-hexagon", 23 | type: DataSpecType.polygon, 24 | borderOpacity: 1.0, 25 | borderColor: BODY_COLOR, 26 | borderSize: BODY_OUTLINE_WIDTH, 27 | fillOpacity: BODY_MESH_OPACITY, 28 | fillColor: BODY_MESH_COLOR, 29 | x: [100.0, 100.0, -100.0, -100.0, -100.0, 100.0, 100.0], 30 | y: [0.0, 100.0, 100.0, 0.0, -100.0, -100.0, 0.0], 31 | z: [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0], 32 | } 33 | 34 | const BODY_POINTS: Points3dSpecs = { 35 | id: "body-points", 36 | type: DataSpecType.points, 37 | opacity: 1.0, 38 | color: BODY_COLOR, 39 | size: NORMAL_POINT_SIZE, 40 | x: [100.0, 100.0, -100.0, -100.0, -100.0, 100.0, 100.0], 41 | y: [0.0, 100.0, 100.0, 0.0, -100.0, -100.0, 0.0], 42 | z: [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0], 43 | } 44 | 45 | const SUPPORT_POLYGON: Polygon3dSpecs = { 46 | id: "support-polygon", 47 | type: DataSpecType.polygon, 48 | borderOpacity: 0, 49 | borderColor: SUPPORT_POLYGON_MESH_COLOR, 50 | borderSize: 0, 51 | fillOpacity: SUPPORT_POLYGON_MESH_OPACITY, 52 | fillColor: SUPPORT_POLYGON_MESH_COLOR, 53 | x: [ 54 | 300.0, 55 | 241.4213562373095, 56 | -241.42135623730948, 57 | -300.0, 58 | -241.42135623730954, 59 | 241.42135623730948, 60 | ], 61 | y: [ 62 | 0.0, 63 | 241.42135623730948, 64 | 241.4213562373095, 65 | 2.4492935982947064e-14, 66 | -241.42135623730948, 67 | -241.42135623730954, 68 | ], 69 | z: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 70 | } 71 | 72 | const LEG_LINES: Array = [ 73 | { 74 | opacity: 1.0, 75 | color: LEG_COLOR, 76 | size: LEG_OUTLINE_WIDTH, 77 | type: DataSpecType.lines, 78 | id: "leg-0", 79 | x0: [100, 200, 300], 80 | y0: [0, 0, 0], 81 | z0: [100, 100, 100], 82 | x1: [200, 300, 300], 83 | y1: [0, 0, 0], 84 | z1: [100, 100, 0], 85 | }, 86 | { 87 | opacity: 1.0, 88 | color: LEG_COLOR, 89 | size: LEG_OUTLINE_WIDTH, 90 | type: DataSpecType.lines, 91 | id: "leg-1", 92 | x0: [100.0, 170.71, 241.42], 93 | y0: [100.0, 170.71, 241.42], 94 | z0: [100.0, 100.0, 100.0], 95 | x1: [170.71, 241.42, 241.42], 96 | y1: [170.71, 241.42, 241.42], 97 | z1: [100, 100, 0], 98 | }, 99 | { 100 | opacity: 1.0, 101 | color: LEG_COLOR, 102 | size: LEG_OUTLINE_WIDTH, 103 | type: DataSpecType.lines, 104 | id: "leg-2", 105 | x0: [-100.0, -170.71067811865476, -241.42135623730948], 106 | y0: [100.0, 170.71067811865476, 241.4213562373095], 107 | z0: [100.0, 100.0, 100.0], 108 | x1: [-170.71, -241.42, -241.42], 109 | y1: [170.71, 241.42, 241.42], 110 | z1: [100, 100, 0], 111 | }, 112 | { 113 | opacity: 1.0, 114 | color: LEG_COLOR, 115 | size: LEG_OUTLINE_WIDTH, 116 | type: DataSpecType.lines, 117 | id: "leg-3", 118 | x0: [-100.0, -200.0, -300.0], 119 | y0: [0.0, 0, 0], 120 | z0: [100.0, 100.0, 100.0], 121 | x1: [-200, -300, -300], 122 | y1: [0, 0, 0], 123 | z1: [100, 100, 0], 124 | }, 125 | { 126 | opacity: 1.0, 127 | color: LEG_COLOR, 128 | size: LEG_OUTLINE_WIDTH, 129 | type: DataSpecType.lines, 130 | id: "leg-4", 131 | x0: [-100.0, -170.71067811865476, -241.42135623730954], 132 | y0: [-100.0, -170.71067811865476, -241.42135623730948], 133 | z0: [100.0, 100.0, 100.0], 134 | x1: [-170.71, -241.42, -241.42], 135 | y1: [-170.71, -241.42, -241.42], 136 | z1: [100, 100, 0], 137 | }, 138 | { 139 | opacity: 1.0, 140 | color: LEG_COLOR, 141 | size: LEG_OUTLINE_WIDTH, 142 | type: DataSpecType.lines, 143 | id: "leg-5", 144 | x0: [100.0, 170.71067811865476, 241.42135623730948], 145 | y0: [-100.0, -170.71067811865476, -241.42135623730954], 146 | z0: [100.0, 100.0, 100.0], 147 | x1: [170, 241.42, 241.42], 148 | y1: [-170, -241.42, -241.24], 149 | z1: [100, 100, 0], 150 | }, 151 | ] 152 | 153 | const LEG_POINTS: Array = [ 154 | { 155 | opacity: 1.0, 156 | color: LEG_COLOR, 157 | size: LEG_OUTLINE_WIDTH, 158 | type: DataSpecType.points, 159 | id: "rightMiddleLegpoints0", 160 | x: [100.0, 200.0, 300.0, 300.0], 161 | y: [0.0, 0.0, 0.0, 0.0], 162 | z: [100.0, 100.0, 100.0, 0.0], 163 | }, 164 | { 165 | opacity: 1.0, 166 | color: LEG_COLOR, 167 | size: LEG_OUTLINE_WIDTH, 168 | type: DataSpecType.points, 169 | id: "rightFrontLegpoints1", 170 | x: [100.0, 170.71067811865476, 241.4213562373095, 241.4213562373095], 171 | y: [100.0, 170.71067811865476, 241.42135623730948, 241.42135623730948], 172 | z: [100.0, 100.0, 100.0, 0.0], 173 | }, 174 | { 175 | opacity: 1.0, 176 | color: LEG_COLOR, 177 | size: LEG_OUTLINE_WIDTH, 178 | type: DataSpecType.points, 179 | id: "leftFrontLegpoints2", 180 | x: [-100.0, -170.71067811865476, -241.42135623730948, -241.42135623730948], 181 | y: [100.0, 170.71067811865476, 241.4213562373095, 241.4213562373095], 182 | z: [100.0, 100.0, 100.0, 0.0], 183 | }, 184 | { 185 | opacity: 1.0, 186 | color: LEG_COLOR, 187 | size: LEG_OUTLINE_WIDTH, 188 | type: DataSpecType.points, 189 | id: "leftMiddleLegpoints3", 190 | x: [-100.0, -200.0, -300.0, -300.0], 191 | y: [0.0, 1.2246467991473532e-14, 2.4492935982947064e-14, 2.4492935982947064e-14], 192 | z: [100.0, 100.0, 100.0, 0.0], 193 | }, 194 | { 195 | opacity: 1.0, 196 | color: LEG_COLOR, 197 | size: LEG_OUTLINE_WIDTH, 198 | type: DataSpecType.points, 199 | id: "leftBackLegpoints4", 200 | x: [-100.0, -170.71067811865476, -241.42135623730954, -241.42135623730954], 201 | y: [-100.0, -170.71067811865476, -241.42135623730948, -241.42135623730948], 202 | z: [100.0, 100.0, 100.0, 0.0], 203 | }, 204 | { 205 | opacity: 1.0, 206 | color: LEG_COLOR, 207 | size: LEG_OUTLINE_WIDTH, 208 | type: DataSpecType.points, 209 | id: "rightBackLegpoints5", 210 | x: [100.0, 170.71067811865476, 241.42135623730948, 241.42135623730948], 211 | y: [-100.0, -170.71067811865476, -241.42135623730954, -241.42135623730954], 212 | z: [100.0, 100.0, 100.0, 0.0], 213 | }, 214 | ] 215 | 216 | const MISC_POINTS: Array = [ 217 | { 218 | color: COG_COLOR, 219 | opacity: 1, 220 | size: COG_SIZE, 221 | id: "centerOfGravity", 222 | type: DataSpecType.points, 223 | x: [0.0], 224 | y: [0.0], 225 | z: [100.0], 226 | }, 227 | 228 | { 229 | color: BODY_COLOR, 230 | opacity: 1.0, 231 | size: HEAD_SIZE, 232 | id: "head", 233 | type: DataSpecType.points, 234 | x: [0.0], 235 | y: [100.0], 236 | z: [100.0], 237 | }, 238 | ] 239 | 240 | // ...LEG_LINES, ...LEG_POINTS, ...MISC_POINTS 241 | 242 | const DATA = [ 243 | SUPPORT_POLYGON, 244 | ...LEG_POINTS, 245 | ...LEG_LINES, 246 | BODY, 247 | BODY_POINTS, 248 | ...MISC_POINTS, 249 | ] 250 | export default DATA 251 | // LEG_POINTS 252 | // GROUND_MESH 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /test/data/output-data-2d.ts: -------------------------------------------------------------------------------- 1 | const props2d = { 2 | container: { color: "#17212B", opacity: 1, xRange: 600, yRange: 600 }, 3 | data: [ 4 | { 5 | x: [ 6 | 161.67462016999573, 7 | -149.49085809525332, 8 | -190.77850898381033, 9 | 58.14499340227819, 10 | ], 11 | y: [ 12 | -174.17973350240138, 13 | -225.55076310101552, 14 | -31.76965868048612, 15 | -5.2326718136170784, 16 | ], 17 | fillColor: "#0652DD", 18 | fillOpacity: 0.1, 19 | borderColor: "#0652DD", 20 | borderOpacity: 0.1, 21 | borderSize: 1, 22 | type: "polygon", 23 | id: "xy-plane", 24 | }, 25 | { 26 | x0: [ 27 | 224.0746641168776, 28 | -157.0145249835535, 29 | -203.85273903715975, 30 | 87.91179633150188, 31 | -149.49085809525332, 32 | -190.77850898381033, 33 | 58.14499340227819, 34 | 161.67462016999573, 35 | -157.0145249835535, 36 | 224.0746641168776, 37 | -203.85273903715975, 38 | 87.91179633150188, 39 | ], 40 | y0: [ 41 | 105.0757907851432, 42 | 76.15578712214187, 43 | 224.73422317739303, 44 | 233.9834428781948, 45 | -225.55076310101552, 46 | -31.76965868048612, 47 | -5.2326718136170784, 48 | -174.17973350240138, 49 | 76.15578712214187, 50 | 105.0757907851432, 51 | 224.73422317739303, 52 | 233.9834428781948, 53 | ], 54 | x1: [ 55 | -157.0145249835535, 56 | -203.85273903715975, 57 | 87.91179633150188, 58 | 224.0746641168776, 59 | -190.77850898381033, 60 | 58.14499340227819, 61 | 161.67462016999573, 62 | -149.49085809525332, 63 | -149.49085809525332, 64 | 161.67462016999573, 65 | -190.77850898381033, 66 | 58.14499340227819, 67 | ], 68 | y1: [ 69 | 76.15578712214187, 70 | 224.73422317739303, 71 | 233.9834428781948, 72 | 105.0757907851432, 73 | -31.76965868048612, 74 | -5.2326718136170784, 75 | -174.17973350240138, 76 | -225.55076310101552, 77 | -225.55076310101552, 78 | -174.17973350240138, 79 | -31.76965868048612, 80 | -5.2326718136170784, 81 | ], 82 | color: "#607D8B", 83 | opacity: 1, 84 | size: 1, 85 | type: "lines", 86 | id: "scene-edges-cube-box", 87 | }, 88 | { 89 | x0: [ 90 | 13.579028890489033, 91 | 103.84787807766645, 92 | 103.84787807766645, 93 | -61.63028651029317, 94 | 58.14499340227819, 95 | 161.67462016999573, 96 | -149.49085809525332, 97 | -190.77850898381033, 98 | ], 99 | y0: [ 100 | -198.62917771921326, 101 | -79.81391312275588, 102 | -79.81391312275588, 103 | -18.001554621177572, 104 | -5.2326718136170784, 105 | -174.17973350240138, 106 | -225.55076310101552, 107 | -31.76965868048612, 108 | ], 109 | x1: [ 110 | -61.63028651029317, 111 | -172.76547128356057, 112 | 146.4974525629976, 113 | -51.515755148341945, 114 | 161.67462016999573, 115 | -149.49085809525332, 116 | -190.77850898381033, 117 | 58.14499340227819, 118 | ], 119 | y1: [ 120 | -18.001554621177572, 121 | -116.3127669562455, 122 | 178.5194275121503, 123 | 229.56345381286016, 124 | -174.17973350240138, 125 | -225.55076310101552, 126 | -31.76965868048612, 127 | -5.2326718136170784, 128 | ], 129 | color: "#795548", 130 | opacity: 1, 131 | size: 1, 132 | type: "lines", 133 | id: "cross-section-lines", 134 | }, 135 | { 136 | x0: [58.14499340227819], 137 | y0: [-5.2326718136170784], 138 | x1: [-190.77850898381033], 139 | y1: [-31.76965868048612], 140 | color: "#E91E63", 141 | opacity: 1, 142 | size: 1, 143 | type: "lines", 144 | id: "x-edge-axes", 145 | }, 146 | { 147 | x0: [58.14499340227819], 148 | y0: [-5.2326718136170784], 149 | x1: [161.67462016999573], 150 | y1: [-174.17973350240138], 151 | color: "#03A9F4", 152 | opacity: 1, 153 | size: 1, 154 | type: "lines", 155 | id: "y-edge-axes", 156 | }, 157 | { 158 | x0: [58.14499340227819], 159 | y0: [-5.2326718136170784], 160 | x1: [87.91179633150188], 161 | y1: [233.9834428781948], 162 | color: "#CDDC39", 163 | opacity: 1, 164 | size: 1, 165 | type: "lines", 166 | id: "z-edge-axes", 167 | }, 168 | { 169 | x: [58.14499340227819], 170 | y: [-5.2326718136170784], 171 | color: "#FF00FF", 172 | opacity: 1, 173 | size: 5, 174 | type: "points", 175 | id: "point-edge-axes", 176 | }, 177 | { 178 | x0: [-28.615384615384617], 179 | y0: [-97.2923076923077], 180 | x1: [-64.38461538461539], 181 | y1: [-97.2923076923077], 182 | color: "#E91E63", 183 | opacity: 1, 184 | size: 3, 185 | type: "lines", 186 | id: "x-world-axes", 187 | }, 188 | { 189 | x0: [-28.615384615384617], 190 | y0: [-97.2923076923077], 191 | x1: [-28.615384615384617], 192 | y1: [-133.06153846153845], 193 | color: "#03A9F4", 194 | opacity: 1, 195 | size: 3, 196 | type: "lines", 197 | id: "y-world-axes", 198 | }, 199 | { 200 | x0: [-28.615384615384617], 201 | y0: [-97.2923076923077], 202 | x1: [-29.76], 203 | y1: [-101.18400000000001], 204 | color: "#CDDC39", 205 | opacity: 1, 206 | size: 3, 207 | type: "lines", 208 | id: "z-world-axes", 209 | }, 210 | { 211 | x: [-28.615384615384617], 212 | y: [-97.2923076923077], 213 | color: "#FFFF00", 214 | opacity: 1, 215 | size: 5, 216 | type: "points", 217 | id: "point-world-axes", 218 | }, 219 | { 220 | x0: [-20.33453589638525], 221 | y0: [24.45380450656123], 222 | x1: [-58.340211931810515], 223 | y1: [20.84583906223499], 224 | color: "#E91E63", 225 | opacity: 1, 226 | size: 3, 227 | type: "lines", 228 | id: "x-cube-axes", 229 | }, 230 | { 231 | x0: [-20.33453589638525], 232 | y0: [24.45380450656123], 233 | x1: [-9.595413451612322], 234 | y1: [3.540345800017196], 235 | color: "#03A9F4", 236 | opacity: 1, 237 | size: 3, 238 | type: "lines", 239 | id: "y-cube-axes", 240 | }, 241 | { 242 | x0: [-20.33453589638525], 243 | y0: [24.45380450656123], 244 | x1: [-18.02278469501903], 245 | y1: [58.441470588620945], 246 | color: "#CDDC39", 247 | opacity: 1, 248 | size: 3, 249 | type: "lines", 250 | id: "z-cube-axes", 251 | }, 252 | { 253 | x: [-20.33453589638525], 254 | y: [24.45380450656123], 255 | color: "#00FF00", 256 | opacity: 1, 257 | size: 5, 258 | type: "points", 259 | id: "point-cube-axes", 260 | }, 261 | { 262 | id: "support-polygon", 263 | type: "polygon", 264 | borderOpacity: 0, 265 | borderColor: "#3c6382", 266 | borderSize: 0, 267 | fillOpacity: 0.2, 268 | fillColor: "#3c6382", 269 | x: [ 270 | -99.13499614523474, 271 | -72.1381111231581, 272 | 44.17856451741092, 273 | 38.98643417759471, 274 | 9.509593200113317, 275 | -96.87990129898287, 276 | ], 277 | y: [ 278 | -106.59729965877008, 279 | -143.47336921255348, 280 | -126.70498950754066, 281 | -88.3723155491199, 282 | -56.838685246548266, 283 | -69.70976089542354, 284 | ], 285 | }, 286 | { 287 | opacity: 1, 288 | color: "#EE5A24", 289 | size: 5, 290 | type: "points", 291 | id: "rightMiddleLegpoints0", 292 | x: [ 293 | -50.82639457031958, 294 | -74.66045608624152, 295 | -98.84237242078565, 296 | -99.13499614523474, 297 | ], 298 | y: [ 299 | -81.40018562248044, 300 | -84.40870283403318, 301 | -87.46112893657569, 302 | -106.59729965877008, 303 | ], 304 | }, 305 | { 306 | opacity: 1, 307 | color: "#EE5A24", 308 | size: 5, 309 | type: "points", 310 | id: "rightFrontLegpoints1", 311 | x: [ 312 | -44.857534097927875, 313 | -57.86614260149225, 314 | -71.4223600281128, 315 | -72.1381111231581, 316 | ], 317 | y: [ 318 | -96.53006359988692, 319 | -109.96224807048861, 320 | -123.95987227049888, 321 | -143.47336921255348, 322 | ], 323 | }, 324 | { 325 | opacity: 1, 326 | color: "#EE5A24", 327 | size: 5, 328 | type: "points", 329 | id: "leftFrontLegpoints2", 330 | x: [ 331 | 2.68582089897977, 332 | 24.412427103369733, 333 | 46.567430199449845, 334 | 44.17856451741092, 335 | ], 336 | y: [ 337 | -90.29882816602719, 338 | -98.88580391823503, 339 | -107.64209436628896, 340 | -126.70498950754066, 341 | ], 342 | }, 343 | { 344 | opacity: 1, 345 | color: "#EE5A24", 346 | size: 5, 347 | type: "points", 348 | id: "leftMiddleLegpoints3", 349 | x: [ 350 | -4.172238578023106, 351 | 18.66213365193309, 352 | 41.177221139068166, 353 | 38.98643417759471, 354 | ], 355 | y: [ 356 | -75.51114186048775, 357 | -72.6288130629837, 358 | -69.78678682337654, 359 | -88.3723155491199, 360 | ], 361 | }, 362 | { 363 | opacity: 1, 364 | color: "#EE5A24", 365 | size: 5, 366 | type: "points", 367 | id: "leftBackLegpoints4", 368 | x: [ 369 | -10.754986486008747, 370 | 0.4366840432089152, 371 | 11.216434247611291, 372 | 9.509593200113317, 373 | ], 374 | y: [ 375 | -61.31709594733114, 376 | -49.76101114076187, 377 | -38.6302592811095, 378 | -56.838685246548266, 379 | ], 380 | }, 381 | { 382 | opacity: 1, 383 | color: "#EE5A24", 384 | size: 5, 385 | type: "points", 386 | id: "rightBackLegpoints5", 387 | x: [ 388 | -56.55226300371927, 389 | -76.74854518593125, 390 | -96.57172230891533, 391 | -96.87990129898287, 392 | ], 393 | y: [ 394 | -66.88624429101091, 395 | -58.904096331411026, 396 | -51.06941015514152, 397 | -69.70976089542354, 398 | ], 399 | }, 400 | { 401 | opacity: 1, 402 | color: "#EE5A24", 403 | size: 5, 404 | type: "lines", 405 | id: "leg-0", 406 | x0: [-50.82639457031958, -74.66045608624152, -98.84237242078565], 407 | y0: [-81.40018562248044, -84.40870283403318, -87.46112893657569], 408 | x1: [-74.66045608624152, -98.84237242078565, -99.13499614523474], 409 | y1: [-84.40870283403318, -87.46112893657569, -106.59729965877008], 410 | }, 411 | { 412 | opacity: 1, 413 | color: "#EE5A24", 414 | size: 5, 415 | type: "lines", 416 | id: "leg-1", 417 | x0: [-44.857534097927875, -57.86601527669466, -71.42209454605768], 418 | y0: [-96.53006359988692, -109.96211659984218, -123.95959814402815], 419 | x1: [-57.86601527669466, -71.42209454605768, -72.13784931672937], 420 | y1: [-109.96211659984218, -123.95959814402815, -143.4730914151873], 421 | }, 422 | { 423 | opacity: 1, 424 | color: "#EE5A24", 425 | size: 5, 426 | type: "lines", 427 | id: "leg-2", 428 | x0: [2.68582089897977, 24.412427103369733, 46.567430199449845], 429 | y0: [-90.29882816602719, -98.88580391823503, -107.64209436628896], 430 | x1: [24.4122167101179, 46.56700107518136, 44.17814201485293], 431 | y1: [-98.88572076480854, -107.64192476411303, -126.70481879371827], 432 | }, 433 | { 434 | opacity: 1, 435 | color: "#EE5A24", 436 | size: 5, 437 | type: "lines", 438 | id: "leg-3", 439 | x0: [-4.172238578023106, 18.66213365193309, 41.177221139068166], 440 | y0: [-75.51114186048775, -72.6288130629837, -69.78678682337653], 441 | x1: [18.66213365193309, 41.177221139068166, 38.98643417759471], 442 | y1: [-72.6288130629837, -69.78678682337653, -88.3723155491199], 443 | }, 444 | { 445 | opacity: 1, 446 | color: "#EE5A24", 447 | size: 5, 448 | type: "lines", 449 | id: "leg-4", 450 | x0: [-10.754986486008747, 0.4366840432089152, 11.216434247611291], 451 | y0: [-61.31709594733114, -49.76101114076187, -38.6302592811095], 452 | x1: [0.4365787267528505, 11.21623129587826, 9.5093923058009], 453 | y1: [-49.76111988644864, -38.630468841195494, -56.8388984113324], 454 | }, 455 | { 456 | opacity: 1, 457 | color: "#EE5A24", 458 | size: 5, 459 | type: "lines", 460 | id: "leg-5", 461 | x0: [-56.55226300371927, -76.74854518593125, -96.57172230891533], 462 | y0: [-66.88624429101091, -58.904096331411026, -51.06941015514152], 463 | x1: [-76.54743590722609, -96.57134561048139, -96.87118363846942], 464 | y1: [-58.98358046637161, -51.069559037129245, -69.73479352786138], 465 | }, 466 | { 467 | id: "body-hexagon", 468 | type: "polygon", 469 | borderOpacity: 1, 470 | borderColor: "#FC427B", 471 | borderSize: 5, 472 | fillOpacity: 0.3, 473 | fillColor: "#ff6348", 474 | x: [ 475 | -50.82639457031958, 476 | -44.857534097927875, 477 | 2.68582089897977, 478 | -4.172238578023106, 479 | -10.754986486008747, 480 | -56.55226300371927, 481 | -50.82639457031958, 482 | ], 483 | y: [ 484 | -81.40018562248044, 485 | -96.53006359988692, 486 | -90.29882816602719, 487 | -75.51114186048775, 488 | -61.31709594733114, 489 | -66.88624429101091, 490 | -81.40018562248044, 491 | ], 492 | }, 493 | { 494 | id: "body-points", 495 | type: "points", 496 | opacity: 1, 497 | color: "#FC427B", 498 | size: 8, 499 | x: [ 500 | -50.82639457031958, 501 | -44.857534097927875, 502 | 2.68582089897977, 503 | -4.172238578023106, 504 | -10.754986486008747, 505 | -56.55226300371927, 506 | -50.82639457031958, 507 | ], 508 | y: [ 509 | -81.40018562248044, 510 | -96.53006359988692, 511 | -90.29882816602719, 512 | -75.51114186048775, 513 | -61.31709594733114, 514 | -66.88624429101091, 515 | -81.40018562248044, 516 | ], 517 | }, 518 | { 519 | color: "#32ff7e", 520 | opacity: 1, 521 | size: 14, 522 | id: "centerOfGravity", 523 | type: "points", 524 | x: [-27.33273567944495], 525 | y: [-78.43463662914887], 526 | }, 527 | { 528 | color: "#FC427B", 529 | opacity: 1, 530 | size: 14, 531 | id: "head", 532 | type: "points", 533 | x: [-20.91252502759967], 534 | y: [-93.39172830586264], 535 | }, 536 | ], 537 | } 538 | 539 | export default props2d 540 | --------------------------------------------------------------------------------