浏览代码

Remove h3d.Matrix's getPosition and getScale parameter leading to allocs.

clandrin 3 年之前
父节点
当前提交
3ffbb91590
共有 4 个文件被更改,包括 7 次插入10 次删除
  1. 4 5
      h3d/Matrix.hx
  2. 1 1
      h3d/pass/PointShadowMap.hx
  3. 1 2
      h3d/scene/Object.hx
  4. 1 2
      h3d/scene/Skin.hx

+ 4 - 5
h3d/Matrix.hx

@@ -229,8 +229,8 @@ class Matrix {
 		multiply(this, tmp);
 	}
 
-	public inline function getPosition( ?v : Vector ) {
-		if( v == null ) v = new Vector();
+	public inline function getPosition() {
+		var v = new Vector();
 		v.set(_41,_42,_43,_44);
 		return v;
 	}
@@ -253,9 +253,8 @@ class Matrix {
 		_44 = vw;
 	}
 
-	public inline function getScale(?v: h3d.Vector) {
-		if(v == null)
-			v = new Vector();
+	public inline function getScale() {
+		var v = new Vector();
 		v.x = Math.sqrt(_11 * _11 + _12 * _12 + _13 * _13);
 		v.y = Math.sqrt(_21 * _21 + _22 * _22 + _23 * _23);
 		v.z = Math.sqrt(_31 * _31 + _32 * _32 + _33 * _33);

+ 1 - 1
h3d/pass/PointShadowMap.hx

@@ -83,7 +83,7 @@ class PointShadowMap extends Shadows {
 		pshader.shadowMap = texture;
 		pshader.shadowBias = bias;
 		pshader.shadowPower = power;
-		light.getAbsPos().getPosition(pshader.lightPos);
+		pshader.lightPos = light.getAbsPos().getPosition();
 		pshader.zFar = pointLight.range;
 
 		// ESM

+ 1 - 2
h3d/scene/Object.hx

@@ -846,9 +846,8 @@ class Object {
 		Set the position, scale and rotation of the object relative to its parent based on the specified transform matrix.
 	**/
 	static var tmpMat = new h3d.Matrix();
-	static var tmpVec = new h3d.Vector();
 	public function setTransform( mat : h3d.Matrix ) {
-		var s = mat.getScale(tmpVec);
+		var s = mat.getScale();
 		this.x = mat.tx;
 		this.y = mat.ty;
 		this.z = mat.tz;

+ 1 - 2
h3d/scene/Skin.hx

@@ -94,7 +94,6 @@ class Skin extends MultiMaterial {
 		return s;
 	}
 
-	static var tmpVec = new h3d.Vector();
 	override function getBoundsRec( b : h3d.col.Bounds ) {
 		// ignore primitive bounds !
 		var old = primitive;
@@ -106,7 +105,7 @@ class Skin extends MultiMaterial {
 		syncJoints();
 		if( skinData.vertexWeights == null )
 			cast(primitive, h3d.prim.HMDModel).loadSkin(skinData);
-		var absScale = getAbsPos().getScale(tmpVec);
+		var absScale = getAbsPos().getScale();
 		var scale = Math.max(Math.max(absScale.x, absScale.y), absScale.z);
 		for( j in skinData.allJoints ) {
 			if( j.offsetRay < 0 ) continue;