瀏覽代碼

Terrain: Cache previous instance for faster scene refresh

trethaller 6 年之前
父節點
當前提交
73c4356522
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      hide/prefab/terrain/Terrain.hx

+ 12 - 0
hide/prefab/terrain/Terrain.hx

@@ -30,6 +30,7 @@ class Terrain extends Object3D {
 
 
 	#if editor
 	#if editor
 	var editor : hide.prefab.terrain.TerrainEditor;
 	var editor : hide.prefab.terrain.TerrainEditor;
+	var cachedInstance : h3d.scene.pbr.terrain.Terrain;
 	#end
 	#end
 
 
 	public function new(?parent) {
 	public function new(?parent) {
@@ -150,6 +151,16 @@ class Terrain extends Object3D {
 
 
 	override function makeInstance(ctx:Context):Context {
 	override function makeInstance(ctx:Context):Context {
 		ctx = ctx.clone(this);
 		ctx = ctx.clone(this);
+		
+		#if editor
+		if(cachedInstance != null) {
+			ctx.local3d.addChild(cachedInstance);
+			ctx.local3d = cachedInstance;
+			ctx.local3d.name = name;
+			updateInstance(ctx);
+			return ctx;
+		}
+		#end
 
 
 		terrain = new h3d.scene.pbr.terrain.Terrain(ctx.local3d);
 		terrain = new h3d.scene.pbr.terrain.Terrain(ctx.local3d);
 		terrain.cellCount = getCellCount();
 		terrain.cellCount = getCellCount();
@@ -164,6 +175,7 @@ class Terrain extends Object3D {
 		terrain.heightBlendStrength = heightBlendStrength;
 		terrain.heightBlendStrength = heightBlendStrength;
 		terrain.heightBlendSharpness = heightBlendSharpness;
 		terrain.heightBlendSharpness = heightBlendSharpness;
 		terrain.name = "terrain";
 		terrain.name = "terrain";
+		cachedInstance = terrain;
 
 
 		ctx.local3d = terrain;
 		ctx.local3d = terrain;
 		ctx.local3d.name = name;
 		ctx.local3d.name = name;