Description Usage Arguments Details Value
View source: R/trimesh_to_threejson.R
Generate threejs model JSON from a triangular mesh.
1 2 3 | trimesh_to_threejson(vertices, face_vertices, colours, face_vertex_colours,
normals, face_vertex_normals, vertex_uvs, texture_file,
transparency = 1)
|
vertices |
a matrix of vertices with 3 columns corresponding to: x, y, z. |
face_vertices |
a matrix with 3 columns of faces as defined by their vertices. column 1 is the row index of a vertex in 'vertices', column 2 is a second row index in of a vertex, and so on for column 3, making up three vertices of a triangular face. |
colours |
a character vector of colours of form: '0x7cccba' (hex) |
face_vertex_colours |
a matrix with 3 columns of face vertex colour indicies in 'colours', each row corresponds to a face in 'face_vertices'. Row 1, column 1 is the colour index of vertex 1 in face 1. |
normals |
a 3 column matrix of normal vectors in x, y, z space. |
face_vertex_normals |
a matrix with 3 columns of face vertex normal indicies in 'normals', each row corresponds to a face in 'face_vertices'. Row 1, column 1 is the normal index of vertex 1 in face 1. |
vertex_uvs |
A 2 column matrix of texture coordinates, the same length as 'vertices'. |
texture_file |
An path to an image file. |
transparency |
A numeric value between 0 and 1 indicating to what degree the model should be transparent. 1.0 is fully opaque, 0 is fully transparent. |
The format of threejs model JSON is described here: https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3 In this format each face is described by lists of indicies into lists of vertices, colours and normals. Colours, normals and vertices can be re-used or shared among faces so there are no length requirements on 'vertices', 'colours', or 'normals'. All the 'face_' arguments must have the same length or be not supplied.
JSON describing the mesh.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.