Ignore:
Timestamp:
02/17/07 22:48:12 (17 years ago)
Author:
mattausch
Message:

worded on obj loading in Ogre

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp

    r2122 r2123  
    88#include "PreprocessorFactory.h" 
    99#include "OgreLogManager.h" 
     10#include "ObjManualMeshLoader.h" 
    1011 
    1112 
     
    1718 
    1819ObjReader::~ObjReader() 
    19 {} 
     20{ 
     21        CLEAR_CONTAINER(mPvsObjects); 
     22} 
    2023 
    2124 
     
    3134        // hack 
    3235        preprocessor->mLoadMeshes = false; 
    33         GtpVisibilityPreprocessor::ObjectContainer pvsObjects; 
    3436 
    35         Ogre::LogManager::getSingleton().logMessage("loading obj scene!!"); 
     37        Ogre::LogManager::getSingleton().logMessage("loading obj scene"); 
    3638 
    3739        if (preprocessor->LoadScene(sceneName)) 
     
    3941                Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects"); 
    4042                // form objects from the scene triangles 
    41                 if (!preprocessor->LoadObjects(visibilitySolution, pvsObjects, preprocessor->mObjects)) 
     43                if (!preprocessor->LoadObjects(visibilitySolution, mPvsObjects, preprocessor->mObjects)) 
    4244                { 
    4345                        Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded"); 
     
    5254 
    5355        std::stringstream d;  
    54         d << "successfully loaded " << pvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects"; 
     56        d << "successfully loaded " << mPvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects"; 
    5557 
    5658        Ogre::LogManager::getSingleton().logMessage(d.str()); 
    5759 
    58         GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = pvsObjects.end(); 
     60        GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 
    5961 
    6062        int i = 0; 
    61         for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i) 
     63        for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit, ++ i) 
    6264        { 
    63                 Ogre::LogManager::getSingleton().logMessage("r"); 
     65                if (i % 5000 == 4999) 
     66                { 
     67                        d << i << " objects created" << endl; 
     68                } 
     69         
    6470                const Ogre::String entname = "Object" + Ogre::StringConverter::toString(i); 
    6571 
    66                 Ogre::ManualObject *ent = CreateEntity(entname, *oit); 
     72#if 0 
     73                Ogre::ManualObject *ent = CreateManualObject(entname, *oit); 
     74#else 
     75                Ogre::Entity *ent = CreateEntity(entname, *oit); 
     76#endif 
    6777 
    6878                const Ogre::String nodeName = entname + "Node"; 
     
    7080                node->attachObject(ent); 
    7181 
    72                 if (i > 100) 
    73                         break; 
     82                // problems for too many objects (= vbo)? 
     83                //if (i > 30000)break; 
    7484        } 
    7585 
     
    8999        std::string entityName = name + "Entity"; 
    90100 
    91 GtpVisibilityPreprocessor::BvhLeaf *bvhObj =  
     101        GtpVisibilityPreprocessor::BvhLeaf *bvhObj =  
    92102                static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object); 
     103 
    93104        const int vertexCount = (int)bvhObj->mObjects.size() * 3; 
    94105 
    95106        ManualObject* manual = mSceneManager->createManualObject(entityName); 
    96         manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); 
     107        manual->begin("BaseWhite", RenderOperation::OT_TRIANGLE_LIST); 
    97108         
     109        const float red = GtpVisibilityPreprocessor::Random(1.0f); 
     110        const float green = GtpVisibilityPreprocessor::Random(1.0f); 
     111        const float blue = GtpVisibilityPreprocessor::Random(1.0f); 
     112 
    98113        // create vertices 
    99          
    100         GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end(); 
     114        GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit,  
     115                oit_end = bvhObj->mObjects.end(); 
    101116         
    102117        for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) 
     
    110125                { 
    111126                        const GtpVisibilityPreprocessor::Vector3 vtx = tri.mVertices[i]; 
     127                        const GtpVisibilityPreprocessor::Vector3 n = tri.GetNormal(); 
     128 
    112129                        manual->position(vtx.x, vtx.y, vtx.z); 
    113                         manual->colour(1.0f, 0.0f, 0.0f); 
     130                        manual->normal(n.x, n.y, n.z); 
     131                        //manual->colour(red, green, blue); 
    114132                } 
    115133        } 
    116134 
     135        if (0) 
    117136        for (int i = 0; i < vertexCount; ++ i) 
    118137        { 
    119138                manual->index(i); 
    120139        } 
     140 
     141        manual->end(); 
    121142 
    122143        return manual; 
     
    137158        std::string entityName = name + "Entity"; 
    138159 
    139         MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "Custom"); 
    140         SubMesh* submesh = mesh->createSubMesh(); 
     160        ObjManualMeshLoader *loader = new ObjManualMeshLoader(bvhObj); 
    141161 
    142         const int vertexCount = (int)bvhObj->mObjects.size() * 3; 
    143  
    144         // We must create the vertex data, indicating how many vertices there will be 
    145         submesh->useSharedVertices = false; 
    146         submesh->vertexData = new VertexData(); 
    147         submesh->vertexData->vertexStart = 0; 
    148         submesh->vertexData->vertexCount = vertexCount; 
    149  
    150         std::stringstream d; d << "objects: " << bvhObj->mObjects.size() << " vtx: " << submesh->vertexData->vertexCount << endl; 
    151         Ogre::LogManager::getSingleton().logMessage(d.str()); 
    152  
    153         static const unsigned short source = 0; 
    154         size_t offset = 0; 
    155  
    156         VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 
    157  
    158         offset += declaration->addElement(source, offset, VET_FLOAT3, VES_POSITION).getSize(); 
    159         //offset += declaration->addElement(source, offset, VET_FLOAT3,VES_NORMAL).getSize(); 
    160         //offset += declaration->addElement(source, offset, VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); 
    161  
    162  
    163         int numVertices = 0; 
    164  
    165         HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton(). 
    166                 createVertexBuffer(declaration->getVertexSize(source), 
    167                                                    submesh->vertexData->vertexCount, 
    168                                                    HardwareBuffer::HBU_STATIC_WRITE_ONLY); 
    169  
    170     // No we get access to the buffer to fill it.  During so we record the bounding box. 
    171         AxisAlignedBox aabox; 
    172  
    173         float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); 
    174  
    175         GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end(); 
    176  
    177         for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) 
    178         { 
    179                 GtpVisibilityPreprocessor::TriangleIntersectable *tObj =  
    180                         static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit); 
    181                  
    182                 GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem(); 
    183  
    184                 for (int i = 0; i < 3; ++ i) 
    185                 { 
    186                         Vector3 vtx = Vector3(tri.mVertices[i]); 
    187  
    188                         *vdata ++ = vtx.x; 
    189                         *vdata ++ = vtx.y; 
    190                         *vdata ++ = vtx.z; 
    191  
    192                         //std::stringstream d; d << vtx; 
    193                         //Ogre::LogManager::getSingleton().logMessage(d.str()); 
    194                         aabox.merge(vtx); 
    195                 } 
    196         } 
    197         //Ogre::LogManager::getSingleton().logMessage("***"); 
    198         vbuffer->unlock(); 
    199          
    200         /*Ogre::RenderOperation rop; 
    201         submesh->_getRenderOperation(rop); 
    202         rop.useIndexes = false; 
    203 */ 
    204         ////// 
    205         //-- Creates the index data 
    206  
    207     submesh->vertexData->vertexBufferBinding->setBinding(source, vbuffer); 
    208  
    209         submesh->indexData->indexStart = 0; 
    210         // we use an index for every vertex 
    211         submesh->indexData->indexCount = vertexCount; 
    212         submesh->indexData->indexBuffer = 
    213             HardwareBufferManager::getSingleton(). 
    214                         createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 
    215                                                           submesh->indexData->indexCount, 
    216                                                           HardwareBuffer::HBU_STATIC_WRITE_ONLY); 
    217         submesh->operationType = RenderOperation::OT_LINE_STRIP; 
    218         //uint16* idata = static_cast<uint16*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); 
    219     unsigned short* idata = static_cast<unsigned short*>(submesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); 
    220  
    221         for (int j = 0; j < vertexCount; ++ j) 
    222     { 
    223                 *idata = j; 
    224                 ++ idata; 
    225     } 
    226      
    227         submesh->indexData->indexBuffer->unlock(); 
    228  
    229         submesh->setMaterialName("BaseWhiteNoLighting");  
    230  
    231         // We must indicate the bounding box 
    232         mesh->_setBounds(aabox);  
    233         mesh->_setBoundingSphereRadius((aabox.getMaximum() - aabox.getMinimum()).length() / 2.0);  
    234         mesh->load(); 
    235         mesh->touch(); 
     162        Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup", loader).getPointer();  
     163        pMesh->load();  
    236164 
    237165        // Create an entity with the mesh 
    238166        entity = mSceneManager->createEntity(entityName, meshName); 
    239167 
    240         //entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); 
     168        return entity; 
     169} 
    241170 
    242         return entity; 
    243 #endif 
    244 } 
Note: See TracChangeset for help on using the changeset viewer.