V8 Javascript API

Polygon_mesh Class Reference

[Elements]

Description

Represents a polygon mesh within the scene graph. Actual mesh data is not loaded unless the mesh property is accessed or the mesh data fields are accessed. At that time a read-only binary representation of the mesh is retrieved and stored in the object. Refer to the documentation for the geometry_get_mesh command for details of this binary format. This representation can be passed to the static create method to generate a new mesh based on the data. It can also be edited by accessing the properties of this class which return JavaScript typed array views of the underlying binary representation. If these properties are modified the V8 representation will become inconsistent with that stored in the database until such time as the commit method is called. This will create a new mesh in the database with the same name as the existing one, overwriting it. You can also completely change the mesh data properties by setting them yourself but note that these will not be validated by this class.

Constructor

 Polygon_mesh( String name)
More...

Functions

varying as( String type_name)
Upcasts an element to a specific element type. More...
 commit()
Commits any changes made to the mesh. More...
the copy( String name, Number privacy_level)
Make a copy of this element in the database. More...
 create( String element_type, Number privacy_level)
Creates a scene element called name. More...
 delete()
Remove this element from the database.
bool  exists( String element_type)
Returns whether the element exists or not. More...
 localize( Number privacy_level)
Localizes this element. More...
varying property_get( String cache, String command, String element_name_arg, Function as_a)
Retrieves and caches a property of an element. More...
 property_set( String cache, String command, String element_name_arg, String value_arg_name, varying value, Function from_a)
Sets and caches a property of an element. More...
 set_material( String material, bool override)
Sets the material and, optionally, material override on this element. More...

Static Functions

Polygon_mesh create( String name, Object mesh, Boolean visible)
Creates a new Polygon_mesh. More...

Properties

Attributes attributes
The attributes associated with this element.
Uint32Array  corners
The array of the number of corner points in each polygon.
bool  disable
Set to true to disable the element and all elements below this in the scene graph. More...
bool  exists
Returns whether the polygon mesh exists or not. More...
bool  hide
Alias for disable.
Uint8Array  holes
The array of values representing whether a given polygon is a hole. More...
Mdl_material_instance[] material
The material to use for this element. More...
Uint32Array  material_ids
The array of material_ids for each polygon.
String  material_override
The override attribute for the material. More...
Number  max_displacement
The maximum displacement allowed on an object.
Object  mesh
The actual mesh data in a binary representation retrieved on demand.
String  name
The name of the element. More...
Uint32Array  normal_indices
The array of normal_indices which specify the normals to be used for each vertex of a polygon. More...
Float32Array  normals
The array of normal point values used by the mesh.
Uint32Array  offsets
The array of offsets of the start point of each polygon in the index arrays.
Uint32Array  point_indices
The array of point_indices which specify the points to be used for each vertex of a polygon. More...
Float32Array  points
Returns the array of position point values used by the mesh.
Boolean  tagged
Whether or not the mesh should utilise the material_ids property to apply different materials to each polygon. More...
String  type_name
The type name of the element. More...
Array  user
The array of Float32Array items each of which represent the user data values for a given named user data set.
Array  user_indices
The array of Uint32Array items which specify the user data to be used for each vertex of a triangle. More...
Array  user_names
The array of string items which specify the names of the each user data set.
Array  user_sizes
The array of number items which specify the size of the vectors used by the user data.
Array  uv_indices
The array of Uint32Array items which specify the UVs to be used for each vertex of a polygon. More...
Array  uv_sizes
The array of number items which specify the size of the vectors used by the texture space.
Array  uvs
The array of Float32Array items each of which represent the UV values for a given texture coordinate space.

Constructor

Polygon_mesh( String name)

Note:

It is not possible to create a Polygon_mesh in the constructor.

Parameters

name
The name of the polygon mesh

Functions

varying Polygon_mesh.as( String type_name)

Upcasts an element to a specific element type. If this element is not of the given type then undefined is returned. If type_name does not have a matching element implementation an error is thrown. Note that this is not strictly an upcast but will return a new instance of the specific class representing type_name.

Parameters

type_name
the element type name to convert to.

Returns

the specific Element implementation for this element.

Polygon_mesh.commit()

Commits any changes made to the mesh. This will overwrite the current mesh in the database with the modified version. Please note that no validation is performed on the mesh data. Additionally note that the original mesh data is shadowed in the database and not deleted. If you wish to ensure the old data is removed you should create a new mesh with a different name using the static create method and then remove the original mesh by calling its delete method.

the Polygon_mesh.copy( String name, Number privacy_level)

Make a copy of this element in the database.

Parameters

name
The name of the new element to copy to.
privacy_level
The privacy level to which the element will be copied. Defaults to the privacy level of the current scope.

Returns

copied element

Polygon_mesh.create( String element_type, Number privacy_level)

Creates a scene element called name. Throws on error.

Parameters

element_type
the type of element to create
privacy_level
The privacy level to create the element at. Defaults to the privacy level of the current scope.
Polygon_mesh Polygon_mesh.create( String name, Object mesh, Boolean visible) [static]

Creates a new Polygon_mesh.

Parameters

name
the name of the polygon mesh to create
mesh
polygon mesh data used to create the mesh. See generate_mesh command for details
visible
if true will set the visible attribute on the generated mesh. Defaults to true

Returns

the generated mesh scene element

Polygon_mesh.delete()

Remove this element from the database.

bool Polygon_mesh.exists( String element_type)

Returns whether the element exists or not.

Note:

element_type of 'Scene' is not supported. To test if a Scene exists use this.as('Scene') !== undefined

