|
@@ -33,10 +33,14 @@ class Tile extends h3d.scene.Mesh {
|
|
}
|
|
}
|
|
|
|
|
|
override function onRemove() {
|
|
override function onRemove() {
|
|
- if( heightMap != null ) heightMap.dispose();
|
|
|
|
- if( surfaceIndexMap != null ) surfaceIndexMap.dispose();
|
|
|
|
|
|
+ if( heightMap != null )
|
|
|
|
+ heightMap.dispose();
|
|
|
|
+ if( surfaceIndexMap != null )
|
|
|
|
+ surfaceIndexMap.dispose();
|
|
for( i in 0 ... surfaceWeights.length )
|
|
for( i in 0 ... surfaceWeights.length )
|
|
if( surfaceWeights[i] != null ) surfaceWeights[i].dispose();
|
|
if( surfaceWeights[i] != null ) surfaceWeights[i].dispose();
|
|
|
|
+ if( surfaceWeightArray != null )
|
|
|
|
+ surfaceWeightArray.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
public override function clone( ?o : h3d.scene.Object ) : h3d.scene.Object {
|
|
public override function clone( ?o : h3d.scene.Object ) : h3d.scene.Object {
|
|
@@ -113,10 +117,11 @@ class Tile extends h3d.scene.Mesh {
|
|
computeEdgesNormals();
|
|
computeEdgesNormals();
|
|
}
|
|
}
|
|
|
|
|
|
- public function refresh() {
|
|
|
|
|
|
+ function refreshHeightMap() {
|
|
if( heightMap == null || heightMap.width != getTerrain().heightMapResolution + 1 ) {
|
|
if( heightMap == null || heightMap.width != getTerrain().heightMapResolution + 1 ) {
|
|
var oldHeightMap = heightMap;
|
|
var oldHeightMap = heightMap;
|
|
heightMap = new h3d.mat.Texture(getTerrain().heightMapResolution + 1, getTerrain().heightMapResolution + 1, [Target], RGBA32F );
|
|
heightMap = new h3d.mat.Texture(getTerrain().heightMapResolution + 1, getTerrain().heightMapResolution + 1, [Target], RGBA32F );
|
|
|
|
+ heightMap.name = "terrainHeightMap";
|
|
heightMap.wrap = Clamp;
|
|
heightMap.wrap = Clamp;
|
|
heightMap.filter = Linear;
|
|
heightMap.filter = Linear;
|
|
heightMap.preventAutoDispose();
|
|
heightMap.preventAutoDispose();
|
|
@@ -127,10 +132,13 @@ class Tile extends h3d.scene.Mesh {
|
|
}
|
|
}
|
|
needNewPixelCapture = true;
|
|
needNewPixelCapture = true;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ function refreshIndexMap() {
|
|
if( surfaceIndexMap == null || surfaceIndexMap.width != getTerrain().weightMapResolution ) {
|
|
if( surfaceIndexMap == null || surfaceIndexMap.width != getTerrain().weightMapResolution ) {
|
|
var oldSurfaceIndexMap = surfaceIndexMap;
|
|
var oldSurfaceIndexMap = surfaceIndexMap;
|
|
surfaceIndexMap = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], RGBA);
|
|
surfaceIndexMap = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], RGBA);
|
|
|
|
+ surfaceIndexMap.name = "terrainSurfaceIndexMap";
|
|
surfaceIndexMap.filter = Nearest;
|
|
surfaceIndexMap.filter = Nearest;
|
|
surfaceIndexMap.preventAutoDispose();
|
|
surfaceIndexMap.preventAutoDispose();
|
|
surfaceIndexMap.realloc = null;
|
|
surfaceIndexMap.realloc = null;
|
|
@@ -139,30 +147,40 @@ class Tile extends h3d.scene.Mesh {
|
|
oldSurfaceIndexMap.dispose();
|
|
oldSurfaceIndexMap.dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ function refreshSurfaceWeights() {
|
|
if( getTerrain().surfaceArray.surfaceCount > 0 && (surfaceWeights.length != getTerrain().surfaceArray.surfaceCount || surfaceWeights[0].width != getTerrain().weightMapResolution) ) {
|
|
if( getTerrain().surfaceArray.surfaceCount > 0 && (surfaceWeights.length != getTerrain().surfaceArray.surfaceCount || surfaceWeights[0].width != getTerrain().weightMapResolution) ) {
|
|
- var oldArray = surfaceWeights;
|
|
|
|
- surfaceWeights = new Array<h3d.mat.Texture>();
|
|
|
|
- surfaceWeights = [for( i in 0...getTerrain().surfaceArray.surfaceCount ) null];
|
|
|
|
- for( i in 0 ... surfaceWeights.length ) {
|
|
|
|
- surfaceWeights[i] = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], R8);
|
|
|
|
- surfaceWeights[i].wrap = Clamp;
|
|
|
|
- surfaceWeights[i].preventAutoDispose();
|
|
|
|
- surfaceWeights[i].realloc = null;
|
|
|
|
- if( i < oldArray.length && oldArray[i] != null )
|
|
|
|
- getTerrain().copyPass.apply(oldArray[i], surfaceWeights[i]);
|
|
|
|
- }
|
|
|
|
- generateWeightArray();
|
|
|
|
-
|
|
|
|
- for( i in 0 ... oldArray.length )
|
|
|
|
- if( oldArray[i] != null) oldArray[i].dispose();
|
|
|
|
|
|
+ var oldArray = surfaceWeights;
|
|
|
|
+ surfaceWeights = new Array<h3d.mat.Texture>();
|
|
|
|
+ surfaceWeights = [for( i in 0...getTerrain().surfaceArray.surfaceCount ) null];
|
|
|
|
+ for( i in 0 ... surfaceWeights.length ) {
|
|
|
|
+ surfaceWeights[i] = new h3d.mat.Texture(getTerrain().weightMapResolution, getTerrain().weightMapResolution, [Target], R8);
|
|
|
|
+ surfaceWeights[i].name = "terrainSurfaceWeight"+i;
|
|
|
|
+ surfaceWeights[i].wrap = Clamp;
|
|
|
|
+ surfaceWeights[i].preventAutoDispose();
|
|
|
|
+ surfaceWeights[i].realloc = null;
|
|
|
|
+ if( i < oldArray.length && oldArray[i] != null )
|
|
|
|
+ getTerrain().copyPass.apply(oldArray[i], surfaceWeights[i]);
|
|
|
|
+ }
|
|
|
|
+ for( t in oldArray )
|
|
|
|
+ if( t != null)
|
|
|
|
+ t.dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function refresh() {
|
|
|
|
+ refreshHeightMap();
|
|
|
|
+ refreshIndexMap();
|
|
|
|
+ refreshSurfaceWeights();
|
|
|
|
+ generateWeightArray();
|
|
|
|
+ }
|
|
|
|
+
|
|
public function generateWeightArray() {
|
|
public function generateWeightArray() {
|
|
if( surfaceWeightArray == null || surfaceWeightArray.width != getTerrain().weightMapResolution || surfaceWeightArray.get_layerCount() != surfaceWeights.length ) {
|
|
if( surfaceWeightArray == null || surfaceWeightArray.width != getTerrain().weightMapResolution || surfaceWeightArray.get_layerCount() != surfaceWeights.length ) {
|
|
if( surfaceWeightArray != null ) surfaceWeightArray.dispose();
|
|
if( surfaceWeightArray != null ) surfaceWeightArray.dispose();
|
|
surfaceWeightArray = new h3d.mat.TextureArray(getTerrain().weightMapResolution, getTerrain().weightMapResolution, surfaceWeights.length, [Target], R8);
|
|
surfaceWeightArray = new h3d.mat.TextureArray(getTerrain().weightMapResolution, getTerrain().weightMapResolution, surfaceWeights.length, [Target], R8);
|
|
|
|
+ surfaceWeightArray.name = "terrainSurfaceWeightArray";
|
|
surfaceWeightArray.wrap = Clamp;
|
|
surfaceWeightArray.wrap = Clamp;
|
|
surfaceWeightArray.preventAutoDispose();
|
|
surfaceWeightArray.preventAutoDispose();
|
|
surfaceWeightArray.realloc = null;
|
|
surfaceWeightArray.realloc = null;
|
|
@@ -580,11 +598,11 @@ class Tile extends h3d.scene.Mesh {
|
|
return false;
|
|
return false;
|
|
|
|
|
|
for( i in 0 ... surfaceWeights.length )
|
|
for( i in 0 ... surfaceWeights.length )
|
|
- if( surfaceWeights[i] == null )
|
|
|
|
|
|
+ if( surfaceWeights[i] == null || surfaceWeights[i].isDisposed() )
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if( heightMap == null )
|
|
|
|
|
|
+ if( heightMap == null || heightMap.isDisposed() )
|
|
return false;
|
|
return false;
|
|
|
|
|
|
return true;
|
|
return true;
|