Monday, September 16, 2013

Wrapping up

As the Google summer of code (Gsoc) is drawing to an end, I've been spending the past week polishing the library in its current state rather than trying to rush through any new features through. To recap, the port Cocos3D-XNA currently has support for:


  • creation of orthographic/perspective cameras
  • animatable camera properties (position, zooming etc)
  • configurable materials (multi-texturing, ambient/specular/diffuse/emission colors)
  • integration with custom shaders
  • creation of primitive 3d meshes (spheres, cones, boxes and planes),
which overall I don't think is too shabby a foundation for the port on which to build upon.

Finally, no words can describe how grateful I am to both Google and Mono for this experience, so instead I'll leave them with this:




Monday, September 9, 2013

Primitive 3d shapes using CC3ParametricMeshes

In the past few weeks, we looked at how to load/use materials but I always glossed over how to create our drawing data when running through some examples. Well, no more! Using cocos3d's CC3ParametricMeshes we can painlessly create a collection of different 3d primitive shapes. First, we create our object as so

CC3ParametricMeshes mesh = new CC3ParametricMeshes(0, "myShape");

and then we specify the appropriate populate method for the particular shaper we're after that will load the corresponding locations, normals and tex coordinates. So, we could create a sphere by

// radius and tessellation
mesh.PopulateAsSphere(3.0f, new CC3Tessellation(50,50));

or a cone by calling

// base radius, height and tessellation
mesh.PopulateAsHollowCone(3.0f, 5.0f, new CC3Tessellation(50, 50));

and so on. Currently, within Cocos3D-XNA the CC3ParametricMeshes class additionally provides support for creating rectangles and planes.

Once we've populated our mesh, that's pretty much it with respect to our drawing data! It's just a matter of associating our mesh with a corresponding material and putting it altogether as seen below

Click to enlarge


Monday, September 2, 2013

CC3Material - part 2 (Multitexturing)

Continuing on from last week, we'll again look at the CC3Material class within Cocos3D-XNA and run through an example of how to add (multiple) textures to our materials. To begin, we load our texture files

CC3GraphicsTexture2D crateTexData = new CC3GraphicsTexture2D("Content/crate.jpg");
CC3GraphicsTexture2D logoTexData = new CC3GraphicsTexture2D("Content/logo.gif");

CC3Texture crateTexture = new LCC3Texture(0, "crate");
crateTexture.GraphicsTexture = crateTexData;

CC3Texture logoTexture = new LCC3Texture(1, "logo");
logoTexture.GraphicsTexture = logoTexData;

that are seen below



and then add these textures to our material

multiTexMaterial.AddTexture(crateTexture);
multiTexMaterial.AddTexture(logoTexture);

Finally, we need to specify how these textures are overlaid. This is done by setting the ivar TextureUnitMode in our texture objects which is of enum type CC3TextureUnitMode  that (currently) takes one of the following values

// replace src with dst
CC3TextureUnitMode.Replace,

// add src with dst
CC3TextureUnitMode.Add, 

// replace src with dst where alpha > 0.0
CC3TextureUnitMode.Decal, 

// mix src with dst using TextureUnitConstantColor
CC3TextureUnitMode.Blend 

Note, that the order of rendering of textures in a material is based on the order in which it's added. So typically the first texture added would have the  TextureUnitMode set to CC3TextureUnitMode.Replace. So for our example we would have

crateTexture.TextureUnitMode = CC3TextureUnitMode.Replace;

Then, for subsequent textures that are drawn on top of the initial texture, it's a matter of playing around with the different mixing effects. For the case of CC3TextureUnitMode.Blend a user is required to additionally set a texture object's TextureUnitConstantColor ivar which can adjust the alpha of the source texture as well as overlay it with an additional hue.

Overall, in combination with the other different material/lighting attributes talked about last week, you can get some pretty nice effects as seen below

Click to enlarge