|
@@ -1,14 +1,25 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
|
|
+ /**
|
|
|
|
+ * Base class for submeshes
|
|
|
|
+ */
|
|
export class BaseSubMesh {
|
|
export class BaseSubMesh {
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _materialDefines: Nullable<MaterialDefines>;
|
|
public _materialDefines: Nullable<MaterialDefines>;
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _materialEffect: Nullable<Effect>;
|
|
public _materialEffect: Nullable<Effect>;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets associated effect
|
|
|
|
+ */
|
|
public get effect(): Nullable<Effect> {
|
|
public get effect(): Nullable<Effect> {
|
|
return this._materialEffect;
|
|
return this._materialEffect;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets associated effect (effect used to render this submesh)
|
|
|
|
+ * @param effect defines the effect to associate with
|
|
|
|
+ * @param defines defines the set of defines used to compile this effect
|
|
|
|
+ */
|
|
public setEffect(effect: Nullable<Effect>, defines: Nullable<MaterialDefines> = null) {
|
|
public setEffect(effect: Nullable<Effect>, defines: Nullable<MaterialDefines> = null) {
|
|
if (this._materialEffect === effect) {
|
|
if (this._materialEffect === effect) {
|
|
if (!effect) {
|
|
if (!effect) {
|
|
@@ -21,9 +32,12 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Defines a subdivision inside a mesh
|
|
|
|
+ */
|
|
export class SubMesh extends BaseSubMesh implements ICullable {
|
|
export class SubMesh extends BaseSubMesh implements ICullable {
|
|
- public linesIndexCount: number;
|
|
|
|
-
|
|
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public _linesIndexCount: number;
|
|
private _mesh: AbstractMesh;
|
|
private _mesh: AbstractMesh;
|
|
private _renderingMesh: Mesh;
|
|
private _renderingMesh: Mesh;
|
|
private _boundingInfo: BoundingInfo;
|
|
private _boundingInfo: BoundingInfo;
|
|
@@ -46,11 +60,44 @@
|
|
|
|
|
|
private _currentMaterial: Nullable<Material>;
|
|
private _currentMaterial: Nullable<Material>;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Add a new submesh to a mesh
|
|
|
|
+ * @param materialIndex defines the material index to use
|
|
|
|
+ * @param verticesStart defines vertex index start
|
|
|
|
+ * @param verticesCount defines vertices count
|
|
|
|
+ * @param indexStart defines index start
|
|
|
|
+ * @param indexCount defines indices count
|
|
|
|
+ * @param mesh defines the parent mesh
|
|
|
|
+ * @param renderingMesh defines an optional rendering mesh
|
|
|
|
+ * @param createBoundingBox defines if bounding box should be created for this submesh
|
|
|
|
+ * @returns the new submesh
|
|
|
|
+ */
|
|
public static AddToMesh(materialIndex: number, verticesStart: number, verticesCount: number, indexStart: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true): SubMesh {
|
|
public static AddToMesh(materialIndex: number, verticesStart: number, verticesCount: number, indexStart: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true): SubMesh {
|
|
return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);
|
|
return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);
|
|
}
|
|
}
|
|
|
|
|
|
- constructor(public materialIndex: number, public verticesStart: number, public verticesCount: number, public indexStart: number, public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Creates a new submesh
|
|
|
|
+ * @param materialIndex defines the material index to use
|
|
|
|
+ * @param verticesStart defines vertex index start
|
|
|
|
+ * @param verticesCount defines vertices count
|
|
|
|
+ * @param indexStart defines index start
|
|
|
|
+ * @param indexCount defines indices count
|
|
|
|
+ * @param mesh defines the parent mesh
|
|
|
|
+ * @param renderingMesh defines an optional rendering mesh
|
|
|
|
+ * @param createBoundingBox defines if bounding box should be created for this submesh
|
|
|
|
+ */
|
|
|
|
+ constructor(
|
|
|
|
+ /** the material index to use */
|
|
|
|
+ public materialIndex: number,
|
|
|
|
+ /** vertex index start */
|
|
|
|
+ public verticesStart: number,
|
|
|
|
+ /** vertices count */
|
|
|
|
+ public verticesCount: number,
|
|
|
|
+ /** index start */
|
|
|
|
+ public indexStart: number,
|
|
|
|
+ /** indices count */
|
|
|
|
+ public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true) {
|
|
super();
|
|
super();
|
|
this._mesh = mesh;
|
|
this._mesh = mesh;
|
|
this._renderingMesh = renderingMesh || <Mesh>mesh;
|
|
this._renderingMesh = renderingMesh || <Mesh>mesh;
|
|
@@ -66,12 +113,17 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns true if this submesh covers the entire parent mesh
|
|
|
|
+ * @ignorenaming
|
|
|
|
+ */
|
|
public get IsGlobal(): boolean {
|
|
public get IsGlobal(): boolean {
|
|
return (this.verticesStart === 0 && this.verticesCount === this._mesh.getTotalVertices());
|
|
return (this.verticesStart === 0 && this.verticesCount === this._mesh.getTotalVertices());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the submesh BoudingInfo object.
|
|
|
|
|
|
+ * Returns the submesh BoudingInfo object
|
|
|
|
+ * @returns current bounding info (or mesh's one if the submesh is global)
|
|
*/
|
|
*/
|
|
public getBoundingInfo(): BoundingInfo {
|
|
public getBoundingInfo(): BoundingInfo {
|
|
if (this.IsGlobal) {
|
|
if (this.IsGlobal) {
|
|
@@ -82,8 +134,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Sets the submesh BoundingInfo.
|
|
|
|
- * Return the SubMesh.
|
|
|
|
|
|
+ * Sets the submesh BoundingInfo
|
|
|
|
+ * @param boundingInfo defines the new bounding info to use
|
|
|
|
+ * @returns the SubMesh
|
|
*/
|
|
*/
|
|
public setBoundingInfo(boundingInfo: BoundingInfo): SubMesh {
|
|
public setBoundingInfo(boundingInfo: BoundingInfo): SubMesh {
|
|
this._boundingInfo = boundingInfo;
|
|
this._boundingInfo = boundingInfo;
|
|
@@ -91,21 +144,24 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the mesh of the current submesh.
|
|
|
|
|
|
+ * Returns the mesh of the current submesh
|
|
|
|
+ * @return the parent mesh
|
|
*/
|
|
*/
|
|
public getMesh(): AbstractMesh {
|
|
public getMesh(): AbstractMesh {
|
|
return this._mesh;
|
|
return this._mesh;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the rendering mesh of the submesh.
|
|
|
|
|
|
+ * Returns the rendering mesh of the submesh
|
|
|
|
+ * @returns the rendering mesh (could be different from parent mesh)
|
|
*/
|
|
*/
|
|
public getRenderingMesh(): Mesh {
|
|
public getRenderingMesh(): Mesh {
|
|
return this._renderingMesh;
|
|
return this._renderingMesh;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns the submesh material.
|
|
|
|
|
|
+ * Returns the submesh material
|
|
|
|
+ * @returns null or the current material
|
|
*/
|
|
*/
|
|
public getMaterial(): Nullable<Material> {
|
|
public getMaterial(): Nullable<Material> {
|
|
var rootMaterial = this._renderingMesh.material;
|
|
var rootMaterial = this._renderingMesh.material;
|
|
@@ -128,9 +184,10 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Methods
|
|
// Methods
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Sets a new updated BoundingInfo object to the submesh.
|
|
|
|
- * Returns the SubMesh.
|
|
|
|
|
|
+ * Sets a new updated BoundingInfo object to the submesh
|
|
|
|
+ * @returns the SubMesh
|
|
*/
|
|
*/
|
|
public refreshBoundingInfo(): SubMesh {
|
|
public refreshBoundingInfo(): SubMesh {
|
|
this._lastColliderWorldVertices = null;
|
|
this._lastColliderWorldVertices = null;
|
|
@@ -169,8 +226,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Updates the submesh BoundingInfo.
|
|
|
|
- * Returns the Submesh.
|
|
|
|
|
|
+ * Updates the submesh BoundingInfo
|
|
|
|
+ * @param world defines the world matrix to use to update the bounding info
|
|
|
|
+ * @returns the submesh
|
|
*/
|
|
*/
|
|
public updateBoundingInfo(world: Matrix): SubMesh {
|
|
public updateBoundingInfo(world: Matrix): SubMesh {
|
|
let boundingInfo = this.getBoundingInfo();
|
|
let boundingInfo = this.getBoundingInfo();
|
|
@@ -185,7 +243,8 @@
|
|
|
|
|
|
/**
|
|
/**
|
|
* True is the submesh bounding box intersects the frustum defined by the passed array of planes.
|
|
* True is the submesh bounding box intersects the frustum defined by the passed array of planes.
|
|
- * Boolean returned.
|
|
|
|
|
|
+ * @param frustumPlanes defines the frustum planes
|
|
|
|
+ * @returns true if the submesh is intersecting with the frustum
|
|
*/
|
|
*/
|
|
public isInFrustum(frustumPlanes: Plane[]): boolean {
|
|
public isInFrustum(frustumPlanes: Plane[]): boolean {
|
|
let boundingInfo = this.getBoundingInfo();
|
|
let boundingInfo = this.getBoundingInfo();
|
|
@@ -197,8 +256,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes.
|
|
|
|
- * Boolean returned.
|
|
|
|
|
|
+ * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes
|
|
|
|
+ * @param frustumPlanes defines the frustum planes
|
|
|
|
+ * @returns true if the submesh is inside the frustum
|
|
*/
|
|
*/
|
|
public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {
|
|
public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {
|
|
let boundingInfo = this.getBoundingInfo();
|
|
let boundingInfo = this.getBoundingInfo();
|
|
@@ -210,8 +270,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Renders the submesh.
|
|
|
|
- * Returns it.
|
|
|
|
|
|
+ * Renders the submesh
|
|
|
|
+ * @param enableAlphaMode defines if alpha needs to be used
|
|
|
|
+ * @returns the submesh
|
|
*/
|
|
*/
|
|
public render(enableAlphaMode: boolean): SubMesh {
|
|
public render(enableAlphaMode: boolean): SubMesh {
|
|
this._renderingMesh.render(this, enableAlphaMode);
|
|
this._renderingMesh.render(this, enableAlphaMode);
|
|
@@ -219,10 +280,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns a new Index Buffer.
|
|
|
|
- * Type returned : WebGLBuffer.
|
|
|
|
|
|
+ * @hidden
|
|
*/
|
|
*/
|
|
- public getLinesIndexBuffer(indices: IndicesArray, engine: Engine): WebGLBuffer {
|
|
|
|
|
|
+ public _getLinesIndexBuffer(indices: IndicesArray, engine: Engine): WebGLBuffer {
|
|
if (!this._linesIndexBuffer) {
|
|
if (!this._linesIndexBuffer) {
|
|
var linesIndices = [];
|
|
var linesIndices = [];
|
|
|
|
|
|
@@ -233,14 +293,15 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);
|
|
this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);
|
|
- this.linesIndexCount = linesIndices.length;
|
|
|
|
|
|
+ this._linesIndexCount = linesIndices.length;
|
|
}
|
|
}
|
|
return this._linesIndexBuffer;
|
|
return this._linesIndexBuffer;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * True is the passed Ray intersects the submesh bounding box.
|
|
|
|
- * Boolean returned.
|
|
|
|
|
|
+ * Checks if the submesh intersects with a ray
|
|
|
|
+ * @param ray defines the ray to test
|
|
|
|
+ * @returns true is the passed ray intersects the submesh bounding box
|
|
*/
|
|
*/
|
|
public canIntersects(ray: Ray): boolean {
|
|
public canIntersects(ray: Ray): boolean {
|
|
let boundingInfo = this.getBoundingInfo();
|
|
let boundingInfo = this.getBoundingInfo();
|
|
@@ -252,7 +313,12 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns an object IntersectionInfo.
|
|
|
|
|
|
+ * Intersects current submesh with a ray
|
|
|
|
+ * @param ray defines the ray to test
|
|
|
|
+ * @param positions defines mesh's positions array
|
|
|
|
+ * @param indices defines mesh's indices array
|
|
|
|
+ * @param fastCheck defines if only bounding info should be used
|
|
|
|
+ * @returns intersection info or null if no intersection
|
|
*/
|
|
*/
|
|
public intersects(ray: Ray, positions: Vector3[], indices: IndicesArray, fastCheck?: boolean): Nullable<IntersectionInfo> {
|
|
public intersects(ray: Ray, positions: Vector3[], indices: IndicesArray, fastCheck?: boolean): Nullable<IntersectionInfo> {
|
|
var intersectInfo: Nullable<IntersectionInfo> = null;
|
|
var intersectInfo: Nullable<IntersectionInfo> = null;
|
|
@@ -333,7 +399,10 @@
|
|
|
|
|
|
// Clone
|
|
// Clone
|
|
/**
|
|
/**
|
|
- * Creates a new Submesh from the passed Mesh.
|
|
|
|
|
|
+ * Creates a new submesh from the passed mesh
|
|
|
|
+ * @param newMesh defines the new hosting mesh
|
|
|
|
+ * @param newRenderingMesh defines an optional rendering mesh
|
|
|
|
+ * @returns the new submesh
|
|
*/
|
|
*/
|
|
public clone(newMesh: AbstractMesh, newRenderingMesh?: Mesh): SubMesh {
|
|
public clone(newMesh: AbstractMesh, newRenderingMesh?: Mesh): SubMesh {
|
|
var result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);
|
|
var result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);
|
|
@@ -352,9 +421,9 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Dispose
|
|
// Dispose
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Disposes the Submesh.
|
|
|
|
- * Returns nothing.
|
|
|
|
|
|
+ * Release associated resources
|
|
*/
|
|
*/
|
|
public dispose(): void {
|
|
public dispose(): void {
|
|
if (this._linesIndexBuffer) {
|
|
if (this._linesIndexBuffer) {
|
|
@@ -369,12 +438,13 @@
|
|
|
|
|
|
// Statics
|
|
// Statics
|
|
/**
|
|
/**
|
|
- * Creates a new Submesh from the passed parameters :
|
|
|
|
- * - materialIndex (integer) : the index of the main mesh material.
|
|
|
|
- * - startIndex (integer) : the index where to start the copy in the mesh indices array.
|
|
|
|
- * - indexCount (integer) : the number of indices to copy then from the startIndex.
|
|
|
|
- * - mesh (Mesh) : the main mesh to create the submesh from.
|
|
|
|
- * - renderingMesh (optional Mesh) : rendering mesh.
|
|
|
|
|
|
+ * Creates a new submesh from indices data
|
|
|
|
+ * @param materialIndex the index of the main mesh material
|
|
|
|
+ * @param startIndex the index where to start the copy in the mesh indices array
|
|
|
|
+ * @param indexCount the number of indices to copy then from the startIndex
|
|
|
|
+ * @param mesh the main mesh to create the submesh from
|
|
|
|
+ * @param renderingMesh the optional rendering mesh
|
|
|
|
+ * @returns a new submesh
|
|
*/
|
|
*/
|
|
public static CreateFromIndices(materialIndex: number, startIndex: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh): SubMesh {
|
|
public static CreateFromIndices(materialIndex: number, startIndex: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh): SubMesh {
|
|
var minVertexIndex = Number.MAX_VALUE;
|
|
var minVertexIndex = Number.MAX_VALUE;
|