Skip to content

Commit

Permalink
change parameters of setAttribute in MeshBuffer; address last TODOs; …
Browse files Browse the repository at this point in the history
…prepare for beta3; etc.
  • Loading branch information
peteroupc committed Apr 21, 2017
1 parent 765e995 commit ea65672
Show file tree
Hide file tree
Showing 35 changed files with 551 additions and 461 deletions.
14 changes: 3 additions & 11 deletions demos/backgrounds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global H3DU */
/* global H3DU, quadBatch */
/*
Any copyright to this file is released to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
Expand Down Expand Up @@ -33,11 +33,7 @@ function SunburstBackground(black, white) {
"whiteColor":H3DU.toGLColor(white).slice(0, 3),
"time":0
});
this.batch = new H3DU.Batch3D().addShape(
new H3DU.Shape(
new H3DU.MeshBuffer()
.setAttribute("POSITION", 0, [-1, 1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0], 0, 3)
.setIndices([0, 1, 2, 2, 1, 3])).setShader(this.shader));
this.batch = quadBatch(this.shader);
this.getBatch = function() {
return this.batch;
};
Expand Down Expand Up @@ -70,11 +66,7 @@ function StripesBackground(black, white) {
"whiteColor":H3DU.toGLColor(white).slice(0, 3),
"time":0
});
this.batch = new H3DU.Batch3D().addShape(
new H3DU.Shape(
new H3DU.MeshBuffer()
.setAttribute("POSITION", 0, [-1, 1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0], 0, 3)
.setIndices([0, 1, 2, 2, 1, 3])).setShader(this.shader));
this.batch = quadBatch(this.shader);
this.getBatch = function() {
return this.batch;
};
Expand Down
4 changes: 2 additions & 2 deletions demos/bsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ BspTree._MiniBuilder = function() {
};
this.toMeshBuffer = function() {
return new H3DU.MeshBuffer()
.setAttribute("POSITION", 0, this.vertices, 0, 3)
.setAttribute("NORMAL", 0, this.normals, 0, 3)
.setAttribute("POSITION", this.vertices, 3)
.setAttribute("NORMAL", this.normals, 3)
.setIndices(this.indices);
};
};
Expand Down
4 changes: 2 additions & 2 deletions demos/shaderlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ function fragmentShaderLib() {
"}",
""].join("\n");
}

/* exported quadBatch */
function quadBatch(shader) {
"use strict";
// Create a quad to fill the frame buffer
return new H3DU.Batch3D().addShape(
new H3DU.Shape(
new H3DU.MeshBuffer()
.setAttribute("POSITION", 0, [-1, 1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0], 0, 3)
.setAttribute("POSITION", [-1, 1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0], 3)
.setIndices([0, 1, 2, 2, 1, 3])).setShader(shader));
}

Expand Down
1 change: 0 additions & 1 deletion demos/underlay.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
360 * H3DU.getTimePosition(timer, time, 12000),
0
);
shape.setVisible(false)
shape.setQuaternion(q);
shape.getMaterial().setParams({"emission":[emissive, emissive, emissive]});
// Render the scene
Expand Down
4 changes: 2 additions & 2 deletions doc/H3DU.BufferAccessor.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
[Back to documentation index.](index.md)

<a name='H3DU.BufferAccessor'></a>
### H3DU.BufferAccessor(buffer, offset, countPerValue, [stride])
### H3DU.BufferAccessor(buffer, countPerValue, [offset], [stride])

A <b>vertex attribute object</b>.

#### Parameters

