Skip to content

Commit

Permalink
Merge branch 'develop' into feature/nativeProjects_23
Browse files Browse the repository at this point in the history
  • Loading branch information
sdson committed May 4, 2018
2 parents 720d692 + 67d2743 commit 4357e11
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ data
mago3djs.iml
sample/persistence/json/2119_deploy.json
f4d
!/src/mago3d/f4d
287 changes: 287 additions & 0 deletions src/mago3d/f4d/TinTerrain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
'use strict';

/**
* @class TinTerrain
*/
var TinTerrain = function()
{
if (!(this instanceof TinTerrain))
{
throw new Error(Messages.CONSTRUCT_ERROR);
}

this.geographicExtent;
this.fileLoadState = 0;
this.dataArrayBuffer;
this.vboKeyContainer; // class: VBOVertexIdxCacheKeysContainer.***
this.terrainPositionHIGH;
this.terrainPositionLOW;
};

TinTerrain.prototype.zigZagDecode = function(value)
{
return (value >> 1) ^ (-(value & 1));
};

TinTerrain.prototype.makeVbo = function()
{
if (this.cartesiansArray === undefined)
{ return; }

// rest the CenterPosition to the this.cartesiansArray.***
var coordsCount = this.cartesiansArray.length/3;
for (var i=0; i<coordsCount; i++)
{
this.cartesiansArray[i*3] -= this.centerX;
this.cartesiansArray[i*3+1] -= this.centerY;
this.cartesiansArray[i*3+2] -= this.centerZ;
}

if (this.terrainPositionHIGH === undefined)
{ this.terrainPositionHIGH = new Float32Array(3); }

if (this.terrainPositionLOW === undefined)
{ this.terrainPositionLOW = new Float32Array(3); }
ManagerUtils.calculateSplited3fv([this.centerX[0], this.centerY[0], this.centerZ[0]], this.terrainPositionHIGH, this.terrainPositionLOW);

if (this.vboKeyContainer === undefined)
{ this.vboKeyContainer = new VBOVertexIdxCacheKeysContainer(); }

var vboKey = this.vboKeyContainer.newVBOVertexIdxCacheKey();
vboKey.posVboDataArray = this.cartesiansArray;
vboKey.tcoordVboDataArray = this.texCoordsArray;
vboKey.idxVboDataArray = this.indices;
vboKey.indicesCount = this.indices.length;
/*
if (normal)
{ vboKey.norVboDataArray = Int8Array.from(norArray); }
if (color)
{ vboKey.colVboDataArray = Uint8Array.from(colArray); }
*/
};

TinTerrain.prototype.decodeData = function()
{
if (this.geographicExtent === undefined)
{ return; }

if (this.vertexArray === undefined)
{ this.vertexArray = []; }

var degToRadFactor = Math.PI/180.0;
// latitude & longitude in RADIANS.***
var minLon = this.geographicExtent.minGeographicCoord.longitude * degToRadFactor;
var minLat = this.geographicExtent.minGeographicCoord.latitude * degToRadFactor;
var maxLon = this.geographicExtent.maxGeographicCoord.longitude * degToRadFactor;
var maxLat = this.geographicExtent.maxGeographicCoord.latitude * degToRadFactor;
var lonRange = maxLon - minLon;
var latRange = maxLat - minLat;

var minHeight = this.minHeight[0];
var maxHeight = this.maxHeight[0];
var heightRange = maxHeight - minHeight;

var vertexCount = this.vertexCount[0];
this.texCoordsArray = new Float32Array(vertexCount*2);
var lonArray = new Float32Array(vertexCount);
var latArray = new Float32Array(vertexCount);
var altArray = new Float32Array(vertexCount);
var shortMax = 32767; // 65536
var lonRangeDivShortMax = lonRange/shortMax;
var latRangeDivShortMax = latRange/shortMax;
var heightRangeDivShortMax = heightRange/shortMax;
var uValues = this.uValues;
var vValues = this.vValues;
var hValues = this.hValues;
for (var i=0; i<vertexCount; i++)
{
lonArray[i] = minLon + uValues[i]*lonRangeDivShortMax;
latArray[i] = minLat + vValues[i]*latRangeDivShortMax;
altArray[i] = minHeight + hValues[i]*heightRangeDivShortMax + 20.0;

// make texcoords.***
this.texCoordsArray[i*2] = uValues[i]/shortMax;
this.texCoordsArray[i*2+1] = vValues[i]/shortMax;
}

this.cartesiansArray = Globe.geographicRadianArrayToFloat32ArrayWgs84(lonArray, latArray, altArray, this.cartesiansArray);

// free memory.***
this.uValues = undefined;
this.vValues = undefined;
this.hValues = undefined;

lonArray = undefined;
latArray = undefined;
altArray = undefined;

};

