Skip to content

Commit

Permalink
Support for vertex paint and vertex alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh committed Nov 27, 2014
1 parent edd037a commit 0865aa6
Show file tree
Hide file tree
Showing 26 changed files with 2,538 additions and 2,440 deletions.
24 changes: 22 additions & 2 deletions Babylon/Loading/Plugins/babylon.babylonFileLoader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions Babylon/Loading/Plugins/babylon.babylonFileLoader.ts
@@ -1,5 +1,23 @@
module BABYLON.Internals {

var checkColors4 = (colors: number[], count:number): number[] => {
// Check if color3 was used
if (colors.length === count * 3) {
var colors4 = [];
for (var index = 0; index < colors.length; index += 3) {
var newIndex = (index / 3) * 4;
colors4[newIndex] = colors[index];
colors4[newIndex + 1] = colors[index + 1];
colors4[newIndex + 2] = colors[index + 2];
colors4[newIndex + 3] = 1.0;
}

return colors4;
}

return colors
}

var loadCubeTexture = (rootUrl, parsedTexture, scene) => {
var texture = new BABYLON.CubeTexture(rootUrl + parsedTexture.name, scene);

Expand Down Expand Up @@ -659,6 +677,8 @@
}

// Geometry
mesh.hasVertexAlpha = parsedMesh.hasVertexAlpha;

if (parsedMesh.delayLoadingFile) {
mesh.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
mesh.delayLoadingFile = rootUrl + parsedMesh.delayLoadingFile;
Expand Down Expand Up @@ -821,7 +841,7 @@
// colors
var colors = parsedVertexData.colors;
if (colors) {
vertexData.set(colors, BABYLON.VertexBuffer.ColorKind);
vertexData.set(checkColors4(colors, positions.length / 3), BABYLON.VertexBuffer.ColorKind);
}

// matricesIndices
Expand Down Expand Up @@ -926,7 +946,7 @@
}

if (parsedGeometry.colors) {
mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, parsedGeometry.colors, false);
mesh.setVerticesData(BABYLON.VertexBuffer.ColorKind, checkColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), false);
}

if (parsedGeometry.matricesIndices) {
Expand Down
4 changes: 4 additions & 0 deletions Babylon/Materials/babylon.standardMaterial.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Babylon/Materials/babylon.standardMaterial.ts
Expand Up @@ -330,6 +330,10 @@
if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
attribs.push(BABYLON.VertexBuffer.ColorKind);
defines.push("#define VERTEXCOLOR");

if (mesh.hasVertexAlpha) {
defines.push("#define VERTEXALPHA");
}
}
if (mesh.skeleton && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind) && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
Expand Down
8 changes: 8 additions & 0 deletions Babylon/Math/babylon.math.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0865aa6

Please sign in to comment.