# new Geometry()
- Source:
Geometry in ClayGL contains vertex attributes of mesh. These vertex attributes will be finally provided to the clay.Shader. Different clay.Shader needs different attributes. Here is a list of attributes used in the builtin shaders.
- position:
clay.basic
,clay.lambert
,clay.standard
- texcoord0:
clay.basic
,clay.lambert
,clay.standard
- color:
clay.basic
,clay.lambert
,clay.standard
- weight:
clay.basic
,clay.lambert
,clay.standard
- joint:
clay.basic
,clay.lambert
,clay.standard
- normal:
clay.lambert
,clay.standard
- tangent:
clay.standard
Create a procedural geometry
ClayGL provides a couple of builtin procedural geometries. Inlcuding:
- clay.geometry.Cube
- clay.geometry.Sphere
- clay.geometry.Plane
- clay.geometry.Cylinder
- clay.geometry.Cone
- clay.geometry.ParametricSurface
It's simple to create a basic geometry with these classes.
var sphere = new clay.geometry.Sphere({
radius: 2
});
Create the geometry data by yourself
Usually the vertex attributes data are created by the clay.loader.GLTF or procedural geometries like clay.geometry.Sphere. Besides these, you can create the data manually. Here is a simple example to create a triangle.
var TRIANGLE_POSITIONS = [
[-0.5, -0.5, 0],
[0.5, -0.5, 0],
[0, 0.5, 0]
];
var geometry = new clay.StaticGeometryBase();
// Add triangle vertices to position attribute.
geometry.attributes.position.fromArray(TRIANGLE_POSITIONS);
Then you can use the utility methods like generateVertexNormals
, generateTangents
to create the remaining necessary attributes.
Use with custom shaders
If you wan't to write custom shaders. Don't forget to add SEMANTICS to these attributes. For example
uniform mat4 worldViewProjection : WORLDVIEWPROJECTION;
uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
uniform mat4 world : WORLD;
attribute vec3 position : POSITION;
attribute vec2 texcoord : TEXCOORD_0;
attribute vec3 normal : NORMAL;
These POSITION
, TEXCOORD_0
, NORMAL
are SEMANTICS which will map the attributes in shader to the attributes in the GeometryBase
Available attributes SEMANTICS includes POSITION
, TEXCOORD_0
, TEXCOORD_1
NORMAL
, TANGENT
, COLOR
, WEIGHT
, JOINT
.
Extends
Members
# __uid__ :number
- Source:
- Inherited From:
Type:
- number
# attributes :Object.<string, clay.Geometry.Attribute>
- Source:
- Overrides:
Attributes of geometry. Including:
position
texcoord0
texcoord1
normal
tangent
color
weight
joint
barycentric
Type:
- Object.<string, clay.Geometry.Attribute>
# boundingBox :clay.BoundingBox
- Source:
Calculated bounding box of geometry.
Type:
# dynamic :boolean
- Source:
- Inherited From:
Is vertices data dynamically updated. Attributes value can't be changed after first render if dyanmic is false.
Type:
- boolean
# indices :Uint16Array|Uint32Array
- Source:
- Inherited From:
Indices of geometry.
Type:
- Uint16Array | Uint32Array
# mainAttribute :string
- Source:
- Overrides:
Main attribute will be used to count vertex number
Type:
- string
# (nullable) pick :function
- Source:
- Inherited From:
User defined picking algorithm instead of default triangle ray intersection x, y are NDC.
(x, y, renderer, camera, renderable, out) => boolean
Type:
- function
# (nullable) pickByRay :function
- Source:
- Inherited From:
User defined ray picking algorithm instead of default triangle ray intersection
(ray: clay.Ray, renderable: clay.Renderable, out: Array) => boolean
Type:
- function
# (readonly) triangleCount :number
- Source:
- Inherited From:
Type:
- number
# (readonly) vertexCount :number
- Source:
- Inherited From:
Type:
- number
Methods
# after(name, action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Alias of once('after' + name)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | ||
action |
function | ||
context |
Object |
<optional> |
# applyTransform(matrix)
- Source:
Apply transform to geometry attributes.
Parameters:
Name | Type | Description |
---|---|---|
matrix |
clay.Matrix4 |
# before(name, action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Alias of once('before' + name)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | ||
action |
function | ||
context |
Object |
<optional> |
# createAttribute(name, type, size, semanticopt)
- Source:
- Inherited From:
Create a new attribute
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | ||
type |
string | ||
size |
number | ||
semantic |
string |
<optional> |
# dirty()
- Source:
- Inherited From:
Mark attributes and indices in geometry needs to update. Usually called after you change the data in attributes.
# dirtyAttribute(attrNameopt)
- Source:
- Inherited From:
Mark the attributes needs to update.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
attrName |
string |
<optional> |
# dirtyIndices()
- Source:
- Inherited From:
Mark the indices needs to update.
# dispose(renderer)
- Source:
- Overrides:
Dispose geometry data in GL context.
Parameters:
Name | Type | Description |
---|---|---|
renderer |
clay.Renderer |
# error(action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Alias of on('error')
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
action |
function | ||
context |
Object |
<optional> |
# generateBarycentric()
- Source:
Generate barycentric coordinates for wireframe draw.
# generateFaceNormals()
- Source:
Generate normals per face.
# generateTangents()
- Source:
Generate tangents attributes.
# generateUniqueVertex()
- Source:
Create a unique vertex for each index.
# generateVertexNormals()
- Source:
Generate normals per vertex.
# getAttribute(name) → {clay.GeometryBase.Attribute}
- Source:
- Inherited From:
Get attribute
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
Returns:
# getEnabledAttributes() → {Array.<string>}
- Source:
- Inherited From:
Get enabled attributes name list Attribute which has the same vertex number with position is treated as a enabled attribute
Returns:
- Type
- Array.<string>
# getTriangleIndices(idx, out) → {Array.<number>}
- Source:
- Inherited From:
Get indices of triangle at given index.
Parameters:
Name | Type | Description |
---|---|---|
idx |
number | |
out |
Array.<number> |
Returns:
- Type
- Array.<number>
# has(name, action) → {boolean}
- Source:
- Inherited From:
- Mixes In:
If registered the event handler
Parameters:
Name | Type | Description |
---|---|---|
name |
string | |
action |
function |
Returns:
- Type
- boolean
# initIndicesFromArray(array)
- Source:
- Inherited From:
Initialize indices from an array.
Parameters:
Name | Type | Description |
---|---|---|
array |
Array |
# isUniqueVertex()
- Source:
If vertices are not shared by different indices.
# off(action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Remove event listener
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
action |
function | ||
context |
Object |
<optional> |
# on(name, action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Register event handler
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | ||
action |
function | ||
context |
Object |
<optional> |
# once(name, action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Register event, event will only be triggered once and then removed
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | ||
action |
function | ||
context |
Object |
<optional> |
# removeAttribute(name)
- Source:
- Inherited From:
Remove attribute
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
# setTriangleIndices(idx, arr)
- Source:
- Inherited From:
Set indices of triangle at given index.
Parameters:
Name | Type | Description |
---|---|---|
idx |
number | |
arr |
Array.<number> |
# success(action, contextopt)
- Source:
- Inherited From:
- Mixes In:
Alias of on('success')
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
action |
function | ||
context |
Object |
<optional> |
# trigger(name)
- Source:
- Inherited From:
- Mixes In:
Trigger event
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
# updateBoundingBox()
- Source:
Update boundingBox of Geometry