* `buffer` (Type: Float32Array)<br>A buffer to store vertex attribute data; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_buffer">H3DU.BufferAccessor#buffer</a>.
* `offset` (Type: number)<br>Offset to the first value; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_offset">H3DU.BufferAccessor#offset</a>. Throws an error if less than 0.
* `countPerValue` (Type: number)<br>Number of elements per value; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_countPerValue">H3DU.BufferAccessor#countPerValue</a>. Throws an error if 0 or less.
* `offset` (Type: number) (optional)<br>Offset to the first value; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_offset">H3DU.BufferAccessor#offset</a>. If null, undefined, or omitted, the default is 0. Throws an error if less than 0.
* `stride` (Type: number) (optional)<br>Number of elements from the start of one value to the start of the next; see <a href="H3DU.BufferAccessor.md#H3DU.BufferAccessor_stride">H3DU.BufferAccessor#stride</a>. If null, undefined, or omitted, has the same value as "countPerValue". Throws an error if 0 or less.

### Members
Expand Down
18 changes: 9 additions & 9 deletions doc/H3DU.Mesh.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ or at that point, those methods may be deprecated.</li></ul>
* [BITANGENTS_BIT](#H3DU.Mesh.BITANGENTS_BIT)<br><b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
bitangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.BITANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.BITANGENT">H3DU.Semantic.BITANGENT</a>
semantic.</b>
* [COLORS_BIT](#H3DU.Mesh.COLORS_BIT)<br>The mesh contains colors for each vertex.
* [LINES](#H3DU.Mesh.LINES)<br>Primitive mode for rendering line segments, made up
Expand All @@ -64,7 +64,7 @@ of 4 vertices each.
* [TANGENTS_BIT](#H3DU.Mesh.TANGENTS_BIT)<br><b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
tangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.TANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.TANGENT">H3DU.Semantic.TANGENT</a>
semantic.</b>
* [TEXCOORDS_BIT](#H3DU.Mesh.TEXCOORDS_BIT)<br>The mesh contains texture coordinates for each vertex.
* [TRIANGLES](#H3DU.Mesh.TRIANGLES)<br>Primitive mode for rendering triangles, made up
Expand All @@ -77,7 +77,7 @@ of 3 vertices each.
* [bitangent3](#H3DU.Mesh_bitangent3)<br><b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
bitangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.BITANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.BITANGENT">H3DU.Semantic.BITANGENT</a>
semantic.</b>
* [color3](#H3DU.Mesh_color3)<br>Sets the current color for this mesh.
* [enumPrimitives](#H3DU.Mesh_enumPrimitives)<br><b>Deprecated: For a replacement of this method,
Expand Down Expand Up @@ -108,7 +108,7 @@ given index.
* [tangent3](#H3DU.Mesh_tangent3)<br><b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
tangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.TANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.TANGENT">H3DU.Semantic.TANGENT</a>
semantic.</b>
* [texCoord2](#H3DU.Mesh_texCoord2)<br>Sets the current texture coordinates for this mesh.
* [toMeshBuffer](#H3DU.Mesh_toMeshBuffer)<br>Generates a mesh buffer from the information in this mesh object.
Expand All @@ -125,7 +125,7 @@ instead.</b>
<b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
bitangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.BITANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.BITANGENT">H3DU.Semantic.BITANGENT</a>
semantic.</b>

The mesh contains bitangent vectors for each vertex.
Expand Down Expand Up @@ -214,7 +214,7 @@ Default Value: `8`
<b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
tangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.TANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.TANGENT">H3DU.Semantic.TANGENT</a>
semantic.</b>

The mesh contains tangent vectors for each vertex.
Expand Down Expand Up @@ -264,7 +264,7 @@ Default Value: `5`
<b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
bitangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.BITANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.BITANGENT">H3DU.Semantic.BITANGENT</a>
semantic.</b>

Sets the current bitangent vector for this mesh. Future vertex positions
Expand Down Expand Up @@ -388,7 +388,7 @@ will not build upon previous vertices.

#### Parameters

* `other` (Type: <a href="H3DU.Mesh.md">H3DU.Mesh</a>)<br>A mesh to merge into this one. The mesh given in this parameter will remain unchanged. Throws an error if this mesh's primitive type is incompatible with the the other mesh's primitive type (for example, a triangle type with LINE_STRIP).
* `other` (Type: <a href="H3DU.Mesh.md">H3DU.Mesh</a> | <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a>)<br>A mesh to merge into this one. The mesh given in this parameter will remain unchanged. Throws an error if this mesh's primitive type is incompatible with the the other mesh's primitive type (for example, a triangle type with LINE_STRIP). <i>Passing a MeshBuffer to this method is for compatibility only.</i>

#### Return Value

Expand Down Expand Up @@ -584,7 +584,7 @@ This object. (Type: <a href="H3DU.Mesh.md">H3DU.Mesh</a>)
<b>Deprecated: Deprecated because the default shader no longer
uses tangent and bitangent attributes for normal mapping. To define
tangent vectors for a mesh, use the <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> class
and create a buffer attribute with the H3DU.Semantics.TANGENT
and create a buffer attribute with the <a href="H3DU.Semantic.md#H3DU.Semantic.TANGENT">H3DU.Semantic.TANGENT</a>
semantic.</b>

Sets the current tangent vector for this mesh. Future vertex positions
Expand Down
50 changes: 43 additions & 7 deletions doc/H3DU.MeshBuffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ by swapping the second and third vertex indices of each one.
* [setAttribute](#H3DU.MeshBuffer_setAttribute)<br>Adds information about a buffer attribute to this
mesh buffer (or sets an
existing attribute's information).
* [setAttributeEx](#H3DU.MeshBuffer_setAttributeEx)<br>Adds information about a buffer attribute to this
mesh buffer (or sets an
existing attribute's information), taking a semantic index as
an additional parameter.
* [setColor](#H3DU.MeshBuffer_setColor)<br>Sets all the vertices in this mesh to the given color, by
assigning each value with the attribute semantic <code>COLOR</code>
to the given color.
* [setColor3](#H3DU.MeshBuffer_setColor3)<br><b>Deprecated: Use <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setColor">H3DU.MeshBuffer#setColor</a> instead.</b>
* [setIndices](#H3DU.MeshBuffer_setIndices)<br>Sets the vertex indices used by this mesh buffer.
* [setPrimitiveType](#H3DU.MeshBuffer_setPrimitiveType)<br>Sets the type of graphics primitives stored in this mesh buffer.
* [toWireFrame](#H3DU.MeshBuffer_toWireFrame)<br><b>Deprecated: Included here for compatibility with <a href="H3DU.Mesh.md">H3DU.Mesh</a>.
Expand Down Expand Up @@ -154,7 +159,7 @@ and the other mesh's indices copied or adapted.

#### Parameters

* `other` (Type: <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a>)<br>A mesh to merge into this one. The mesh given in this parameter will remain unchanged. Throws an error if this mesh's primitive type is not the same as the other mesh's primitive type
* `other` (Type: <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a> | <a href="H3DU.Mesh.md">H3DU.Mesh</a>)<br>A mesh to merge into this one. The mesh given in this parameter will remain unchanged. Throws an error if this mesh's primitive type is not the same as the other mesh's primitive type. <i>Passing a Mesh to this method is for compatibility only and this feature may be dropped in the future.</i>

#### Return Value

Expand Down Expand Up @@ -272,7 +277,7 @@ recommended only if face culling is enabled.
);

<a name='H3DU.MeshBuffer_setAttribute'></a>
### H3DU.MeshBuffer#setAttribute(name, index, buffer, startIndex, countPerVertex, [stride])
### H3DU.MeshBuffer#setAttribute(name, buffer, countPerValue, [offset], [stride])

Adds information about a buffer attribute to this
mesh buffer (or sets an
Expand All @@ -282,12 +287,35 @@ stored in a vertex buffer.

#### Parameters

* `name` (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, "POSITION", or "TEXCOORD_0". Throws an error if this value is a string and the string is invalid. If this isn't a string, the set index of the attribute will be 0 (see <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setAttributeEx">H3DU.MeshBuffer#setAttributeEx</a>).
* `buffer` (Type: Float32Array | Array)<br>The buffer where the per-vertex data is stored. See <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setAttributeEx">H3DU.MeshBuffer#setAttributeEx</a>.
* `countPerValue` (Type: number)<br>The number of elements in each per-vertex item. See <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setAttributeEx">H3DU.MeshBuffer#setAttributeEx</a>.
* `offset` (Type: number) (optional)<br>The index into the array (starting from 0) where the first per-vertex item starts.See <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setAttributeEx">H3DU.MeshBuffer#setAttributeEx</a>.
* `stride` (Type: number) (optional)<br>The number of elements from the start of one per-vertex item to the start of the next. See <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setAttributeEx">H3DU.MeshBuffer#setAttributeEx</a>.

#### Return Value

This object.Throws an error if the given
semantic is unsupported. (Type: <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a>)

<a name='H3DU.MeshBuffer_setAttributeEx'></a>
### H3DU.MeshBuffer#setAttributeEx(name, index, buffer, [countPerValue], [offset], [stride])

Adds information about a buffer attribute to this
mesh buffer (or sets an
existing attribute's information), taking a semantic index as
an additional parameter. An attribute
gives information about the per-vertex data used and
stored in a vertex buffer.

#### Parameters

* `name` (Type: number | string)<br>An attribute semantic, such as <a href="H3DU.Semantic.md#H3DU.Semantic.POSITION">H3DU.Semantic.POSITION</a>, "POSITION", or "TEXCOORD_0". Throws an error if this value is a string and the string is invalid.
* `index` (Type: number)<br>The set index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string.
* `buffer` (Type: Float32Array | Array)<br>The buffer where the per-vertex data is stored.
* `startIndex` (Type: number)<br>The index into the array (starting from 0) where the first per-vertex item starts.
* `countPerVertex` (Type: number)<br>The number of elements in each per-vertex item. For example, if each vertex is a 3-element vector, this value is 3. Throws an error if this value is 0 or less.
* `stride` (Type: number) (optional)<br>The number of elements from the start of one per-vertex item to the start of the next. If null, undefined, or omitted, this value is the same as "countPerVertex". Throws an error if this value is 0 or less.
* `index` (Type: number)<br>The semantic index of the attribute for the given semantic. 0 is the first index of the attribute, 1 is the second, and so on. This is ignored if "name" is a string.
* `buffer` (Type: Float32Array | Array | BufferAccessor)<br>The buffer where the per-vertex data is stored.
* `countPerValue` (Type: number) (optional)<br>The number of elements in each per-vertex item. For example, if each vertex is a 3-element vector, this value is 3. Throws an error if this value is 0 or less. If "buffer" is a <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>, the value of "countPerValue" is taken from that accessor and this parameter is ignored; this parameter is currently required otherwise.
* `offset` (Type: number) (optional)<br>The index into the array (starting from 0) where the first per-vertex item starts. If null, undefined, or omitted, the default is 0. Throws an error if less than 0. If "buffer" is a <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>, the value of "offset" is taken from that accessor and this parameter is ignored.
* `stride` (Type: number) (optional)<br>The number of elements from the start of one per-vertex item to the start of the next. If null, undefined, or omitted, this value is the same as "countPerValue". Throws an error if this value is 0 or less. If "buffer" is a <a href="H3DU.BufferAccessor.md">H3DU.BufferAccessor</a>, the value of "stride" is taken from that accessor and this parameter is ignored.

#### Return Value

Expand Down Expand Up @@ -316,6 +344,14 @@ regardless of semantic index, are affected by this method.

This object. (Type: <a href="H3DU.MeshBuffer.md">H3DU.MeshBuffer</a>)

<a name='H3DU.MeshBuffer_setColor3'></a>
### H3DU.MeshBuffer#setColor3()

<b>Deprecated: Use <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setColor">H3DU.MeshBuffer#setColor</a> instead.</b>

Alias for the <a href="H3DU.MeshBuffer.md#H3DU.MeshBuffer_setColor">H3DU.MeshBuffer#setColor</a> method
for compatibility.

<a name='H3DU.MeshBuffer_setIndices'></a>
### H3DU.MeshBuffer#setIndices(indices)

Expand Down
33 changes: 33 additions & 0 deletions doc/tutorial-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@
<a id=Version_History></a>
## Version History

Version 2.0.0-beta3:

The changes in beta 3 from beta 2 include:

- The main library files were converted to ECMAScript's import/export convention. The `rollup` tool
is used to help generate the `h3du_min.js` file.
- HTML documentation included in distribution.
- "Norm" methods in H3DU.Math were renamed to use "Normalize" instead.
- New `convex.js` in extras folder generates the convex hull of a set of points.
- New `interp.js` in extras folder provides a cubic B&eacute;zier interpolation function.
- New `spline.js` in extras folder generates piecewise interpolating curves.
- New demos added, including demos showing how to generate procedural content using shaders.
- Several methods in H3DU.GraphicsPath were reimplemented.
- H3DU.BezierCurve and H3DU.BezierSpline are deprecated.
- H3DU.CurveBuilder and H3DU.SurfaceBuilder classes were created; they replace now-deprecated
H3DU.CurveEval and H3DU.SurfaceEval classes.
- H3DU.MeshBuffer contains many new methods; in exchange, many of the H3DU.Mesh
methods reimplemented in H3DU.MeshBuffer are deprecated.
- H3DU.Mesh is considerably deemphasized in this version; that class should only be used
for building meshes, not storing them.
- H3DU.Curve and H3DU.Surface were created; these classes represent parametric curves
and surfaces and offer methods for querying information at a given point on the curve or surface.
Made several class derive from either class, including H3DU.BSplineCurve, H3DU.BSplineSurface,
and new class H3DU.PiecewiseCurve.
- H3DU.RenderPass3D renamed to H3DU.RenderPass.
- Deleted fromBasic and fromBasicTexture methods from H3DU.PbrMaterial.
- Added JOINTS and WEIGHTS constants to H3DU.Semantic.
- Preliminary support for occlusion maps.
- Default diffuse/albedo in Material and PbrMaterial is now (1,1,1,1).
- New H3DU.BufferAccessor class represents a single vertex buffer.
- Many methods outside H3DU.Mesh now return H3DU.MeshBuffer instead of H3DU.Mesh.
- Bug fixes.

Version 2.0.0-beta2:

The changes in beta 2 from beta 1 include:
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The library differs from many others because this one is in the public domain, s

This page includes information on how to use the HTML 3D library, an overview of its features, and an example of a simple 3D-enabled Web page.

NOTE: This section and the rest of this page will largely discuss the 2.0.0-beta2 version of the HTML 3D library, which differs considerably from the current release (version 1.5.1) of the library. (See the section "History" for more information.)
NOTE: This section and the rest of this page will largely discuss the 2.0.0-beta3 version of the HTML 3D library, which differs considerably from the current release (version 1.5.1) of the library. (See the section "History" for more information.)

<a id=Example></a>
## Example
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-shapes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This page will discuss:
* Binding mesh buffers to shapes
* Shape groups, or combinations of several shapes

NOTE: This page will largely discuss the 2.0.0-beta1 version of the HTML 3D library, which differs considerably from the current release (version 1.5.1) of the library. (See the library's <a href="tutorial-history.md">change history</a> for more information.)
NOTE: This page will largely discuss the 2.0.0-beta3 version of the HTML 3D library, which differs considerably from the current release (version 1.5.1) of the library. (See the library's <a href="tutorial-history.md">change history</a> for more information.)

<a id=Contents></a>
## Contents
Expand Down
Loading

0 comments on commit ea65672

Please sign in to comment.