浏览代码

Fix Leak spline mesh
Add fast option for getheight for terrain

ShiroSmith 5 年之前
父节点
当前提交
9af3f37efd
共有 2 个文件被更改,包括 14 次插入4 次删除
  1. 12 2
      hrt/prefab/l3d/SplineMesh.hx
  2. 2 2
      hrt/prefab/terrain/TerrainMesh.hx

+ 12 - 2
hrt/prefab/l3d/SplineMesh.hx

@@ -72,6 +72,16 @@ enum SplineMeshMode {
 	BigGeometry;
 	BigGeometry;
 }
 }
 
 
+// Need to dipose the GPU buffer manually
+class SplineMeshBatch extends h3d.scene.MeshBatch {
+	override function onRemove() {
+		var splinemeshShader = material.mainPass.getShader(SplineMeshShader);
+		if( splinemeshShader != null ) {
+			splinemeshShader.points.dispose();
+		}
+	}
+}
+
 class SplineMesh extends Spline {
 class SplineMesh extends Spline {
 
 
 	var meshPath : String;
 	var meshPath : String;
@@ -85,7 +95,7 @@ class SplineMesh extends Spline {
 	var meshRotation = new h3d.Vector(0,0,0);
 	var meshRotation = new h3d.Vector(0,0,0);
 	var modelMat = new h3d.Matrix();
 	var modelMat = new h3d.Matrix();
 
 
-	var meshBatch : h3d.scene.MeshBatch = null;
+	var meshBatch : SplineMeshBatch = null;
 	var meshPrimitive : h3d.prim.MeshPrimitive = null;
 	var meshPrimitive : h3d.prim.MeshPrimitive = null;
 	var meshMaterial : h3d.mat.Material = null;
 	var meshMaterial : h3d.mat.Material = null;
 	var customPass : String;
 	var customPass : String;
@@ -202,7 +212,7 @@ class SplineMesh extends Spline {
 				}
 				}
 			}
 			}
 
 
-			meshBatch = new MeshBatch(meshPrimitive, splineMaterial, ctx.local3d);
+			meshBatch = new SplineMeshBatch(meshPrimitive, splineMaterial, ctx.local3d);
 			meshBatch.ignoreParentTransform = true;
 			meshBatch.ignoreParentTransform = true;
 		}
 		}
 	}
 	}

+ 2 - 2
hrt/prefab/terrain/TerrainMesh.hx

@@ -79,13 +79,13 @@ class TerrainMesh extends h3d.scene.Object {
 		generateSurfaceArray();
 		generateSurfaceArray();
 	}
 	}
 
 
-	public function getHeight( x : Float, y : Float ) : Float {
+	public function getHeight( x : Float, y : Float, fast = false) : Float {
 		var z = 0.0;
 		var z = 0.0;
 		var t = getTileAtWorldPos(x, y);
 		var t = getTileAtWorldPos(x, y);
 		if( t != null ) {
 		if( t != null ) {
 			tmpVec.set(x, y);
 			tmpVec.set(x, y);
 			var pos = t.globalToLocal(tmpVec);
 			var pos = t.globalToLocal(tmpVec);
-			z = t.getHeight(pos.x / tileSize, pos.y / tileSize);
+			z = t.getHeight(pos.x / tileSize, pos.y / tileSize, fast);
 		}
 		}
 		return z;
 		return z;
 	}
 	}