|
@@ -1,6 +1,5 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
- export interface IGetSetVerticesData
|
|
|
|
- {
|
|
|
|
|
|
+ export interface IGetSetVerticesData {
|
|
isVerticesDataPresent(kind: string): boolean;
|
|
isVerticesDataPresent(kind: string): boolean;
|
|
getVerticesData(kind: string, copyWhenShared?: boolean, forceCopy?: boolean): Nullable<FloatArray>;
|
|
getVerticesData(kind: string, copyWhenShared?: boolean, forceCopy?: boolean): Nullable<FloatArray>;
|
|
getIndices(copyWhenShared?: boolean): Nullable<IndicesArray>;
|
|
getIndices(copyWhenShared?: boolean): Nullable<IndicesArray>;
|
|
@@ -346,7 +345,7 @@
|
|
if (length === 0 || length === other.length) {
|
|
if (length === 0 || length === other.length) {
|
|
return other;
|
|
return other;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
var padding = new Float32Array(length - other.length);
|
|
var padding = new Float32Array(length - other.length);
|
|
padding.fill(defaultValue);
|
|
padding.fill(defaultValue);
|
|
return this._mergeElement(padding, other, length);
|
|
return this._mergeElement(padding, other, length);
|
|
@@ -744,7 +743,7 @@
|
|
var positions32 = new Float32Array(positions);
|
|
var positions32 = new Float32Array(positions);
|
|
var normals32 = new Float32Array(normals);
|
|
var normals32 = new Float32Array(normals);
|
|
var uvs32 = new Float32Array(uvs);
|
|
var uvs32 = new Float32Array(uvs);
|
|
-
|
|
|
|
|
|
+
|
|
vertexData.indices = indices;
|
|
vertexData.indices = indices;
|
|
vertexData.positions = positions32;
|
|
vertexData.positions = positions32;
|
|
vertexData.normals = normals32;
|
|
vertexData.normals = normals32;
|
|
@@ -1401,10 +1400,10 @@
|
|
* Creates the VertexData of the TiledGround.
|
|
* Creates the VertexData of the TiledGround.
|
|
*/
|
|
*/
|
|
public static CreateTiledGround(options: { xmin: number, zmin: number, xmax: number, zmax: number, subdivisions?: { w: number; h: number; }, precision?: { w: number; h: number; } }): VertexData {
|
|
public static CreateTiledGround(options: { xmin: number, zmin: number, xmax: number, zmax: number, subdivisions?: { w: number; h: number; }, precision?: { w: number; h: number; } }): VertexData {
|
|
- var xmin = typeof options.xmin === 'number' ? options.xmin : -1.0;
|
|
|
|
- var zmin = typeof options.zmin === 'number' ? options.zmin : -1.0;
|
|
|
|
- var xmax = typeof options.xmax === 'number' ? options.xmax : 1.0;
|
|
|
|
- var zmax = typeof options.zmax === 'number' ? options.zmax : 1.0;
|
|
|
|
|
|
+ var xmin = (options.xmin !== undefined && options.xmin !== null) ? options.xmin : -1.0;
|
|
|
|
+ var zmin = (options.zmin !== undefined && options.zmin !== null) ? options.zmin : -1.0;
|
|
|
|
+ var xmax = (options.xmax !== undefined && options.xmax !== null) ? options.xmax : 1.0;
|
|
|
|
+ var zmax = (options.zmax !== undefined && options.zmax !== null) ? options.zmax : 1.0;
|
|
var subdivisions = options.subdivisions || { w: 1, h: 1 };
|
|
var subdivisions = options.subdivisions || { w: 1, h: 1 };
|
|
var precision = options.precision || { w: 1, h: 1 };
|
|
var precision = options.precision || { w: 1, h: 1 };
|
|
|
|
|
|
@@ -1494,7 +1493,7 @@
|
|
var uvs = [];
|
|
var uvs = [];
|
|
var row, col;
|
|
var row, col;
|
|
var filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);
|
|
var filter = options.colorFilter || new Color3(0.3, 0.59, 0.11);
|
|
-
|
|
|
|
|
|
+
|
|
// Vertices
|
|
// Vertices
|
|
for (row = 0; row <= options.subdivisions; row++) {
|
|
for (row = 0; row <= options.subdivisions; row++) {
|
|
for (col = 0; col <= options.subdivisions; col++) {
|
|
for (col = 0; col <= options.subdivisions; col++) {
|
|
@@ -1659,8 +1658,8 @@
|
|
/**
|
|
/**
|
|
* Re-creates the VertexData of the Polygon for sideOrientation.
|
|
* Re-creates the VertexData of the Polygon for sideOrientation.
|
|
*/
|
|
*/
|
|
- public static CreatePolygon(polygon: Mesh, sideOrientation: number, fUV?:Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4) {
|
|
|
|
- var faceUV: Vector4[] = fUV || new Array<Vector4>(3);
|
|
|
|
|
|
+ public static CreatePolygon(polygon: Mesh, sideOrientation: number, fUV?: Vector4[], fColors?: Color4[], frontUVs?: Vector4, backUVs?: Vector4) {
|
|
|
|
+ var faceUV: Vector4[] = fUV || new Array<Vector4>(3);
|
|
var faceColors = fColors;
|
|
var faceColors = fColors;
|
|
var colors = [];
|
|
var colors = [];
|
|
|
|
|
|
@@ -1673,39 +1672,39 @@
|
|
faceColors[f] = new Color4(1, 1, 1, 1);
|
|
faceColors[f] = new Color4(1, 1, 1, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
var positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);
|
|
var positions = <FloatArray>polygon.getVerticesData(VertexBuffer.PositionKind);
|
|
- var normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);
|
|
|
|
- var uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);
|
|
|
|
|
|
+ var normals = <FloatArray>polygon.getVerticesData(VertexBuffer.NormalKind);
|
|
|
|
+ var uvs = <FloatArray>polygon.getVerticesData(VertexBuffer.UVKind);
|
|
var indices = <IndicesArray>polygon.getIndices();
|
|
var indices = <IndicesArray>polygon.getIndices();
|
|
-
|
|
|
|
|
|
+
|
|
// set face colours and textures
|
|
// set face colours and textures
|
|
var idx: number = 0;
|
|
var idx: number = 0;
|
|
var face: number = 0;
|
|
var face: number = 0;
|
|
- for (var index = 0; index < normals.length; index += 3) {
|
|
|
|
|
|
+ for (var index = 0; index < normals.length; index += 3) {
|
|
//Edge Face no. 1
|
|
//Edge Face no. 1
|
|
- if(Math.abs(normals[index + 1]) < 0.001) {
|
|
|
|
- face = 1;
|
|
|
|
|
|
+ if (Math.abs(normals[index + 1]) < 0.001) {
|
|
|
|
+ face = 1;
|
|
}
|
|
}
|
|
//Top Face no. 0
|
|
//Top Face no. 0
|
|
- if(Math.abs(normals[index + 1] - 1) < 0.001 ) {
|
|
|
|
- face = 0;
|
|
|
|
|
|
+ if (Math.abs(normals[index + 1] - 1) < 0.001) {
|
|
|
|
+ face = 0;
|
|
}
|
|
}
|
|
//Bottom Face no. 2
|
|
//Bottom Face no. 2
|
|
- if(Math.abs(normals[index + 1] + 1) < 0.001 ) {
|
|
|
|
- face = 2;
|
|
|
|
|
|
+ if (Math.abs(normals[index + 1] + 1) < 0.001) {
|
|
|
|
+ face = 2;
|
|
}
|
|
}
|
|
idx = index / 3;
|
|
idx = index / 3;
|
|
- uvs[2*idx] = (1 - uvs[2*idx])*faceUV[face].x + uvs[2*idx]*faceUV[face].z;
|
|
|
|
- uvs[2*idx + 1] = (1 - uvs[2*idx + 1])*faceUV[face].y + uvs[2*idx + 1]*faceUV[face].w;
|
|
|
|
|
|
+ uvs[2 * idx] = (1 - uvs[2 * idx]) * faceUV[face].x + uvs[2 * idx] * faceUV[face].z;
|
|
|
|
+ uvs[2 * idx + 1] = (1 - uvs[2 * idx + 1]) * faceUV[face].y + uvs[2 * idx + 1] * faceUV[face].w;
|
|
if (faceColors) {
|
|
if (faceColors) {
|
|
colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);
|
|
colors.push(faceColors[face].r, faceColors[face].g, faceColors[face].b, faceColors[face].a);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // sides
|
|
|
|
|
|
+ // sides
|
|
VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);
|
|
VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, frontUVs, backUVs);
|
|
-
|
|
|
|
|
|
+
|
|
// Result
|
|
// Result
|
|
var vertexData = new VertexData();
|
|
var vertexData = new VertexData();
|
|
vertexData.indices = indices;
|
|
vertexData.indices = indices;
|
|
@@ -1719,8 +1718,8 @@
|
|
}
|
|
}
|
|
|
|
|
|
return vertexData;
|
|
return vertexData;
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates the VertexData of the IcoSphere.
|
|
* Creates the VertexData of the IcoSphere.
|
|
@@ -2234,8 +2233,10 @@
|
|
* depthSortedFacets : optional array of depthSortedFacets to store the facet distances from the reference location
|
|
* depthSortedFacets : optional array of depthSortedFacets to store the facet distances from the reference location
|
|
*/
|
|
*/
|
|
public static ComputeNormals(positions: any, indices: any, normals: any,
|
|
public static ComputeNormals(positions: any, indices: any, normals: any,
|
|
- options?: { facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any,
|
|
|
|
- useRightHandedSystem?: boolean, depthSort?: boolean, distanceTo?: Vector3, depthSortedFacets?: any }): void {
|
|
|
|
|
|
+ options?: {
|
|
|
|
+ facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any,
|
|
|
|
+ useRightHandedSystem?: boolean, depthSort?: boolean, distanceTo?: Vector3, depthSortedFacets?: any
|
|
|
|
+ }): void {
|
|
|
|
|
|
// temporary scalar variables
|
|
// temporary scalar variables
|
|
var index = 0; // facet index
|
|
var index = 0; // facet index
|
|
@@ -2276,7 +2277,7 @@
|
|
if (computeDepthSort) {
|
|
if (computeDepthSort) {
|
|
if (distanceTo === undefined) {
|
|
if (distanceTo === undefined) {
|
|
distanceTo = Vector3.Zero();
|
|
distanceTo = Vector3.Zero();
|
|
- }
|
|
|
|
|
|
+ }
|
|
var depthSortedFacets = options.depthSortedFacets;
|
|
var depthSortedFacets = options.depthSortedFacets;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2319,7 +2320,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Loop : 1 indice triplet = 1 facet
|
|
// Loop : 1 indice triplet = 1 facet
|
|
- var nbFaces = (indices.length / 3)|0;
|
|
|
|
|
|
+ var nbFaces = (indices.length / 3) | 0;
|
|
for (index = 0; index < nbFaces; index++) {
|
|
for (index = 0; index < nbFaces; index++) {
|
|
|
|
|
|
// get the indexes of the coordinates of each vertex of the facet
|
|
// get the indexes of the coordinates of each vertex of the facet
|
|
@@ -2386,10 +2387,10 @@
|
|
block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;
|
|
block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;
|
|
block_idx_o = ox + options.subDiv.max * oy + subSq * oz;
|
|
block_idx_o = ox + options.subDiv.max * oy + subSq * oz;
|
|
|
|
|
|
- options.facetPartitioning[block_idx_o] = options.facetPartitioning[block_idx_o] ? options.facetPartitioning[block_idx_o] :new Array();
|
|
|
|
- options.facetPartitioning[block_idx_v1] = options.facetPartitioning[block_idx_v1] ? options.facetPartitioning[block_idx_v1] :new Array();
|
|
|
|
- options.facetPartitioning[block_idx_v2] = options.facetPartitioning[block_idx_v2] ? options.facetPartitioning[block_idx_v2] :new Array();
|
|
|
|
- options.facetPartitioning[block_idx_v3] = options.facetPartitioning[block_idx_v3] ? options.facetPartitioning[block_idx_v3] :new Array();
|
|
|
|
|
|
+ options.facetPartitioning[block_idx_o] = options.facetPartitioning[block_idx_o] ? options.facetPartitioning[block_idx_o] : new Array();
|
|
|
|
+ options.facetPartitioning[block_idx_v1] = options.facetPartitioning[block_idx_v1] ? options.facetPartitioning[block_idx_v1] : new Array();
|
|
|
|
+ options.facetPartitioning[block_idx_v2] = options.facetPartitioning[block_idx_v2] ? options.facetPartitioning[block_idx_v2] : new Array();
|
|
|
|
+ options.facetPartitioning[block_idx_v3] = options.facetPartitioning[block_idx_v3] ? options.facetPartitioning[block_idx_v3] : new Array();
|
|
|
|
|
|
// push each facet index in each block containing the vertex
|
|
// push each facet index in each block containing the vertex
|
|
options.facetPartitioning[block_idx_v1].push(index);
|
|
options.facetPartitioning[block_idx_v1].push(index);
|
|
@@ -2488,12 +2489,12 @@
|
|
var lu: number = uvs.length;
|
|
var lu: number = uvs.length;
|
|
var u: number = 0;
|
|
var u: number = 0;
|
|
for (u = 0; u < lu; u++) {
|
|
for (u = 0; u < lu; u++) {
|
|
- uvs[u + lu] = uvs[u];
|
|
|
|
|
|
+ uvs[u + lu] = uvs[u];
|
|
}
|
|
}
|
|
frontUVs = frontUVs ? frontUVs : new Vector4(0.0, 0.0, 1.0, 1.0);
|
|
frontUVs = frontUVs ? frontUVs : new Vector4(0.0, 0.0, 1.0, 1.0);
|
|
- backUVs = backUVs ? backUVs : new Vector4(0.0, 0.0, 1.0, 1.0);
|
|
|
|
|
|
+ backUVs = backUVs ? backUVs : new Vector4(0.0, 0.0, 1.0, 1.0);
|
|
u = 0;
|
|
u = 0;
|
|
- for (i = 0; i < lu / 2; i++) {
|
|
|
|
|
|
+ for (i = 0; i < lu / 2; i++) {
|
|
uvs[u] = frontUVs.x + (frontUVs.z - frontUVs.x) * uvs[u];
|
|
uvs[u] = frontUVs.x + (frontUVs.z - frontUVs.x) * uvs[u];
|
|
uvs[u + 1] = frontUVs.y + (frontUVs.w - frontUVs.y) * uvs[u + 1];
|
|
uvs[u + 1] = frontUVs.y + (frontUVs.w - frontUVs.y) * uvs[u + 1];
|
|
uvs[u + lu] = backUVs.x + (backUVs.z - backUVs.x) * uvs[u + lu];
|
|
uvs[u + lu] = backUVs.x + (backUVs.z - backUVs.x) * uvs[u + lu];
|