Crystal Space
Welcome, Guest. Please login or register.
October 25, 2014, 12:39:56 am

Login with username, password and session length
Search:     Advanced search
9011 Posts in 2044 Topics by 8817 Members
Latest Member: Natsaw1610
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  General Crystal Space Discussion
| | |-+  How to color a mesh (wrapper)?
« previous next »
Pages: [1] Print
Author Topic: How to color a mesh (wrapper)?  (Read 2529 times)
kornerr
Full Member
***
Posts: 101


347968356
View Profile WWW Email
« on: May 11, 2006, 05:42:47 am »

I'm doing this:
Code:
obj_state->SetMaterialWrapper (null_mw);
obj_state->SetManualColors (true);
obj_state->SetColor (csColor (random () % 256, random () % 256, random () % 256));
null_mw is 1x1 png of white color. I texture map it every polygon, then I try to color it, but it doesn't work. I tried to do without setting material wrapper, but app segfaults then. So how to color a mesh (wrapper)?

All I get when loading an X3D model is this: http://kornerr.users.kemcity.ru/pictures/single_colored_X3D_model_8bpp.png

Thanks.
Logged

jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: May 11, 2006, 07:11:15 am »

Did you disable lighting? Also disable manual colors. I think the best thing to do is to disable lighting and manual colors. Then SetColor() should work.

Greetings,
Logged
kornerr
Full Member
***
Posts: 101


347968356
View Profile WWW Email
« Reply #2 on: May 11, 2006, 11:11:25 am »

I SetLighting (false) and SetManualColors (false), but all is the same. I even tried this functions upon MeshFactoryState (previously tried on MeshState), still no success.
What to do?

Thanks.
Logged

jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: May 11, 2006, 12:17:39 pm »

I SetLighting (false) and SetManualColors (false), but all is the same. I even tried this functions upon MeshFactoryState (previously tried on MeshState), still no success.
What to do?

Thanks.

Can you show me a bit more code?

Greetings,
Logged
kornerr
Full Member
***
Posts: 101


347968356
View Profile WWW Email
« Reply #4 on: May 11, 2006, 12:51:27 pm »

Code:
        X3DDocument x3d_doc ("/this/models/workspace.x3d", obj_reg);

        vector<X3DTransform> transforms = x3d_doc.GetTransforms ();
        const int NUM_OF_OBJS = transforms.size ();

        cout << "num of trans = " << NUM_OF_OBJS << endl;

        csRefArray <iMeshFactoryWrapper> x3d_objs_fact (NUM_OF_OBJS);
        csRefArray <iGeneralFactoryState> x3d_objs_fact_states (NUM_OF_OBJS);

        for (int i = 0; i < NUM_OF_OBJS; i++) {
                csRef<iMeshFactoryWrapper> fw_tmp;
                csRef<iGeneralFactoryState> fws_tmp;

                fw_tmp = engine->CreateMeshFactory ("crystalspace.mesh.object.genmesh",
                                "one_of_obj_facts");
                x3d_objs_fact[i] = fw_tmp;
                fws_tmp = scfQueryInterface<iGeneralFactoryState> (
                                x3d_objs_fact[i]->GetMeshObjectFactory ());
                x3d_objs_fact_states[i] = fws_tmp;

                x3d_objs_fact_states[i]->SetLighting (false);
                x3d_objs_fact_states[i]->SetManualColors (false);

                // Add vetices and triangles

                vector<csVector3> vertices = transforms[i].GetVertices ();
                vector<csTriangle> tris = transforms[i].GetTris ();

                for (int j = 0; j < vertices.size (); j++) {
                        x3d_objs_fact_states[i]->AddVertex (
                                        csVector3 (vertices[j].x, vertices[j].y, vertices[j].z),
                                        csVector2 (0, 1), csVector3 (1, 1, 1), csColor4 (1, 1, 1, 1)
                                        );
                }
                for (int j = 0; j < tris.size (); j++) {
                        x3d_objs_fact_states[i]->AddTriangle (
                                        csTriangle (tris[j].a, tris[j].b, tris[j].c)
                                        );
                }
                x3d_objs_fact_states[i]->CalculateNormals ();

                csVector3 translation = transforms[i].GetTranslation ();

                csRef<iMeshWrapper> obj = engine->CreateMeshWrapper (x3d_objs_fact[i],
                                "obj", room, csVector3 (0 + translation.x, 20 + translation.y,
                                        0 + translation.z));
                csRef<iGeneralMeshState> obj_state = scfQueryInterface<iGeneralMeshState> (                                obj->GetMeshObject ());

                obj_state->SetMaterialWrapper (null_mw);
                csRandomGen rnd;
                cout << "rnd.Get = " << rnd.Get () << endl;
                obj_state->SetColor (csColor (rnd.Get (), rnd.Get (), rnd.Get ()));
                cout << "IsManualColors = " << obj_state->IsManualColors () << endl;
                cout << "IsLighting = " << obj_state->IsLighting () << endl;
        }
« Last Edit: May 11, 2006, 01:19:37 pm by kornerr » Logged

Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.321 seconds with 15 queries.