JSFiddle - React, Tailwind, and code Playground
by MaxenceBrasselet
HTML
<script src="https://rawgithub.com/BabylonJS/Babylon.js/master/babylon.1.8.0.js"></script>
<div id="rootDiv">
<canvas id="renderCanvas"></canvas>
</div>
CSS
html, body, div, canvas {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
JavaScript
BABYLON.Mesh.prototype._setVerticesDataByMerging = function (meshToMerge1, meshToMerge2, kind) {
var verticesData = [];
if(meshToMerge1.isVerticesDataPresent([kind])) {
verticesData = meshToMerge1.getVerticesData(kind);
}
if(meshToMerge2.isVerticesDataPresent([kind])) {
verticesData = verticesData.concat(meshToMerge2.getVerticesData(kind));
}
if (verticesData.length === 0)
return;
this.setVerticesData(verticesData, kind, false);
};
BABYLON.Mesh.prototype._getWorldVerticesPositionsAndNormals = function (worldVerticesPositions, worldVerticesNormals) {
var localPos = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
var localNorm = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
var worldMatrix = this.getWorldMatrix();
var ite = 0;
while (ite < localPos.length) {
var vertex = new BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(localPos[ite++], localPos[ite++], localPos[ite++]), worldMatrix);
worldVerticesPositions.push(vertex.x);
worldVerticesPositions.push(vertex.y);
worldVerticesPositions.push(vertex.z);
}
ite = 0;
while (ite < localNorm.length) {
var vertex = new BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(localNorm[ite++], localNorm[ite++], localNorm[ite++]), worldMatrix);
worldVerticesNormals.push(vertex.x);
worldVerticesNormals.push(vertex.y);
worldVerticesNormals.push(vertex.z);
}
};
// Merge
BABYLON.Mesh.prototype.merge = function (meshToMerge) {
if (meshToMerge === this || meshToMerge.id === this.id)
return;
var newMesh = new BABYLON.Mesh("merged", this._scene);
//var newMesh = this;
newMesh._setVerticesDataByMerging(this, meshToMerge, BABYLON.VertexBuffer.UVKind);
newMesh._setVerticesDataByMerging(this, meshToMerge, BABYLON.VertexBuffer.UV2Kind);
newMesh._setVerticesDataByMerging(this,...