About Store Forum Documentation Contact



Post Reply 
Welding and optimizing meshes
Author Message
andargor Offline
Member

Post: #1
Welding and optimizing meshes
I have been trying to optimize this object using welding:

http://screencast.com/t/tZGaBhzNhX

The result is this:

http://screencast.com/t/AVrPdSeUYC

Notice how the specularity of the box has been changed, and the sides flicker as well (you can't see it well in the video).

Basically, I would like to join the two shapes and only keep the outside for optimization reasons. This is my code, what am I doing wrong? Also, I'm probably doing unnecessary things, please point them out if you see them.

PHP Code:
        MaterialPtr mat = new Material();
        
mat->color Vec4(0.2f,0.2f,0.7f,0.7f); // blue
        
mat->ambient Vec(0.2f,0.2f,0.2f);
        
mat->specular 0.5f;
        
mat->validate();

        
MaterialPtr mat2 = new Material();
        
mat2->color Vec4(0.7f,0.2f,0.2f,0.7f); // red
        
mat2->ambient Vec(0.2f,0.2f,0.2f);
        
mat2->specular 0.5f;
        
mat2->validate();

        
MeshPtr mesh = new Mesh();
        
mesh->setAutoTanBin();

        
MeshPart *mp1 = &mesh->parts.New();
        
mp1->base.create(Box(0.3f),VTX_TEX0|VTX_NRM|VTX_TNG);
        
mp1->setMaterial(mat); // blue cube
        
        
MeshPart *mp2 = &mesh->parts.New();
        
mp2->base.create(Ball(0.3f,Vec(0.1f,0.1f,0.1f)),VTX_TEX0|VTX_NRM|VTX_TNG);
        
mp2->setMaterial(mat2); // red ball
        //mesh->setMaterial(Materials.ptrRequire("data/mtrl/brick/0.mtrl")).setRender().setBox();
        
mesh->weldVtx().setAdjacencies();
        
mesh->removeDegenerateFaces().removeUnusedVtxs().setNormals();
        
mesh->setShader().setRender().setBox();

        
PhysBodyPtr pb = new PhysBody();
        
pb->parts.New().create(mesh->box);

        
File f;
        
f.write("ship.mesh");
        
mesh->save(f);

        
Game::ObjParams obj;
        
obj.type(true"OBJ_VEHICLE");
        
obj.mesh(truemesh);
        
obj.phys(truepb);

        
Game::Obj *Game::World.objCreateNear(obj,Matrix(obj.scale(),Vec(0,0,0))); 
04-26-2011 03:55 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Welding and optimizing meshes
I think you'll want to use CSG: "EsenthelEngineSDK\Tutorials\Source\Advanced\3 - Mesh, Shaders\Mesh\Constructive Solid Geometry (CSG).cpp"
04-26-2011 04:23 AM
Find all posts by this user Quote this message in a reply
andargor Offline
Member

Post: #3
RE: Welding and optimizing meshes
Thanks! I looked into it and it has 2 problems:

1) Even with SEL_XOR, the vtx/tri/quad count didn't decrease (just for kicks, I also tried SEL_SUB the SEL_AND from the SEL_ADD... no dice)

2) The material from each part doesn't survive

I'll keep digging...

EDIT: The flickering is from the shadows
(This post was last modified: 04-27-2011 02:23 AM by andargor.)
04-27-2011 02:18 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #4
RE: Welding and optimizing meshes
To be honest, I'm not sure how the optimizing works; but I doubt it will automatically figure out your sphere is partially in the box and delete those faces.
04-27-2011 06:51 AM
Find all posts by this user Quote this message in a reply
andargor Offline
Member

Post: #5
RE: Welding and optimizing meshes
(04-27-2011 06:51 AM)Tottel Wrote:  To be honest, I'm not sure how the optimizing works; but I doubt it will automatically figure out your sphere is partially in the box and delete those faces.

Doesn't it do it on the fly with Frustum? All I'm looking for is something that will allow me to remove (cull) hidden vertices from the mesh. In this example, the result will have 2 parts, each with their materials, one is a box with a missing corner and the other part of a sphere, welded together. (or 3 parts if you count that small floating corner).
04-27-2011 02:42 PM
Find all posts by this user Quote this message in a reply
Post Reply