Переглянути джерело

added h3d.mat.Material.create shortcut

ncannasse 7 роки тому
батько
коміт
1085a5c641
4 змінених файлів з 16 додано та 7 видалено
  1. 10 0
      h3d/mat/Material.hx
  2. 2 3
      hxd/fmt/fbx/Library.hx
  3. 2 2
      samples/Base3D.hx
  4. 2 2
      samples/Stencil.hx

+ 10 - 0
h3d/mat/Material.hx

@@ -331,4 +331,14 @@ class Material extends BaseMaterial {
 	}
 	#end
 
+	/*
+		Shortcut to create a material for the current renderer setup using the specific diffuse texture.
+	*/
+	public static function create( ?tex : h3d.mat.Texture ) {
+		var mat = h3d.mat.MaterialSetup.current.createMaterial();
+		mat.texture = tex;
+		mat.props = mat.getDefaultProps();
+		return mat;
+	}
+
 }

+ 2 - 3
hxd/fmt/fbx/Library.hx

@@ -3,7 +3,6 @@ using hxd.fmt.fbx.Data;
 
 class Library extends BaseLibrary {
 
-
 	public function makeObject( ?textureLoader : String -> FbxNode -> h3d.mat.Material ) : h3d.scene.Object {
 		var scene = new h3d.scene.Object();
 		var hgeom = new Map();
@@ -14,7 +13,7 @@ class Library extends BaseLibrary {
 			textureLoader = function(_,_) {
 				if( tmpTex == null )
 					tmpTex = h3d.mat.Texture.fromColor(0xFF00FF);
-				return new h3d.mat.Material(tmpTex);
+				return h3d.mat.Material.create(tmpTex);
 			}
 		}
 
@@ -57,7 +56,7 @@ class Library extends BaseLibrary {
 				while( tmats.length > lastAdded )
 					tmats.pop();
 				if( tmats.length == 0 )
-					tmats.push(new h3d.mat.Material(h3d.mat.Texture.fromColor(0xFF00FF)));
+					tmats.push(h3d.mat.Material.create(h3d.mat.Texture.fromColor(0xFF00FF)));
 				// create object
 				if( tmats.length == 1 )
 					o.obj = new h3d.scene.Mesh(prim, tmats[0], scene);

+ 2 - 2
samples/Base3D.hx

@@ -27,13 +27,13 @@ class Base3D extends SampleApp {
 		var tex = hxd.Res.hxlogo.toTexture();
 
 		// create a material with this texture
-		var mat = new h3d.mat.Material(tex);
+		var mat = h3d.mat.Material.create(tex);
 
 		// our first cube mesh on the 3D scene with our created material
 		obj1 = new Mesh(prim, mat, s3d);
 
 		// creates another cube, this time with no texture
-		obj2 = new Mesh(prim, new h3d.mat.Material(), s3d);
+		obj2 = new Mesh(prim, s3d);
 
 		// set the second cube color
 		obj2.material.color.setColor(0xFFB280);

+ 2 - 2
samples/Stencil.hx

@@ -17,12 +17,12 @@ class Stencil extends hxd.App {
 		var tex = hxd.Res.hxlogo.toTexture();
 
 		{	// create the top cube
-			var obj = new Mesh(prim, new h3d.mat.Material(tex), root);
+			var obj = new Mesh(prim, h3d.mat.Material.create(tex), root);
 			obj.material.mainPass.enableLights = true;
 		}
 
 		{	// create the cube reflection
-			var obj = new Mesh(prim, new h3d.mat.Material(tex), root);
+			var obj = new Mesh(prim, h3d.mat.Material.create(tex), root);
 			obj.scaleZ = -1;
 			obj.material.color.setColor(0x55C8FF);