CompositeMaterial for 4.0

Software: Away3D 4.x

Avatar
Choons, Sr. Member
Posted: 24 September 2011 06:07 AM   Total Posts: 281

it’s good. we need it. can we have it?

   

Richard Olsson, Administrator
Posted: 24 September 2011 01:23 PM   Total Posts: 1192   [ # 1 ]

What do you need it for? In 3.6, The composite material was mainly used to enable shading (using a shading material) on a material that otherwise didn’t support it. That’s no longer required in Away 4 where any material can have any shading method, and even daisy chain some of the methods.

If you can please explain the use case, it might be easier to assess whether it is something that we want to add, or if there is maybe some better way of doing it.

   

Avatar
Choons, Sr. Member
Posted: 24 September 2011 05:56 PM   Total Posts: 281   [ # 2 ]

Alejandro mentioned shading as well in a different thread, but I only ever saw it as a way to use several different materials dynamically on a single model at once. I used CompositeMaterial in a garment configurator design. The fabric texture of the garment needed to be tiled onto the model and UV scaled down to retain fine detail on zooming. The user then could choose graphic elements to add to the garment and could position, rotate, and scale them anywhere on the garment they please. The graphics require a material that is not set to repeat in contrast to the fabric texture material. Other details like stitching or zippers could be added as well.

So I used CompositeMaterial as a container much the way ObjectContainer3D is used except for multiple TransformBitmapMaterial and regular BitmapMaterials so that they could all be easily applied to the same model and manipulated individually.

Flash’s BitmapData & matrix transform stuff can handle some of that, but it’s a lot harder to use. Also there is no way to composite it all together with an underlying fabric texture. Trust me I’ve tried, it just washes out all detail unless you use some kind of absurdly huge bitmap and even then looks awful. Fabric texture really requires UV scaling and tiling by itself. So at the very least 2 materials are required for this- one with repeat turned on and one with repeat off.

I welcome any suggestions of a way to do it in 4.0. I’ve considered perhaps splatting layers. It just seems like CompositeMaterial made stuff like this so easy to do that I am amazed the devs don’t think it’s useful to port over to 4.0

   

Richard Olsson, Administrator
Posted: 24 September 2011 06:05 PM   Total Posts: 1192   [ # 3 ]

First of all, UV coordinates are attributes of the geometry, and has nothing to do with the materials. Now that we are on the GPU there is no real way of faking that. This means that the only real way to solve what you’re after (one repeated texture with scaled UVs, one without) is to have multiple UV channels. That’s something that is possible already, but you likely won’t find a transfer format that lets you just parse it into Away3D. So consider either using separate meshes, or exporting the extra UV channel on your own somehow and adding it after you have loaded your meshes.

Your use of the CompositeMaterial is an interesting case, but it is likely not a good idea when you’re working on the GPU.

   

Avatar
Choons, Sr. Member
Posted: 24 September 2011 06:14 PM   Total Posts: 281   [ # 4 ]

well it’s going to be a basic need for product configurators to layer on graphics elements like that. If it’s impossible to do on hardware then that’s one thing, but it is quite useful.

I don’t know how multiple UV channels was “faked” in 3.6 but it sure allows for for some very cool things that cannot be done in 4.0

   

Richard Olsson, Administrator
Posted: 24 September 2011 06:42 PM   Total Posts: 1192   [ # 5 ]

You’re probably right about the need to achieve this kind of thing. And the best way to do it is probably using multiple UV channels.

   

John Brookes, Moderator
Posted: 24 September 2011 06:43 PM   Total Posts: 732   [ # 6 ]

Can’t you just add a new subgeometry for each layer?
I done an animated tiled png on top of a fixed bitmapmaterial, worked, just didnt take it fiurther.

   

Avatar
Choons, Sr. Member
Posted: 24 September 2011 07:58 PM   Total Posts: 281   [ # 7 ]

@John I’d love to see a demo and some source code for that to see if it can do what I used CompositeMaterial for.

   

John Brookes, Moderator
Posted: 25 September 2011 08:05 AM   Total Posts: 732   [ # 8 ]

Just had a little play again.
You can’t use the default away scale UV as it works on all subGs, already had these UV functions from before they added scaleuV

Also, never noticed before, the images have to be created in reverse order. (background last) And im not talking about the animation thang.
If you had a background image and a transparent img on top, you have to create the transparent img first
No idea what thats about. (materialManager?)

The basics is
p = new Plane(bmMaterial,500,500);
scene.addChild(p);
 
Mesh(p).geometry.addSubGeometry(SubGeometry(Mesh(p).geometry.subGeometries[0]).clone());
Mesh(p).subMeshes[1].material = aMaterialYouCreatedEarlier


Anyhoo random messing looks like this
http://www.shrewballooba.co.uk/sgAnim/

private function initObjects():void
  {
   
var imgArr:Array = [new animAsset1().bitmapData
          new 
animAsset2().bitmapData
          new 
animAsset3().bitmapData
          new 
animAsset4().bitmapData
          new 
animAsset5().bitmapData
          new 
animAsset6().bitmapData
          new 
animAsset7().bitmapData
          new 
animAsset8().bitmapData
          new 
animAsset9().bitmapData
          new 
animAsset10().bitmapData
          new 
animAsset11().bitmapData]
   
var animBmMaterial:AnimatedBitmapMaterial = new AnimatedBitmapMaterial(nulltruetrue)
   
animBmMaterial.repeat true;
   
animBmMaterial.setMaps(imgArr);
   
animBmMaterial.alphaThreshold 0.5;
   
   
//background
   
var bmMaterial:BitmapMaterial = new BitmapMaterial(new imgAsset().bitmapData);
   
bmMaterial.repeat true;
   
   
= new Plane(bmMaterial,500,500);
   
scene.addChild(p);
   
   
Mesh(p).geometry.addSubGeometry(SubGeometry(Mesh(p).geometry.subGeometries[0]).clone());
   
Mesh(p).subMeshes[1].material =animBmMaterial
   incrementUV
(p1, new Point(0, -0.3));
   
   
Mesh(p).geometry.addSubGeometry(SubGeometry(Mesh(p).geometry.subGeometries[1]).clone());
   
Mesh(p).subMeshes[2].material =animBmMaterial
   scaleUV
(p2, new Point( -0.90.9));
   
animBmMaterial.play();
   
   
scaleUV(p0, new Point(22));
  
}
  
  
private function scaleUV(m:Mesh,SubMeshIndex:intscale:Point):void
  {
   
var v:Vector.<Number> = SubGeometry(m.geometry.subGeometries[SubMeshIndex]).UVData;
   for (var 
i:int 0v.lengthi=i+2)
   
{
    v[i] 
*= scale.x;
    
v[i 1] *= scale.y;
    
SubGeometry(m.geometry.subGeometries[SubMeshIndex]).updateUVData(v);
   
}
  }
  
  
private function incrementUV(m:Mesh,SubMeshIndex:intpos:Point):void
  {
   
var v:Vector.<Number> = SubGeometry(m.geometry.subGeometries[SubMeshIndex]).UVData;
   for (var 
i:int 0v.lengthi=i+2)
   
{
    v[i] 
+= pos.x;
    
v[i 1] += pos.y;
    
SubGeometry(m.geometry.subGeometries[SubMeshIndex]).updateUVData(v);
   
}
  }
  
  
private function handleEnterFrame(e:Event):void 
  {
   incrementUV
(p1, new Point(-0.020));
   
incrementUV(p2, new Point( -0.0210));

   
view.render();
  

No idea if the above has anything to do with what you wanted :/

   

Avatar
Choons, Sr. Member
Posted: 25 September 2011 08:31 AM   Total Posts: 281   [ # 9 ]

man, thanks for exploring it like that. Yeah I was really against the change of moving the UV ops from being a material property a while back for this reason. Your approach gives back the flexibility of the old system. Nicelly done!

So yeah the usefulness of being able to layer on content like that seems pretty apparent to me. Good to know there is a way to do it apart from Flash’s bitmap ops. Now let’s see if it makes it into the framework proper. Thanks, John wink

 

   

Avatar
Choons, Sr. Member
Posted: 25 September 2011 08:35 AM   Total Posts: 281   [ # 10 ]

@John - when you use a Point as a parameter in scaleUV I assume it’s a shorthand way to pass in scaleX & scaleY values?

   

John Brookes, Moderator
Posted: 25 September 2011 09:07 AM   Total Posts: 732   [ # 11 ]

Yeah, could have added U and V parameters (x,y) to the function or even a vector3D without the z. Just used point.

   

John Brookes, Moderator
Posted: 25 September 2011 09:56 AM   Total Posts: 732   [ # 12 ]

Just found an old post from when I first started playing with UVs in broomstick.
The scale in this one scales from center (i think) also a rotation at the end of the thread.

http://groups.google.com/group/away3d-dev/browse_thread/thread/5aa45c305514a626/8f62004e732cae21?lnk=gst

   

inSertCodE, Sr. Member
Posted: 18 November 2011 12:36 AM   Total Posts: 105   [ # 13 ]
Richard Olsson - 24 September 2011 06:42 PM

You’re probably right about the need to achieve this kind of thing. And the best way to do it is probably using multiple UV channels.

Sorry to bump this… How can we create a second UVW channel?

The method used below works great and does the job but it has a downside. It doubles the geometry vertex/faces/ UVW coordinates ect.
If we add a second channel only UVW coordinates will be doubled.
Am I correct?

You mentioned there is a way to add a second UVW channel so I would appreciate it if you share with us how.

Thanks.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X