|
@@ -7227,24 +7227,37 @@ var BABYLON;
|
|
this.subMeshId = 0;
|
|
this.subMeshId = 0;
|
|
}
|
|
}
|
|
// Methods
|
|
// Methods
|
|
- PickingInfo.prototype.getNormal = function (useWorldCoordinates) {
|
|
|
|
|
|
+ PickingInfo.prototype.getNormal = function (useWorldCoordinates, useVerticesNormals) {
|
|
if (useWorldCoordinates === void 0) { useWorldCoordinates = false; }
|
|
if (useWorldCoordinates === void 0) { useWorldCoordinates = false; }
|
|
|
|
+ if (useVerticesNormals === void 0) { useVerticesNormals = true; }
|
|
if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
|
if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
var indices = this.pickedMesh.getIndices();
|
|
var indices = this.pickedMesh.getIndices();
|
|
- var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
|
|
|
- var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
|
|
|
|
- var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
|
|
|
|
- var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
|
|
|
|
- normal0 = normal0.scale(this.bu);
|
|
|
|
- normal1 = normal1.scale(this.bv);
|
|
|
|
- normal2 = normal2.scale(1.0 - this.bu - this.bv);
|
|
|
|
- var result = new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
|
|
|
|
|
|
+ var result;
|
|
|
|
+ if (useVerticesNormals) {
|
|
|
|
+ var normals = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
|
|
|
+ var normal0 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3] * 3);
|
|
|
|
+ var normal1 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 1] * 3);
|
|
|
|
+ var normal2 = BABYLON.Vector3.FromArray(normals, indices[this.faceId * 3 + 2] * 3);
|
|
|
|
+ normal0 = normal0.scale(this.bu);
|
|
|
|
+ normal1 = normal1.scale(this.bv);
|
|
|
|
+ normal2 = normal2.scale(1.0 - this.bu - this.bv);
|
|
|
|
+ result = new BABYLON.Vector3(normal0.x + normal1.x + normal2.x, normal0.y + normal1.y + normal2.y, normal0.z + normal1.z + normal2.z);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ var positions = this.pickedMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
|
|
+ var vertex1 = BABYLON.Vector3.FromArray(positions, indices[this.faceId * 3] * 3);
|
|
|
|
+ var vertex2 = BABYLON.Vector3.FromArray(positions, indices[this.faceId * 3 + 1] * 3);
|
|
|
|
+ var vertex3 = BABYLON.Vector3.FromArray(positions, indices[this.faceId * 3 + 2] * 3);
|
|
|
|
+ var p1p2 = vertex1.subtract(vertex2);
|
|
|
|
+ var p3p2 = vertex3.subtract(vertex2);
|
|
|
|
+ result = BABYLON.Vector3.Cross(p1p2, p3p2);
|
|
|
|
+ }
|
|
if (useWorldCoordinates) {
|
|
if (useWorldCoordinates) {
|
|
result = BABYLON.Vector3.TransformNormal(result, this.pickedMesh.getWorldMatrix());
|
|
result = BABYLON.Vector3.TransformNormal(result, this.pickedMesh.getWorldMatrix());
|
|
}
|
|
}
|
|
- return result;
|
|
|
|
|
|
+ return BABYLON.Vector3.Normalize(result);
|
|
};
|
|
};
|
|
PickingInfo.prototype.getTextureCoordinates = function () {
|
|
PickingInfo.prototype.getTextureCoordinates = function () {
|
|
if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
|
|
if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
|