Skip to content

Commit

Permalink
Merge pull request Gaia3D#587 from Gaia3D/feature/nativeProjects_20
Browse files Browse the repository at this point in the history
Feature/native projects 20
  • Loading branch information
sdson authored Apr 23, 2018
2 parents 36b607a + 8209319 commit 5b27aae
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 170 deletions.
99 changes: 40 additions & 59 deletions src/mago3d/core/MagoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var MagoManager = function()
this.axisXYZ = new AxisXYZ();

this.invertedBox = new Box();
var mesh = this.invertedBox.makeMesh(2.5, 2.5, 2.5);
var mesh = this.invertedBox.makeMesh(1.5, 1.5, 1.5);
mesh.reverseSense();
//mesh.setColor(0.5, 0.5, 0.5, 0.5);
mesh.getVbo(this.invertedBox.vbo_vicks_container);
Expand Down Expand Up @@ -771,6 +771,7 @@ MagoManager.prototype.prepareNeoBuildingsAsimetricVersion = function(gl)
projectFolderName = node.data.projectFolderName;

neoBuilding = currentVisibleNodes[i].data.neoBuilding;

// check if this building is ready to render.***
//if (!neoBuilding.allFilesLoaded) // no used yet.
{
Expand Down Expand Up @@ -3983,7 +3984,21 @@ MagoManager.prototype.checkChangesHistoryColors = function(nodesArray)

MagoManager.prototype.renderInvertedBox = function(gl)
{
//return;
return;

if(this.fakeScreenPlane === undefined)
{
this.fakeScreenPlane = {};
this.fakeScreenPlane.vbo_vicks_container = new VBOVertexIdxCacheKeysContainer();
var vboKey = this.fakeScreenPlane.vbo_vicks_container.newVBOVertexIdxCacheKey();
var posArray = [-1,-1,0, 1,-1,0, -1,1,0, 1,-1,0, 1,1,0, -1,1,0];
//var elems = [0, 1, 2,];
vboKey.posVboDataArray = Float32Array.from(posArray);
vboKey.vertexCount = 6;
}

gl.depthFunc(gl.ALWAYS);
//gl.depthFunc(gl.NEVER);

// call this in the end of rendering pipeline.***
var currentShader = this.postFxShadersManager.getInvertedBoxShader();
Expand All @@ -3992,7 +4007,7 @@ MagoManager.prototype.renderInvertedBox = function(gl)
gl.useProgram(shaderProgram);

gl.enableVertexAttribArray(currentShader.position3_loc);
gl.enableVertexAttribArray(currentShader.normal3_loc);
//gl.disableVertexAttribArray(currentShader.normal3_loc);

gl.uniformMatrix4fv(currentShader.modelViewMatrix4_loc, false, this.sceneState.modelViewMatrix._floatArrays);
gl.uniformMatrix4fv(currentShader.projectionMatrix4_loc, false, this.sceneState.projectionMatrix._floatArrays);
Expand All @@ -4013,14 +4028,14 @@ MagoManager.prototype.renderInvertedBox = function(gl)
//gl.uniform1i(currentShader.diffuseTex_loc, 2); // no used.***

gl.uniform2fv(currentShader.noiseScale2_loc, [this.depthFboNeo.width/this.noiseTexture.width, this.depthFboNeo.height/this.noiseTexture.height]);
gl.uniform3fv(currentShader.kernel16_loc, this.kernel);
gl.uniform3fv(currentShader.kernel16_loc, this.sceneState.ssaoSphereKernel32);

gl.uniform1i(currentShader.textureFlipYAxis_loc, this.sceneState.textureFlipYAxis);

// lighting.
//this.magoPolicy.setSpecularColor(api.getSpecularColor());
gl.uniform3fv(currentShader.specularColor_loc, [0.7, 0.7, 0.7]);
gl.uniform1f(currentShader.ssaoRadius_loc, 1.0);
gl.uniform1f(currentShader.ssaoRadius_loc, 1.5);
gl.uniform1i(currentShader.hasTexture_loc, false);
gl.uniform4fv(currentShader.color4Aux_loc, [0.5,0.5,0.5,1.0]);

Expand Down Expand Up @@ -4048,21 +4063,23 @@ MagoManager.prototype.renderInvertedBox = function(gl)
if (this.isLastFrustum)
{
//this.renderer.renderObject(gl, this.invertedBox, this, currentShader, ssao_idx, bRenderLines, primitiveType);
var vbo_vicky = this.invertedBox.vbo_vicks_container.vboCacheKeysArray[0];
//var vbo_vicky = this.invertedBox.vbo_vicks_container.vboCacheKeysArray[0];
var vbo_vicky = this.fakeScreenPlane.vbo_vicks_container.vboCacheKeysArray[0];
if (!vbo_vicky.isReadyPositions(gl, this.vboMemoryManager))
{ return; }
gl.bindBuffer(gl.ARRAY_BUFFER, vbo_vicky.meshVertexCacheKey);
gl.vertexAttribPointer(currentShader.position3_loc, 3, gl.FLOAT, false, 0, 0);

if (!vbo_vicky.isReadyNormals(gl, this.vboMemoryManager))
return;
gl.bindBuffer(gl.ARRAY_BUFFER, vbo_vicky.meshNormalCacheKey);
gl.vertexAttribPointer(currentShader.normal3_loc, 3, gl.BYTE, true, 0, 0);
//if (!vbo_vicky.isReadyNormals(gl, this.vboMemoryManager))
// return;
//gl.bindBuffer(gl.ARRAY_BUFFER, vbo_vicky.meshNormalCacheKey);
//gl.vertexAttribPointer(currentShader.normal3_loc, 3, gl.BYTE, true, 0, 0);

if (!vbo_vicky.isReadyFaces(gl, this.vboMemoryManager))
{ return; }
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vbo_vicky.meshFacesCacheKey);
gl.drawElements(gl.TRIANGLES, vbo_vicky.indicesCount, gl.UNSIGNED_SHORT, 0); // Fill.***
//if (!vbo_vicky.isReadyFaces(gl, this.vboMemoryManager))
//{ return; }
//gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vbo_vicky.meshFacesCacheKey);
//gl.drawElements(gl.TRIANGLES, vbo_vicky.indicesCount, gl.UNSIGNED_SHORT, 0); // Fill.***
gl.drawArrays(gl.TRIANGLES, 0, this.fakeScreenPlane.vbo_vicks_container.vboCacheKeysArray[0].vertexCount);
}

gl.disable(gl.BLEND);
Expand All @@ -4081,6 +4098,8 @@ MagoManager.prototype.renderInvertedBox = function(gl)
gl.bindTexture(gl.TEXTURE_2D, null);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, null);

