Friday, June 8, 2012

Cubic vs. Planar Meshes in Cubes

‹prev | My Chain | next›

I continue my exploration of 3D mapping in the browser with a closer look at the projectMode setting in the Gladius game engine. As I am finding, this is not so much a Gladius setting, but rather a CubicVR.js setting. Gladius terms components like CubicVR.js as "backends" (even those many of these backends consider themselves engines as well).

As mentioned last night, I suspect that my working example is not really a cubic projection:
  var mesh =
  {
    // ...
    uvmapper: {
      projectionMode: "cubic",
      scale: [1, 1, 1]
    }
  };
Rather, I think that I am building the faces as individual planes. So I change the project mode to "planar":
  var mesh =
  {
    // ...
    uvmapper: {
      projectionMode: "planar",
      scale: [1, 1, 1]
    }
  };
Reloading my deformed pyramid, I find it unchanged. All of the faces are still covered in my vertex-colored texture image:



So it seems reasonable to conclude that, even though I had specified a cubic projection mode, I am treating it as a plain-old planar projection. That does not help me understand what cubic projection is. To get a better understanding, I dig into CubicVR.js a bit more.

The CubicVR.js project is quite well documented and includes many samples including a "cubic" projection mode example. The sample source code makes use of a box "primitive":
                var boxMesh = new CubicVR.Mesh({
                    primitive: {
                        type: "box",
                        size: 1.0,
                        material: boxMaterial,
                        uvmapper: {
                            projectionMode: "cubic",
                            scale: [1, 1, 1]
                        }
                    },
                    compile: true
                });
I cannot find primitive shapes in Gladius (actually, they are in the gladius-cubicvr.js extension), but they definitely exist in CubicVR.js. To better understand the cubic projection mode, I am going to manually code the settings produced in CubicVR.js' cubicvr_boxObject method.

The points, faces and UV mapper end up being about what I originally pulled in from the Gladius samples:
  var mesh =
  {
    points: [
      [ point, -point,  point],
      [ point,  point,  point],
      [-point,  point,  point],
      [-point, -point,  point],
      [ point, -point, -point],
      [ point,  point, -point],
      [-point,  point, -point],
      [-point, -point, -point]
    ],
    faces: [
      [0, 1, 2, 3],
      [7, 6, 5, 4],
      [4, 5, 1, 0],
      [5, 6, 2, 1],
      [6, 7, 3, 2],
      [7, 4, 0, 3]
    ],
    uv: [ /* ... ? ... */ ],
    uvmapper: {
      projectionMode: "cubic",
      scale: [1, 1, 1]
    }
  };
This leaves me with the UV mapping. I find this a little confusing to work through, but if I have this right, the UV mapping works out to... exactly what I got from the original Gladius sample:
// ...
    uv: [
      [ [1, 0], [0, 0], [0, 1], [1, 1] ],
      [ [1, 0], [0, 0], [0, 1], [1, 1] ],
      [ [1, 0], [0, 0], [0, 1], [1, 1] ],
      [ [1, 0], [0, 0], [0, 1], [1, 1] ],
      [ [1, 0], [0, 0], [0, 1], [1, 1] ],
      [ [1, 0], [0, 0], [0, 1], [1, 1] ]
    ],
// ...
Sigh... so I think that I mistook the cubic projection mode (no surprise there). I had come to think that somehow it took the image (or whatever the material was) and wrapped it around the entire mesh. In fact, it seems that it still fits the material to each face, but calculates the "normal" (the side facing out) differently. In planar, it needs to be explicitly set. In cubic, it is determined based on the rotation of the faces, as I found the other night.



Day #411

No comments:

Post a Comment