|
@@ -185,13 +185,15 @@ class Terrain extends Object3D {
|
|
function loadSurfaces( ctx : Context, onEnd : Void -> Void ) {
|
|
function loadSurfaces( ctx : Context, onEnd : Void -> Void ) {
|
|
for( surfaceProps in tmpSurfacesProps ) {
|
|
for( surfaceProps in tmpSurfacesProps ) {
|
|
var surface = terrain.addEmptySurface();
|
|
var surface = terrain.addEmptySurface();
|
|
|
|
+ }
|
|
|
|
+ for( i in 0 ... tmpSurfacesProps.length ) {
|
|
|
|
+ var surfaceProps = tmpSurfacesProps[i];
|
|
|
|
+ var surface = terrain.getSurface(i);
|
|
var albedo = ctx.shared.loadTexture(surfaceProps.albedo);
|
|
var albedo = ctx.shared.loadTexture(surfaceProps.albedo);
|
|
var normal = ctx.shared.loadTexture(surfaceProps.normal);
|
|
var normal = ctx.shared.loadTexture(surfaceProps.normal);
|
|
var pbr = ctx.shared.loadTexture(surfaceProps.pbr);
|
|
var pbr = ctx.shared.loadTexture(surfaceProps.pbr);
|
|
function wait() {
|
|
function wait() {
|
|
- if( albedo.isDisposed() )
|
|
|
|
- return;
|
|
|
|
- if( albedo.flags.has(Loading) || normal.flags.has(Loading) || pbr.flags.has(Loading) )
|
|
|
|
|
|
+ if( albedo.isDisposed() || albedo.flags.has(Loading) || normal.flags.has(Loading) || pbr.flags.has(Loading) )
|
|
return;
|
|
return;
|
|
surface.albedo = albedo;
|
|
surface.albedo = albedo;
|
|
surface.normal = normal;
|
|
surface.normal = normal;
|
|
@@ -205,7 +207,6 @@ class Terrain extends Object3D {
|
|
/*albedo.dispose();
|
|
/*albedo.dispose();
|
|
normal.dispose();
|
|
normal.dispose();
|
|
pbr.dispose();*/
|
|
pbr.dispose();*/
|
|
-
|
|
|
|
onEnd();
|
|
onEnd();
|
|
}
|
|
}
|
|
albedo.waitLoad(wait);
|
|
albedo.waitLoad(wait);
|
|
@@ -217,16 +218,24 @@ class Terrain extends Object3D {
|
|
public function initTerrain( ctx : Context, height = true, surface = true ) {
|
|
public function initTerrain( ctx : Context, height = true, surface = true ) {
|
|
//#if editor
|
|
//#if editor
|
|
if( surface ) {
|
|
if( surface ) {
|
|
|
|
+ var initDone = false;
|
|
function waitAll() {
|
|
function waitAll() {
|
|
- for( surface in terrain.surfaces )
|
|
|
|
|
|
+
|
|
|
|
+ if( initDone )
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ for( surface in terrain.surfaces ) {
|
|
if( surface == null || surface.albedo == null || surface.normal == null || surface.pbr == null )
|
|
if( surface == null || surface.albedo == null || surface.normal == null || surface.pbr == null )
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
terrain.generateSurfaceArray();
|
|
terrain.generateSurfaceArray();
|
|
|
|
|
|
loadTiles(ctx, height, surface, surface);
|
|
loadTiles(ctx, height, surface, surface);
|
|
|
|
|
|
for( t in terrain.tiles )
|
|
for( t in terrain.tiles )
|
|
t.computeEdgesNormals();
|
|
t.computeEdgesNormals();
|
|
|
|
+
|
|
|
|
+ initDone = true;
|
|
}
|
|
}
|
|
loadSurfaces(ctx, waitAll);
|
|
loadSurfaces(ctx, waitAll);
|
|
}
|
|
}
|