gl.depthFunc(gl.EQUAL);
};

/**
Expand All @@ -4096,6 +4115,7 @@ MagoManager.prototype.renderInvertedBox = function(gl)

MagoManager.prototype.renderDirectionalLight = function(gl, cameraPosition, shader, renderTexture, ssao_idx, visibleObjControlerNodes)
{
//this.myCameraSCX;

};

Expand Down Expand Up @@ -4198,9 +4218,10 @@ MagoManager.prototype.renderGeometry = function(gl, cameraPosition, shader, rend
gl.bindTexture(gl.TEXTURE_2D, null);
}

// 2) LOD 2.************************************************************************************************************************************
// 2) LOD 2, 3, 4, 5.************************************************************************************************************************************
var nodesLOD2Count = visibleObjControlerNodes.currentVisibles2.length;
if (nodesLOD2Count > 0 || nodesLOD0Count > 0)
var nodesLOD3Count = visibleObjControlerNodes.currentVisibles3.length;
if (nodesLOD2Count > 0 || nodesLOD0Count > 0 || nodesLOD3Count>0)
{
this.checkChangesHistoryColors(visibleObjControlerNodes.currentVisibles2);

Expand All @@ -4221,8 +4242,9 @@ MagoManager.prototype.renderGeometry = function(gl, cameraPosition, shader, rend
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, this.textureAux_1x1);

this.renderer.renderNeoBuildingsLOD2AsimetricVersion(gl, visibleObjControlerNodes.currentVisibles0, this, currentShader, renderTexture, ssao_idx);
this.renderer.renderNeoBuildingsLOD2AsimetricVersion(gl, visibleObjControlerNodes.currentVisibles2, this, currentShader, renderTexture, ssao_idx);
this.renderer.renderNeoBuildingsLOD2AsimetricVersion(gl, visibleObjControlerNodes.currentVisibles0, this, currentShader, renderTexture, ssao_idx); // lod 0.***
this.renderer.renderNeoBuildingsLOD2AsimetricVersion(gl, visibleObjControlerNodes.currentVisibles2, this, currentShader, renderTexture, ssao_idx); // lod 2.***
this.renderer.renderNeoBuildingsLowLOD(gl, visibleObjControlerNodes.currentVisibles3, this, currentShader, renderTexture, ssao_idx); // lod 3, 4, 5.***

if (currentShader)
{
Expand All @@ -4239,48 +4261,7 @@ MagoManager.prototype.renderGeometry = function(gl, cameraPosition, shader, rend
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, null);
}

// 3) LOD3, LOD4, LOD5.************************************************************************************************************************************
var nodesLOD3Count = visibleObjControlerNodes.currentVisibles3.length;
if (nodesLOD3Count > 0)
{
//this.checkChangesHistoryColors(visibleObjControlerNodes.currentVisibles2);
currentShader = this.postFxShadersManager.getShader("lodBuildingSsao");

shaderProgram = currentShader.program;

gl.useProgram(shaderProgram);
gl.enableVertexAttribArray(currentShader.position3_loc);
gl.enableVertexAttribArray(currentShader.normal3_loc);
gl.enableVertexAttribArray(currentShader.color4_loc);

currentShader.bindUniformGenerals();

gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, this.depthFboNeo.colorBuffer); // original.***
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, this.noiseTexture);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, this.textureAux_1x1);

this.renderer.renderNeoBuildingsLowLOD(gl, visibleObjControlerNodes.currentVisibles3, this, currentShader, renderTexture, ssao_idx);

if (currentShader)
{
if (currentShader.texCoord2_loc !== -1){ gl.disableVertexAttribArray(currentShader.texCoord2_loc); }
if (currentShader.position3_loc !== -1){ gl.disableVertexAttribArray(currentShader.position3_loc); }
if (currentShader.normal3_loc !== -1){ gl.disableVertexAttribArray(currentShader.normal3_loc); }
if (currentShader.color4_loc !== -1){ gl.disableVertexAttribArray(currentShader.color4_loc); }
}

gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, null); // original.***
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, null);
}

// If there are an object selected, then there are a stencilBuffer.******************************************
if (this.nodeSelected) // if there are an object selected then there are a building selected.***
{
Expand Down
10 changes: 8 additions & 2 deletions src/mago3d/f4d/ReaderWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,14 @@ ReaderWriter.prototype.readLegoSimpleBuildingTexture = function(gl, filePath_inS

neoRefImage.onerror = function()
{
// doesn't exist or error loading
return;
if (texture.texId === undefined)
{
texture.texId = gl.createTexture();
// Test wait for texture to load.********************************************
gl.bindTexture(gl.TEXTURE_2D, texture.texId);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([200, 200, 200, 255])); // clear grey
gl.bindTexture(gl.TEXTURE_2D, null);
}
};

neoRefImage.src = filePath_inServer;
Expand Down
9 changes: 8 additions & 1 deletion src/mago3d/renderer/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,14 @@ Renderer.prototype.renderLodBuilding = function(gl, lodBuilding, magoManager, sh
}

gl.drawArrays(gl.TRIANGLES, 0, vertices_count);
//gl.drawArrays(gl.LINES, 0, vertices_count);
/*
gl.uniform1i(shader.bUse1Color_loc, true);
gl.uniform4fv(shader.oneColor4_loc, [1.0, 1.0, 1.0, 1.0]); //.***
gl.disableVertexAttribArray(shader.texCoord2_loc);
gl.uniform1i(shader.hasTexture_loc, false);
gl.drawArrays(gl.LINES, 0, vertices_count);
gl.enableVertexAttribArray(shader.texCoord2_loc);
*/
}
};

Expand Down
19 changes: 18 additions & 1 deletion src/mago3d/renderer/SceneState.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,24 @@ var SceneState = function()
-0.45, 0.0, 0.55,
-0.65, -0.5, 0.7,
0.0, -0.5, 0.55,
0.33, 0.3, 0.35];
0.33, 0.3, 0.35,

0.33, 0.0, -0.85,
0.25, 0.3, -0.5,
0.1, 0.3, -0.85,
-0.15, 0.2, -0.85,
-0.33, 0.05, -0.6,
-0.1, -0.15, -0.85,
-0.05, -0.32, -0.25,
0.2, -0.15, -0.85,
0.6, 0.0, -0.55,
0.5, 0.6, -0.45,
-0.01, 0.7, -0.35,
-0.33, 0.5, -0.45,
-0.45, 0.0, -0.55,
-0.65, -0.5, -0.7,
0.0, -0.5, -0.55,
0.33, 0.3, -0.35];

this.bMust = false;

Expand Down
Loading

0 comments on commit 5b27aae

Please sign in to comment.