TinTerrain.prototype.parseData = function(dataArrayBuffer)
{
this.fileLoadState = CODE.fileLoadState.PARSE_STARTED;
var bytes_readed = 0;

// 1. header.***
this.centerX = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.centerY = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.centerZ = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;

this.minHeight = new Float32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+4)); bytes_readed+=4;
this.maxHeight = new Float32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+4)); bytes_readed+=4;

this.boundingSphereCenterX = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.boundingSphereCenterY = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.boundingSphereCenterZ = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.boundingSphereRadius = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;

this.horizonOcclusionPointX = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.horizonOcclusionPointY = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;
this.horizonOcclusionPointZ = new Float64Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+8)); bytes_readed+=8;

// 2. vertex data.***
this.vertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed+4)); bytes_readed+=4;
var vertexCount = this.vertexCount[0];
this.uValues = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * vertexCount)); bytes_readed += 2 * vertexCount;
this.vValues = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * vertexCount)); bytes_readed += 2 * vertexCount;
this.hValues = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * vertexCount)); bytes_readed += 2 * vertexCount;

// decode data.***
var u = 0;
var v = 0;
var height = 0;
for (var i=0; i<vertexCount; i++)
{
u += this.zigZagDecode(this.uValues[i]);
v += this.zigZagDecode(this.vValues[i]);
height += this.zigZagDecode(this.hValues[i]);

this.uValues[i] = u;
this.vValues[i] = v;
this.hValues[i] = height;
}

// 3. indices.***
this.trianglesCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
var trianglesCount = this.trianglesCount;
if (vertexCount > 65536 )
{
this.indices = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4 * trianglesCount * 3)); bytes_readed += 4 * trianglesCount * 3;
}
else
{
this.indices = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * trianglesCount * 3)); bytes_readed += 2 * trianglesCount * 3;
}

// decode indices.***
var code;
var highest = 0;
var indicesCount = this.indices.length;
for (var i=0; i<indicesCount; i++)
{
code = this.indices[i];
this.indices[i] = highest - code;
if (code === 0)
{
++highest;
}
}

// 4. edges indices.***
if (vertexCount > 65536 )
{
this.westVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.westIndices = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4 * this.westVertexCount)); bytes_readed += 4 * this.westVertexCount;

this.southVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.southIndices = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4 * this.southVertexCount)); bytes_readed += 4 * this.southVertexCount;

this.eastVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.eastIndices = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4 * this.eastVertexCount)); bytes_readed += 4 * this.eastVertexCount;

this.northVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.northIndices = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4 * this.northVertexCount)); bytes_readed += 4 * this.northVertexCount;
}
else
{
this.westVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.westIndices = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * this.westVertexCount)); bytes_readed += 2 * this.westVertexCount;

this.southVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.southIndices = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * this.southVertexCount)); bytes_readed += 2 * this.southVertexCount;

this.eastVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.eastIndices = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * this.eastVertexCount)); bytes_readed += 2 * this.eastVertexCount;

this.northVertexCount = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;
this.northIndices = new Uint16Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 2 * this.northVertexCount)); bytes_readed += 2 * this.northVertexCount;
}

// 5. extension header.***
this.extensionId = new Uint8Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 1)); bytes_readed += 1;
this.extensionLength = new Uint32Array(dataArrayBuffer.slice(bytes_readed, bytes_readed + 4)); bytes_readed += 4;

this.fileLoadState = CODE.fileLoadState.PARSE_FINISHED;

if (this.extensionId.length === 0)
{
dataArrayBuffer = undefined;
return;
}

dataArrayBuffer = undefined;
};




















































16 changes: 16 additions & 0 deletions src/mago3d/f4d/TinTerrainManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/**
* @class TinTerrainManager
*/
var TinTerrainManager = function()
{
if (!(this instanceof TinTerrainManager))
{
throw new Error(Messages.CONSTRUCT_ERROR);
}

this.maxDepth = 14;
this.currentVisiblesMap = {};

};

0 comments on commit 4357e11

Please sign in to comment.