Socket
Book a DemoInstallSign in
Socket

3d-svg-engine

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3d-svg-engine

lightweight 3d engine based on SVG

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

3D SVG engine

Lightweight 3d engine that uses SVG as a rendering environment.

Used technologies:

  • Webpack for build project
  • Typescript as main language engine

Getting started

You can link to a 3d SVG engine files hosted online. You can use these links:

<script src="https://cdn.jsdelivr.net/gh/manInit/3d-svg-engine/dist/3dengine.dist.js"></script>

and

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/manInit/3d-svg-engine/dist/3dengine.css">

A sample HTML page might look like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Starter template</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/manInit/3d-svg-engine/dist/3dengine.css">
</head>
<body>
  <div id="world"></div>
  <script src="https://cdn.jsdelivr.net/gh/manInit/3d-svg-engine/dist/3dengine.dist.js"></script>
  <script>
    add(cube(10))
  </script>
</body>
</html>

Root elem for render is element with id = "world". This element should be in document

How to control camera

For pointer lock you should click on root tag.

You can rotate camera with mouse movement. And next keys to control camera:

keys

KeyEffect
WASDMove camera
shiftFlying down
spacebarFlying up
arrowsRotate camera

Examples

Here some examples usage this library

  • Simple model solar system: Example Example
  • Voxel draw: Example Example

Documentation

Basic figures

cube(size, x, y, z, color)

Create object of cube

Parameters:

ParamDescriptionDefaultExample
sizeCube side length-10.23
xx coordinate of the center of the cube012
yy coordinate of the center of the cube023
zz coordinate of the center of the cube034
colorCube color'black''#ff4433ee'

pyramid(size, x, y, z, color)

Create object of pyramid

Parameters:

ParamDescriptionDefaultExample
sizePyramid side length-23.4
xx coordinate of the center of the pyramid023.3
yy coordinate of the center of the pyramid0534.2
zz coordinate of the center of the pyramid0-23.3
colorPyramid color'black''#ffee99ee'

parallelepiped(sizea, sizeb, sizec, x, y, z, color)

Create object of parallelepiped

Parameters:

ParamDescriptionDefaultExample
sizeaParallelepiped length to depth-23.4
sizebParallelepiped height--12.3
sizecParallelepiped width--10.3
xx coordinate of the center of the parallelepiped023
yy coordinate of the center of the parallelepiped02.2
zz coordinate of the center of the parallelepiped0-3.2
colorPyramid color'black''#ff443366'

sphere(r, x, y, z, color)

Create object of sphere

Parameters:

ParamDescriptionDefaultExample
rSphere radius-34.4
xx coordinate of the center of the parallelepiped023
yy coordinate of the center of the parallelepiped023.4
zz coordinate of the center of the parallelepiped034.5
colorPyramid color'black''#99339900'

Basic figures methods

All figures have methods for moving and rotating

.translate(x, y, z)

Мove the figure. Arguments define how much the figure moves in each direction.

Parameters:

ParamDescriptionDefaultExample
xMoves along x axis-23
yMoves along y axis-23.4
zMoves along z axis-34.5

.rotate(ax, ay, az)

Rotate figure around the center coordinates (Angles in degrees).

Parameters:

ParamDescriptionDefaultExample
axRotate around the x axis-23
ayRotate around the y axis-23.4
azRotate around the z axis-34.5

Player object

You have access to the global player object which contains information about the camera position and direction of view. You can set these properties too. Like this:

    player.position = { x: 100, y: 150, z: 100 }

Properties

PropertyDescriptionExample
positionObject with coords camera position{ x: 23, y: 46, z: -100 }
rotationObject with angles of camera (angles in degrees){ ax: 123, ay: 10, az: -10 }

Basic functions

add(...objects)

Add objects on scene

parameters:

ParamDescriptionDefaultExample
...objectsObjects we want to add to the scene-cube(12), sphere(23), pyramid(1)

update(callbackFunction)

Use custom function to update state scene. Like move figures or rotate and etc. This function will be called every frame

Parameters:

ParamDescriptionDefaultExample
callbackFunctionFunction-() => myCube.translate(1, 0, 0)

setBackground(urlImage)

Set background image to scene. This image will be translated left/right with rotate camera.

Parameters:

ParamDescriptionDefaultExample
urlImagePath to image-'./sky.png'

saveScreen()

Capture screenshot and download as SVG file

Parameters:

Without params

Keywords

3d

FAQs

Package last updated on 24 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.