|
@@ -1,5 +1,5 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
- export class Mesh extends Node {
|
|
|
|
|
|
+ export class Mesh extends Node implements IGetSetVerticesData {
|
|
// Statics
|
|
// Statics
|
|
public static BILLBOARDMODE_NONE = 0;
|
|
public static BILLBOARDMODE_NONE = 0;
|
|
public static BILLBOARDMODE_X = 1;
|
|
public static BILLBOARDMODE_X = 1;
|
|
@@ -12,7 +12,7 @@
|
|
public rotation = new BABYLON.Vector3(0, 0, 0);
|
|
public rotation = new BABYLON.Vector3(0, 0, 0);
|
|
public rotationQuaternion = null;
|
|
public rotationQuaternion = null;
|
|
public scaling = new BABYLON.Vector3(1, 1, 1);
|
|
public scaling = new BABYLON.Vector3(1, 1, 1);
|
|
- public delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE
|
|
|
|
|
|
+ public delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
|
|
public material = null;
|
|
public material = null;
|
|
public isVisible = true;
|
|
public isVisible = true;
|
|
public isPickable = true;
|
|
public isPickable = true;
|
|
@@ -53,16 +53,13 @@
|
|
public _physicRestitution: number;
|
|
public _physicRestitution: number;
|
|
|
|
|
|
// Private
|
|
// Private
|
|
- private _boundingInfo: BoundingInfo;
|
|
|
|
- private _totalVertices = 0;
|
|
|
|
|
|
+ public _geometry: Geometry;
|
|
|
|
+ public _boundingInfo: BoundingInfo;
|
|
private _pivotMatrix = BABYLON.Matrix.Identity();
|
|
private _pivotMatrix = BABYLON.Matrix.Identity();
|
|
- private _indices = [];
|
|
|
|
private _renderId = 0;
|
|
private _renderId = 0;
|
|
private _onBeforeRenderCallbacks = [];
|
|
private _onBeforeRenderCallbacks = [];
|
|
private _delayInfo; //ANY
|
|
private _delayInfo; //ANY
|
|
private _animationStarted = false;
|
|
private _animationStarted = false;
|
|
- private _vertexBuffers;
|
|
|
|
- private _indexBuffer;
|
|
|
|
private _delayLoadingFunction: (any, Mesh) => void;
|
|
private _delayLoadingFunction: (any, Mesh) => void;
|
|
|
|
|
|
constructor(name: string, scene: Scene) {
|
|
constructor(name: string, scene: Scene) {
|
|
@@ -159,48 +156,61 @@
|
|
}
|
|
}
|
|
|
|
|
|
public getTotalVertices(): number {
|
|
public getTotalVertices(): number {
|
|
- return this._totalVertices;
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return this._geometry.getTotalVertices();
|
|
}
|
|
}
|
|
|
|
|
|
public getVerticesData(kind): number[] {
|
|
public getVerticesData(kind): number[] {
|
|
- return this._vertexBuffers[kind].getData();
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return this._geometry.getVerticesData(kind);
|
|
}
|
|
}
|
|
|
|
|
|
public getVertexBuffer(kind): VertexBuffer {
|
|
public getVertexBuffer(kind): VertexBuffer {
|
|
- return this._vertexBuffers[kind];
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return undefined;
|
|
|
|
+ }
|
|
|
|
+ return this._geometry.getVertexBuffer(kind);
|
|
}
|
|
}
|
|
|
|
|
|
public isVerticesDataPresent(kind: string): boolean {
|
|
public isVerticesDataPresent(kind: string): boolean {
|
|
- if (!this._vertexBuffers) {
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
if (this._delayInfo) {
|
|
if (this._delayInfo) {
|
|
return this._delayInfo.indexOf(kind) !== -1;
|
|
return this._delayInfo.indexOf(kind) !== -1;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- return this._vertexBuffers[kind] !== undefined;
|
|
|
|
|
|
+ return this._geometry.isVerticesDataPresent(kind);
|
|
}
|
|
}
|
|
|
|
|
|
public getVerticesDataKinds(): string[] {
|
|
public getVerticesDataKinds(): string[] {
|
|
- var result = [];
|
|
|
|
- if (!this._vertexBuffers && this._delayInfo) {
|
|
|
|
- for (var kind in this._delayInfo) {
|
|
|
|
- result.push(kind);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- for (kind in this._vertexBuffers) {
|
|
|
|
- result.push(kind);
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ var result = [];
|
|
|
|
+ if (this._delayInfo) {
|
|
|
|
+ for (var kind in this._delayInfo) {
|
|
|
|
+ result.push(kind);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
- return result;
|
|
|
|
|
|
+ return this._geometry.getVerticesDataKinds();
|
|
}
|
|
}
|
|
|
|
|
|
public getTotalIndices(): number {
|
|
public getTotalIndices(): number {
|
|
- return this._indices.length;
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return this._geometry.getTotalIndices();
|
|
}
|
|
}
|
|
|
|
|
|
public getIndices(): number[] {
|
|
public getIndices(): number[] {
|
|
- return this._indices;
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+ return this._geometry.getIndices();
|
|
}
|
|
}
|
|
|
|
|
|
public setPivotMatrix(matrix: Matrix): void {
|
|
public setPivotMatrix(matrix: Matrix): void {
|
|
@@ -279,15 +289,15 @@
|
|
public refreshBoundingInfo(): void {
|
|
public refreshBoundingInfo(): void {
|
|
var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
|
|
|
|
- if (!data) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if (data) {
|
|
|
|
+ var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
|
|
|
|
+ this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
}
|
|
}
|
|
|
|
|
|
- var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
|
|
|
|
- this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
|
|
-
|
|
|
|
- for (var index = 0; index < this.subMeshes.length; index++) {
|
|
|
|
- this.subMeshes[index].refreshBoundingInfo();
|
|
|
|
|
|
+ if (this.subMeshes) {
|
|
|
|
+ for (var index = 0; index < this.subMeshes.length; index++) {
|
|
|
|
+ this.subMeshes[index].refreshBoundingInfo();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
this._updateBoundingInfo();
|
|
this._updateBoundingInfo();
|
|
@@ -399,12 +409,13 @@
|
|
|
|
|
|
|
|
|
|
public _createGlobalSubMesh(): SubMesh {
|
|
public _createGlobalSubMesh(): SubMesh {
|
|
- if (!this._totalVertices || !this._indices) {
|
|
|
|
|
|
+ var totalVertices = this.getTotalVertices();
|
|
|
|
+ if (!totalVertices || !this.getIndices()) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
this.subMeshes = [];
|
|
this.subMeshes = [];
|
|
- return new BABYLON.SubMesh(0, 0, this._totalVertices, 0, this._indices.length, this);
|
|
|
|
|
|
+ return new BABYLON.SubMesh(0, 0, totalVertices, 0, this.getTotalIndices(), this);
|
|
}
|
|
}
|
|
|
|
|
|
public subdivide(count: number): void {
|
|
public subdivide(count: number): void {
|
|
@@ -412,85 +423,86 @@
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- var subdivisionSize = this._indices.length / count;
|
|
|
|
|
|
+ var totalIndices = this.getTotalIndices();
|
|
|
|
+ var subdivisionSize = totalIndices / count;
|
|
var offset = 0;
|
|
var offset = 0;
|
|
|
|
|
|
this.subMeshes = [];
|
|
this.subMeshes = [];
|
|
for (var index = 0; index < count; index++) {
|
|
for (var index = 0; index < count; index++) {
|
|
- BABYLON.SubMesh.CreateFromIndices(0, offset, Math.min(subdivisionSize, this._indices.length - offset), this);
|
|
|
|
|
|
+ BABYLON.SubMesh.CreateFromIndices(0, offset, Math.min(subdivisionSize, totalIndices - offset), this);
|
|
|
|
|
|
offset += subdivisionSize;
|
|
offset += subdivisionSize;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public setVerticesData(data: number[], kind: string, updatable?: boolean): void {
|
|
public setVerticesData(data: number[], kind: string, updatable?: boolean): void {
|
|
- if (!this._vertexBuffers) {
|
|
|
|
- this._vertexBuffers = {};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._vertexBuffers[kind]) {
|
|
|
|
- this._vertexBuffers[kind].dispose();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this._vertexBuffers[kind] = new BABYLON.VertexBuffer(this, data, kind, updatable);
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ var vertexData = new BABYLON.VertexData();
|
|
|
|
+ vertexData.set(data, kind);
|
|
|
|
|
|
- if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
|
- this._resetPointsArrayCache();
|
|
|
|
|
|
+ var scene = this.getScene();
|
|
|
|
|
|
- var stride = this._vertexBuffers[kind].getStrideSize();
|
|
|
|
- this._totalVertices = data.length / stride;
|
|
|
|
-
|
|
|
|
- var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
|
|
|
|
- this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
|
|
-
|
|
|
|
- this._createGlobalSubMesh();
|
|
|
|
|
|
+ new BABYLON.Geometry(Geometry.RandomId(), scene.getEngine(), vertexData, updatable, this);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._geometry.setVerticesData(data, kind, updatable);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public updateVerticesData(kind: string, data: number[], updateExtends?: boolean): void {
|
|
|
|
- if (this._vertexBuffers[kind]) {
|
|
|
|
- this._vertexBuffers[kind].update(data);
|
|
|
|
-
|
|
|
|
- if (kind === BABYLON.VertexBuffer.PositionKind) {
|
|
|
|
- this._resetPointsArrayCache();
|
|
|
|
-
|
|
|
|
- if (updateExtends) {
|
|
|
|
- var stride = this._vertexBuffers[kind].getStrideSize();
|
|
|
|
- this._totalVertices = data.length / stride;
|
|
|
|
|
|
+ public updateVerticesData(kind: string, data: number[], updateExtends?: boolean, makeItUnique?: boolean): void {
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!makeItUnique) {
|
|
|
|
+ this._geometry.updateVerticesData(kind, data, updateExtends);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this.makeGeometryUnique();
|
|
|
|
+ this.updateVerticesData(kind, data, updateExtends, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this._totalVertices);
|
|
|
|
- this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ public makeGeometryUnique() {
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ var geometry = this._geometry.copy(Geometry.RandomId());
|
|
|
|
+ geometry.applyToMesh(this);
|
|
}
|
|
}
|
|
|
|
|
|
public setIndices(indices: number[]): void {
|
|
public setIndices(indices: number[]): void {
|
|
- if (this._indexBuffer) {
|
|
|
|
- this.getScene().getEngine()._releaseBuffer(this._indexBuffer);
|
|
|
|
- }
|
|
|
|
|
|
+ if (!this._geometry) {
|
|
|
|
+ var vertexData = new BABYLON.VertexData();
|
|
|
|
+ vertexData.indices = indices;
|
|
|
|
|
|
- this._indexBuffer = this.getScene().getEngine().createIndexBuffer(indices);
|
|
|
|
- this._indices = indices;
|
|
|
|
|
|
+ var scene = this.getScene();
|
|
|
|
|
|
- this._createGlobalSubMesh();
|
|
|
|
|
|
+ new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, false, this);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._geometry.setIndices(indices);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// ANY
|
|
// ANY
|
|
public bindAndDraw(subMesh: SubMesh, effect, wireframe?: boolean): void {
|
|
public bindAndDraw(subMesh: SubMesh, effect, wireframe?: boolean): void {
|
|
|
|
+ if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
var engine = this.getScene().getEngine();
|
|
var engine = this.getScene().getEngine();
|
|
|
|
|
|
// Wireframe
|
|
// Wireframe
|
|
- var indexToBind = this._indexBuffer;
|
|
|
|
|
|
+ var indexToBind = this._geometry.getIndexBuffer();
|
|
var useTriangles = true;
|
|
var useTriangles = true;
|
|
|
|
|
|
if (wireframe) {
|
|
if (wireframe) {
|
|
- indexToBind = subMesh.getLinesIndexBuffer(this._indices, engine);
|
|
|
|
|
|
+ indexToBind = subMesh.getLinesIndexBuffer(this.getIndices(), engine);
|
|
useTriangles = false;
|
|
useTriangles = false;
|
|
}
|
|
}
|
|
|
|
|
|
// VBOs
|
|
// VBOs
|
|
- engine.bindMultiBuffers(this._vertexBuffers, indexToBind, effect);
|
|
|
|
|
|
+ engine.bindMultiBuffers(this._geometry.getVertexBuffers(), indexToBind, effect);
|
|
|
|
|
|
// Draw order
|
|
// Draw order
|
|
engine.draw(useTriangles, useTriangles ? subMesh.indexStart : 0, useTriangles ? subMesh.indexCount : subMesh.linesIndexCount);
|
|
engine.draw(useTriangles, useTriangles ? subMesh.indexStart : 0, useTriangles ? subMesh.indexCount : subMesh.linesIndexCount);
|
|
@@ -509,7 +521,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
public render(subMesh: SubMesh): void {
|
|
public render(subMesh: SubMesh): void {
|
|
- if (!this._vertexBuffers || !this._indexBuffer) {
|
|
|
|
|
|
+ if (!this._geometry || !this._geometry.getVertexBuffers() || !this._geometry.getIndexBuffer()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -582,20 +594,29 @@
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- var result = this._boundingInfo.isInFrustum(frustumPlanes);
|
|
|
|
|
|
+ if (!this._boundingInfo.isInFrustum(frustumPlanes)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- if (result && this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
|
|
|
|
- this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
|
|
|
|
- this.getScene()._addPendingData(this);
|
|
|
|
|
|
+ var that = this;
|
|
|
|
+ var scene = this.getScene();
|
|
|
|
|
|
- Tools.LoadFile(this.delayLoadingFile, data => {
|
|
|
|
- this._delayLoadingFunction(JSON.parse(data), this);
|
|
|
|
- this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
|
|
|
|
- this.getScene()._removePendingData(this);
|
|
|
|
- }, () => { }, this.getScene().database);
|
|
|
|
|
|
+ if (this._geometry) {
|
|
|
|
+ this._geometry.load(scene);
|
|
}
|
|
}
|
|
|
|
+ else if (that.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
|
|
|
|
+ that.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ scene._addPendingData(that);
|
|
|
|
+
|
|
|
|
+ BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
|
|
|
|
+ that._delayLoadingFunction(JSON.parse(data), that);
|
|
|
|
+ that.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
|
|
|
|
+ scene._removePendingData(that);
|
|
|
|
+ }, function () { }, scene.database);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
public setMaterialByID(id: string): void {
|
|
public setMaterialByID(id: string): void {
|
|
@@ -656,25 +677,25 @@
|
|
|
|
|
|
this._resetPointsArrayCache();
|
|
this._resetPointsArrayCache();
|
|
|
|
|
|
- var data = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].getData();
|
|
|
|
|
|
+ var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
var temp = [];
|
|
var temp = [];
|
|
for (var index = 0; index < data.length; index += 3) {
|
|
for (var index = 0; index < data.length; index += 3) {
|
|
BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
|
|
BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
|
|
}
|
|
}
|
|
|
|
|
|
- this.setVerticesData(temp, BABYLON.VertexBuffer.PositionKind, this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].isUpdatable());
|
|
|
|
|
|
+ this.setVerticesData(temp, BABYLON.VertexBuffer.PositionKind, this.getVertexBuffer(BABYLON.VertexBuffer.PositionKind).isUpdatable());
|
|
|
|
|
|
// Normals
|
|
// Normals
|
|
if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
|
if (!this.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- data = this._vertexBuffers[BABYLON.VertexBuffer.NormalKind].getData();
|
|
|
|
|
|
+ data = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
|
for (index = 0; index < data.length; index += 3) {
|
|
for (index = 0; index < data.length; index += 3) {
|
|
BABYLON.Vector3.TransformNormal(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
|
|
BABYLON.Vector3.TransformNormal(BABYLON.Vector3.FromArray(data, index), transform).toArray(temp, index);
|
|
}
|
|
}
|
|
|
|
|
|
- this.setVerticesData(temp, BABYLON.VertexBuffer.NormalKind, this._vertexBuffers[BABYLON.VertexBuffer.NormalKind].isUpdatable());
|
|
|
|
|
|
+ this.setVerticesData(temp, BABYLON.VertexBuffer.NormalKind, this.getVertexBuffer(BABYLON.VertexBuffer.NormalKind).isUpdatable());
|
|
}
|
|
}
|
|
|
|
|
|
public lookAt(targetPoint: Vector3, yawCor: number, pitchCor: number, rollCor: number): void {
|
|
public lookAt(targetPoint: Vector3, yawCor: number, pitchCor: number, rollCor: number): void {
|
|
@@ -707,7 +728,7 @@
|
|
|
|
|
|
this._positions = [];
|
|
this._positions = [];
|
|
|
|
|
|
- var data = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind].getData();
|
|
|
|
|
|
+ var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
for (var index = 0; index < data.length; index += 3) {
|
|
for (var index = 0; index < data.length; index += 3) {
|
|
this._positions.push(BABYLON.Vector3.FromArray(data, index));
|
|
this._positions.push(BABYLON.Vector3.FromArray(data, index));
|
|
}
|
|
}
|
|
@@ -728,7 +749,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Collide
|
|
// Collide
|
|
- collider._collide(subMesh, subMesh._lastColliderWorldVertices, this._indices, subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart);
|
|
|
|
|
|
+ collider._collide(subMesh, subMesh._lastColliderWorldVertices, this.getIndices(), subMesh.indexStart, subMesh.indexStart + subMesh.indexCount, subMesh.verticesStart);
|
|
}
|
|
}
|
|
|
|
|
|
public _processCollisionsForSubModels(collider: Collider, transformMatrix: Matrix): void {
|
|
public _processCollisionsForSubModels(collider: Collider, transformMatrix: Matrix): void {
|
|
@@ -790,7 +811,7 @@
|
|
if (this.subMeshes.length > 1 && !subMesh.canIntersects(ray))
|
|
if (this.subMeshes.length > 1 && !subMesh.canIntersects(ray))
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- var currentIntersectInfo = subMesh.intersects(ray, this._positions, this._indices, fastCheck);
|
|
|
|
|
|
+ var currentIntersectInfo = subMesh.intersects(ray, this._positions, this.getIndices(), fastCheck);
|
|
|
|
|
|
if (currentIntersectInfo) {
|
|
if (currentIntersectInfo) {
|
|
if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
|
|
if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
|
|
@@ -832,20 +853,14 @@
|
|
public clone(name: string, newParent: Node, doNotCloneChildren?: boolean): Mesh {
|
|
public clone(name: string, newParent: Node, doNotCloneChildren?: boolean): Mesh {
|
|
var result = new BABYLON.Mesh(name, this.getScene());
|
|
var result = new BABYLON.Mesh(name, this.getScene());
|
|
|
|
|
|
- // Buffers
|
|
|
|
- result._vertexBuffers = this._vertexBuffers;
|
|
|
|
- for (var kind in result._vertexBuffers) {
|
|
|
|
- result._vertexBuffers[kind]._buffer.references++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- result._indexBuffer = this._indexBuffer;
|
|
|
|
- this._indexBuffer.references++;
|
|
|
|
|
|
+ // Geometry
|
|
|
|
+ this._geometry.applyToMesh(result);
|
|
|
|
|
|
// Deep copy
|
|
// Deep copy
|
|
- BABYLON.Tools.DeepCopy(this, result, ["name", "material", "skeleton"], ["_indices", "_totalVertices"]);
|
|
|
|
|
|
+ BABYLON.Tools.DeepCopy(this, result, ["name", "material", "skeleton"], []);
|
|
|
|
|
|
// Bounding info
|
|
// Bounding info
|
|
- var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this._totalVertices);
|
|
|
|
|
|
+ var extend = BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind), 0, this.getTotalVertices());
|
|
result._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
result._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
|
|
|
|
|
|
// Material
|
|
// Material
|
|
@@ -883,16 +898,8 @@
|
|
|
|
|
|
// Dispose
|
|
// Dispose
|
|
public dispose(doNotRecurse?: boolean): void {
|
|
public dispose(doNotRecurse?: boolean): void {
|
|
- if (this._vertexBuffers) {
|
|
|
|
- for (var vbKind in this._vertexBuffers) {
|
|
|
|
- this._vertexBuffers[vbKind].dispose();
|
|
|
|
- }
|
|
|
|
- this._vertexBuffers = null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this._indexBuffer) {
|
|
|
|
- this.getScene().getEngine()._releaseBuffer(this._indexBuffer);
|
|
|
|
- this._indexBuffer = null;
|
|
|
|
|
|
+ if (this._geometry) {
|
|
|
|
+ this._geometry.releaseForMesh(this);
|
|
}
|
|
}
|
|
|
|
|
|
// Physics
|
|
// Physics
|
|
@@ -1032,15 +1039,16 @@
|
|
var updatableNormals = false;
|
|
var updatableNormals = false;
|
|
for (var kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
|
|
for (var kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
|
|
var kind = kinds[kindIndex];
|
|
var kind = kinds[kindIndex];
|
|
|
|
+ var vertexBuffer = this.getVertexBuffer(kind);
|
|
|
|
|
|
if (kind === BABYLON.VertexBuffer.NormalKind) {
|
|
if (kind === BABYLON.VertexBuffer.NormalKind) {
|
|
- updatableNormals = this.getVertexBuffer(kind).isUpdatable();
|
|
|
|
|
|
+ updatableNormals = vertexBuffer.isUpdatable();
|
|
kinds.splice(kindIndex, 1);
|
|
kinds.splice(kindIndex, 1);
|
|
kindIndex--;
|
|
kindIndex--;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- vbs[kind] = this.getVertexBuffer(kind);
|
|
|
|
|
|
+ vbs[kind] = vertexBuffer;
|
|
data[kind] = vbs[kind].getData();
|
|
data[kind] = vbs[kind].getData();
|
|
newdata[kind] = [];
|
|
newdata[kind] = [];
|
|
}
|
|
}
|
|
@@ -1049,9 +1057,10 @@
|
|
var previousSubmeshes = this.subMeshes.slice(0);
|
|
var previousSubmeshes = this.subMeshes.slice(0);
|
|
|
|
|
|
var indices = this.getIndices();
|
|
var indices = this.getIndices();
|
|
|
|
+ var totalIndices = this.getTotalIndices();
|
|
|
|
|
|
// Generating unique vertices per face
|
|
// Generating unique vertices per face
|
|
- for (index = 0; index < indices.length; index++) {
|
|
|
|
|
|
+ for (index = 0; index < totalIndices; index++) {
|
|
var vertexIndex = indices[index];
|
|
var vertexIndex = indices[index];
|
|
|
|
|
|
for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
|
|
for (kindIndex = 0; kindIndex < kinds.length; kindIndex++) {
|
|
@@ -1067,7 +1076,7 @@
|
|
// Updating faces & normal
|
|
// Updating faces & normal
|
|
var normals = [];
|
|
var normals = [];
|
|
var positions = newdata[BABYLON.VertexBuffer.PositionKind];
|
|
var positions = newdata[BABYLON.VertexBuffer.PositionKind];
|
|
- for (var index = 0; index < indices.length; index += 3) {
|
|
|
|
|
|
+ for (var index = 0; index < totalIndices; index += 3) {
|
|
indices[index] = index;
|
|
indices[index] = index;
|
|
indices[index + 1] = index + 1;
|
|
indices[index + 1] = index + 1;
|
|
indices[index + 2] = index + 2;
|
|
indices[index + 2] = index + 2;
|