Class: VoxelEditor

VoxelEditor()

Class used to interface with the scene and handles the main render loop.

Constructor

new VoxelEditor()

Source:

Members

extrudeBrushAction

Perform the current brush action for the extrude brush type. For add, place a layer of voxels on all adjacent voxels of the same color along the clicked side. For remove, remove a layer of adjacent voxels of the same color along the clicked side. For paint, paint a layer of adjacent voxels of the same color along the clicked side.

Source:

singleBrushAction

Perform the current brush action for the single brush type. For add, add a single voxel. For remove, remove a single voxel. For paint, paint a single voxel.

Source:

Methods

addLight(x, y, z)

Adds a directional light to the scene at the given x, y, and z position. Remember, the default position of the directional light's target is (0, 0, 0).

Parameters:
Name Type Description
x number
y number
z number
Source:

createCamera(fovopt, aspectopt, nearopt, faropt)

Helper function used to create the camera and set it to a default position.

Parameters:
Name Type Attributes Default Description
fov number <optional>
75

field of view

aspect number <optional>
2

Aspect. Canvas default is 2

near number <optional>
0.1
far number <optional>
1000
Source:

createOrbitControls()

Helper function to create the orbit controls.

Source:

getCanvasRelativePosition(event) → {Object}

Finds the x and y coordinate of a mouse click relative to the canvas.

Parameters:
Name Type Description
event Event
Source:
Returns:

Object with x and y coordinates of click relative to canvas

Type
Object

onExportImage(imageName)

Exports the current frame of the canvas to an image file.

Parameters:
Name Type Description
imageName string
Source:

onExportModel(name, type)

Exports the voxel model to some 3D file format

Parameters:
Name Type Description
name string

What the exported file should be called

type string

The type of file to export

Source:

onGetProjectData() → {Object}

Gets project data from the currently open project.

Source:
Returns:

JavaScript object representing the relevant data from the currently open project/scene.

Type
Object

onLoadProjectData(projectData)

Loads a project from the given data.

Parameters:
Name Type Description
projectData Object
Source:

onNewProject()

Creates a new, empty voxel world

Source:

onNewSelectedColor(index)

Updates which voxel the user is placing/painting now from the palette.

Parameters:
Name Type Description
index number
Source:

onSelectedColorChange(index, r, g, b)

Called whenever a new color is selected.

Parameters:
Name Type Description
index number

Index of the changed color

r r

Red color from 0-1

g g

Green color from 0-1

b b

Blue color from 0-1

Source:

placeVoxel(event)

Handler for adding, removing, or painting a voxel based on the given brush and where the user clicked.

Parameters:
Name Type Description
event Event
Source:

placeVoxelIfNoMovement(event)

Callback function used to check if the user meant to set a voxel instead of orbiting the camera.

Parameters:
Name Type Description
event Event
Source:

recordMovement(event)

Callback function used to record how far the mouse has moved since started recording.

Parameters:
Name Type Description
event Event
Source:

recordStartPosition(event)

Reset mouse movement and begin recording.

Parameters:
Name Type Description
event Event
Source:

render()

Main render loop.

Source:

requestRenderIfNotRequested()

Used to make a render update request only if one hasn't been made already.

Source:

resizeRendererToDisplaySize(renderer) → {boolean}

Checks if the renderer needs to resize to account for changes in screen width or height.

Parameters:
Name Type Description
renderer WebGLRenderer
Source:
Returns:

True if the renderer resized. False otherwise.

Type
boolean