Parameters

element_type
if provided then the element must also be of this type.
Polygon_mesh.localize( Number privacy_level)

Localizes this element.

Parameters

privacy_level
The privacy level to which the element will be localized. Defaults to the privacy level of the current scope.
varying Polygon_mesh.property_get( String cache, String command, String element_name_arg, Function as_a)

Retrieves and caches a property of an element. The value of the property must be retrievable via a command that takes a single argument which is the name of the element to retrieve the property from. The name of this Element is used. If the returned property is another named scene Element then the element's constructor can be provided to return the element itself rather than it's name. On error this will return undefined.

Parameters

cache
name of the property to cache the result to
command
name of the RS command to get the property value
element_name_arg
name of the command argument to use for the element name
as_a
if the property being retrieved is an RS Element then the element constructor should be passed in here. The result of the command is assumed to be the element name and this is used to create an Element instance to return rather than the name of the element. Use undefined if the retrieved value is not an element.

Returns

the property value if it exists or undefined

Polygon_mesh.property_set( String cache, String command, String element_name_arg, String value_arg_name, varying value, Function from_a)

Sets and caches a property of an element. The value of the property must be set via a command that takes two arguments, one being the name of the element to set and the other being the property's value. The names of these arguments are passed in. If the property is another named scene Element then the element's constructor can be provided and value can either be the element itself or it's name. Will throw on error.

Parameters

cache
name of the property to cache the result to
command
name of the RS command to set the property value
element_name_arg
name of the command argument to use for the element name
value_arg_name
name of the value argument to use for the value
value
the value to set
from_a
if the property being set is a RealityServer Element then the element constructor should be passed in here. value can then either be the name of the scene element or the Element itself. If value is a name then an Element is constructed and cache rather than the name itself. Use undefined if the value does not represent an Element .
Polygon_mesh.set_material( String material, bool override)

Sets the material and, optionally, material override on this element.

Parameters

material
the material to set, see Element_scene_graph.material
override
if defined then sets override on the material, see Element_scene_graph.material_override

Properties

Attributes Polygon_mesh.attributes

The attributes associated with this element.

Uint32Array Polygon_mesh.corners

The array of the number of corner points in each polygon.

bool Polygon_mesh.disable

Set to true to disable the element and all elements below this in the scene graph. Set to false to show again or undefined to remove the disable attribute completely.

bool Polygon_mesh.exists

Returns whether the polygon mesh exists or not. This test is type checked.

bool Polygon_mesh.hide

Alias for disable.

Uint8Array Polygon_mesh.holes

The array of values representing whether a given polygon is a hole. If a polygon is a hole it must be specified immediately after the non-hole polygon into which it is cut. A value of 0 indicates a non-hole polygon and 1 indicates a hole polygon.

Mdl_material_instance[] Polygon_mesh.material

The material to use for this element. When setting can supply either a String giving the name of the material to use or a Mdl_material_instance . Arrays of these can also be used. Note that single values will always be converted to arrays when setting. Getting always returns an array of Mdl_material_instance .

Uint32Array Polygon_mesh.material_ids

The array of material_ids for each polygon.

String Polygon_mesh.material_override

The override attribute for the material. Accepts the strings override or standard as valid values. Truthy non-string values will be interpreted as override, otherwise standard.

Number Polygon_mesh.max_displacement

The maximum displacement allowed on an object.

Object Polygon_mesh.mesh

The actual mesh data in a binary representation retrieved on demand.

String Polygon_mesh.name

The name of the element. Read only.

Uint32Array Polygon_mesh.normal_indices

The array of normal_indices which specify the normals to be used for each vertex of a polygon. This is a flat array and must be combined with the corners information to divide it into polygons. Random access is possible by using the offsets property to determine where a polygon starts and the corners property to determine its extent

Float32Array Polygon_mesh.normals

The array of normal point values used by the mesh.

Uint32Array Polygon_mesh.offsets

The array of offsets of the start point of each polygon in the index arrays.

Uint32Array Polygon_mesh.point_indices

The array of point_indices which specify the points to be used for each vertex of a polygon. This is a flat array and must be combined with the corners information to divide it into polygons. Random access is possible by using the offsets property to determine where a polygon starts and the corners property to determine its extent

Float32Array Polygon_mesh.points

Returns the array of position point values used by the mesh.

Boolean Polygon_mesh.tagged

Whether or not the mesh should utilise the material_ids property to apply different materials to each polygon. If true then the material_ids property must also be present

String Polygon_mesh.type_name

The type name of the element. If the element does not exists returns undefined. Read only.

Note:

For a Scene element this will return 'Attribute_container', not 'Scene'.

Array Polygon_mesh.user

The array of Float32Array items each of which represent the user data values for a given named user data set.

Array Polygon_mesh.user_indices

The array of Uint32Array items which specify the user data to be used for each vertex of a triangle. This is a flat array, random access is possible by using the fact that all triangles always have three vertices

Array Polygon_mesh.user_names

The array of string items which specify the names of the each user data set.

Array Polygon_mesh.user_sizes

The array of number items which specify the size of the vectors used by the user data.

Array Polygon_mesh.uv_indices

The array of Uint32Array items which specify the UVs to be used for each vertex of a polygon. This is a flat array and must be combined with the corners information to divide it into polygons. Random access is possible by using the offsets property to determine where a polygon starts and the corners property to determine its extent

Array Polygon_mesh.uv_sizes

The array of number items which specify the size of the vectors used by the texture space.

Array Polygon_mesh.uvs

The array of Float32Array items each of which represent the UV values for a given texture coordinate space.