Browse Source

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

clandrin 3 years ago
parent
commit
3ffbb91590
4 changed files with 7 additions and 10 deletions
  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);
 		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);
 		v.set(_41,_42,_43,_44);
 		return v;
 		return v;
 	}
 	}
@@ -253,9 +253,8 @@ class Matrix {
 		_44 = vw;
 		_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.x = Math.sqrt(_11 * _11 + _12 * _12 + _13 * _13);
 		v.y = Math.sqrt(_21 * _21 + _22 * _22 + _23 * _23);
 		v.y = Math.sqrt(_21 * _21 + _22 * _22 + _23 * _23);
 		v.z = Math.sqrt(_31 * _31 + _32 * _32 + _33 * _33);
 		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.shadowMap = texture;
 		pshader.shadowBias = bias;
 		pshader.shadowBias = bias;
 		pshader.shadowPower = power;
 		pshader.shadowPower = power;
-		light.getAbsPos().getPosition(pshader.lightPos);
+		pshader.lightPos = light.getAbsPos().getPosition();
 		pshader.zFar = pointLight.range;
 		pshader.zFar = pointLight.range;
 
 
 		// ESM
 		// 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.
 		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 tmpMat = new h3d.Matrix();
-	static var tmpVec = new h3d.Vector();
 	public function setTransform( mat : h3d.Matrix ) {
 	public function setTransform( mat : h3d.Matrix ) {
-		var s = mat.getScale(tmpVec);
+		var s = mat.getScale();
 		this.x = mat.tx;
 		this.x = mat.tx;
 		this.y = mat.ty;
 		this.y = mat.ty;
 		this.z = mat.tz;
 		this.z = mat.tz;

+ 1 - 2
h3d/scene/Skin.hx

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