Ignore:
Timestamp:
02/15/07 19:09:13 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2119 r2122  
    5252 
    5353        std::stringstream d;  
    54         d << "successfully loaded " << pvsObjects.size() << " objects"; 
     54        d << "successfully loaded " << pvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects"; 
    5555 
    5656        Ogre::LogManager::getSingleton().logMessage(d.str()); 
     
    6060        int i = 0; 
    6161        for (oit = pvsObjects.begin(); oit != oit_end; ++ oit, ++ i) 
    62         {Ogre::LogManager::getSingleton().logMessage("r"); 
    63                 const Ogre::String entname = "Object" + i; 
    64  
    65                 Ogre::Entity *ent = CreateEntity(entname, *oit); 
    66  
    67                 const Ogre::String nodeName = entname + "/Node"; 
    68                 root->createChildSceneNode(nodeName); 
     62        { 
     63                Ogre::LogManager::getSingleton().logMessage("r"); 
     64                const Ogre::String entname = "Object" + Ogre::StringConverter::toString(i); 
     65 
     66                Ogre::ManualObject *ent = CreateEntity(entname, *oit); 
     67 
     68                const Ogre::String nodeName = entname + "Node"; 
     69                Ogre::SceneNode* node = root->createChildSceneNode(nodeName); 
     70                node->attachObject(ent); 
     71 
     72                if (i > 100) 
     73                        break; 
    6974        } 
    7075 
    7176        delete preprocessor; 
    7277 
    73         return false; 
     78        return true; 
     79} 
     80 
     81 
     82Ogre::ManualObject *ObjReader::CreateManualObject(const std::string &name, 
     83                                                                                                  GtpVisibilityPreprocessor::Intersectable *object) 
     84{ 
     85        using namespace Ogre; 
     86        //using namespace GtpVisibilityPreprocessor; 
     87 
     88        std::string meshName = name + ".mesh"; 
     89        std::string entityName = name + "Entity"; 
     90 
     91GtpVisibilityPreprocessor::BvhLeaf *bvhObj =  
     92                static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object); 
     93        const int vertexCount = (int)bvhObj->mObjects.size() * 3; 
     94 
     95        ManualObject* manual = mSceneManager->createManualObject(entityName); 
     96        manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); 
     97         
     98        // create vertices 
     99         
     100        GtpVisibilityPreprocessor::ObjectContainer::const_iterator oit, oit_end = bvhObj->mObjects.end(); 
     101         
     102        for (oit = bvhObj->mObjects.begin(); oit != oit_end; ++ oit) 
     103        { 
     104                GtpVisibilityPreprocessor::TriangleIntersectable *tObj =  
     105                        static_cast<GtpVisibilityPreprocessor::TriangleIntersectable *>(*oit); 
     106                 
     107                GtpVisibilityPreprocessor::Triangle3 tri = tObj->GetItem(); 
     108 
     109                for (int i = 0; i < 3; ++ i) 
     110                { 
     111                        const GtpVisibilityPreprocessor::Vector3 vtx = tri.mVertices[i]; 
     112                        manual->position(vtx.x, vtx.y, vtx.z); 
     113                        manual->colour(1.0f, 0.0f, 0.0f); 
     114                } 
     115        } 
     116 
     117        for (int i = 0; i < vertexCount; ++ i) 
     118        { 
     119                manual->index(i); 
     120        } 
     121 
     122        return manual; 
    74123} 
    75124 
     
    79128{ 
    80129        using namespace Ogre; 
    81         //using namespace GtpVisibilityPreprocessor; 
    82130 
    83131        Entity *entity; 
     
    86134                static_cast<GtpVisibilityPreprocessor::BvhLeaf *>(object); 
    87135 
    88         std::string meshName = name + "/Mesh"; 
    89         std::string entityName = name + "/Entity"; 
    90  
    91         MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup"); 
     136        std::string meshName = name + ".mesh"; 
     137        std::string entityName = name + "Entity"; 
     138 
     139        MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "Custom"); 
    92140        SubMesh* submesh = mesh->createSubMesh(); 
     141 
     142        const int vertexCount = (int)bvhObj->mObjects.size() * 3; 
    93143 
    94144        // We must create the vertex data, indicating how many vertices there will be 
     
    96146        submesh->vertexData = new VertexData(); 
    97147        submesh->vertexData->vertexStart = 0; 
    98         submesh->vertexData->vertexCount = (int)bvhObj->mObjects.size() * 3; 
     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()); 
    99152 
    100153        static const unsigned short source = 0; 
     
    103156        VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration(); 
    104157 
    105         offset += declaration->addElement(source, offset, VET_FLOAT3,VES_POSITION).getSize(); 
    106         //      offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize(); 
    107         //      offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); 
     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(); 
    108161 
    109162 
     
    113166                createVertexBuffer(declaration->getVertexSize(source), 
    114167                                                   submesh->vertexData->vertexCount, 
    115                                                    HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
    116                                                    false); 
     168                                                   HardwareBuffer::HBU_STATIC_WRITE_ONLY); 
    117169 
    118170    // No we get access to the buffer to fill it.  During so we record the bounding box. 
     
    132184                for (int i = 0; i < 3; ++ i) 
    133185                { 
    134                         Vector3 vtx(tri.mVertices[i]); 
     186                        Vector3 vtx = Vector3(tri.mVertices[i]); 
    135187 
    136188                        *vdata ++ = vtx.x; 
     
    138190                        *vdata ++ = vtx.z; 
    139191 
     192                        //std::stringstream d; d << vtx; 
     193                        //Ogre::LogManager::getSingleton().logMessage(d.str()); 
    140194                        aabox.merge(vtx); 
    141195                } 
    142196        } 
    143  
     197        //Ogre::LogManager::getSingleton().logMessage("***"); 
    144198        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");  
    145230 
    146231        // We must indicate the bounding box 
    147232        mesh->_setBounds(aabox);  
    148  
    149         mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0);  
     233        mesh->_setBoundingSphereRadius((aabox.getMaximum() - aabox.getMinimum()).length() / 2.0);  
    150234        mesh->load(); 
    151          
     235        mesh->touch(); 
     236 
    152237        // Create an entity with the mesh 
    153         entity = mSceneManager->createEntity(meshName, entityName); 
     238        entity = mSceneManager->createEntity(entityName, meshName); 
     239 
     240        //entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); 
    154241 
    155242        return entity; 
     243#endif 
    156244} 
Note: See TracChangeset for help on using the changeset viewer.