예제 #1
0
AABBTreeUnpacked::AABBTreeUnpacked(ObjectVector& objects)
{
    m_numNodes = 0;
    m_maxDepth = 0;
    m_twoChildNodes = 0;
    m_leafNodes = 0;

    // Find the total AABB of all the objects
    root = new(_mm_malloc(sizeof(Node),16)) Node();
    root->aabb = Surround(objects,0,objects.size());
    if(objects.size() == 1)
    {
        m_maxDepth = 0;
        m_numNodes = 1;
        m_leafNodes = 1;
        root->obj = objects[0].obj;
        root->children[0] = NULL;
        root->children[1] = NULL;
    }
    else
    {
        root->obj = NULL;
        ++m_numNodes;
        ++m_twoChildNodes;
        BuildTreeRecursive(
            objects,
            root,
            0,
            (uint32_t)objects.size(),
            1);
    }

    //assert(m_numNodes == m_leafNodes + m_twoChildNodes);
}
//-----------------------------------------------------------------------------------------
void OgitorsRoot::RegExpByProperty(const Ogre::String& nameregexp, bool inverse, const ObjectVector& list_in, ObjectVector& list_out)
{
    list_out.clear();

    try
    {
        const boost::regex e(nameregexp.c_str());

        OgitorsPropertyVector pvec;

        for(unsigned int i = 0;i < list_in.size();i++)   
        {
            pvec = list_in[i]->getProperties()->getPropertyVector();

            bool add_list = false;
            
            for(unsigned int k = 0;k < pvec.size();k++)
            {
                if(regex_match(pvec[k]->getName().c_str(), e))
                {
                    add_list = true;
                    break;
                }
            }
            
            if(add_list != inverse)
                list_out.push_back(list_in[i]);
        }
    }
    catch(...)
    {
        list_out.clear();
    }
}    
예제 #3
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::add(const ObjectVector& newselection)
{
    if(mDeletionInProgress)
        return;

    if(newselection.size() == 0)
        return;

    for(unsigned int i = 0;i < newselection.size();i++)
    {
        if(newselection[i] && (newselection[i] != this) && (mSelectedObjects.find(newselection[i]->getName()) == mSelectedObjects.end()))
        {
            mSelectedObjects.insert(NameObjectPairList::value_type(newselection[i]->getName(), newselection[i]));

            newselection[i]->setSelected(true);
        }
    }

    _createModifyList();
}
예제 #4
0
void AABBTreeUnpacked::Partition(
    ObjectVector& objects,
    uint32_t beginIndex,
    uint32_t endIndex,
    uint32_t axis,
    float val,
    uint32_t& finalRightIdx)
{
    assert(endIndex > beginIndex);
    assert(endIndex <= objects.size());
    assert(axis < 3);

    ObjectVector sos(endIndex-beginIndex);

    // Indices which we use to track the number of aabbs in the left and right lists.
    uint32_t rightIdxObj = endIndex;

    uint32_t leftIdxSOS = 0;
    uint32_t rightIdxSOS = endIndex - beginIndex - 1;

    for(uint32_t i = beginIndex; i < endIndex; ++i)
    {
        Vector3 centroid = objects[i].aabb.GetCentroid();

        if(centroid.GetComponent(axis) >= val)
        {
            sos[rightIdxSOS--] = objects[i];
            --rightIdxObj;
        }
        else
        {
            sos[leftIdxSOS++] = objects[i];
        }
    }

    // Make sure we have actually found a place for all the AABBs
    assert(leftIdxSOS == rightIdxSOS+1);

    // Copy the partitioned list back to the correct part of the object vector.

    uint32_t it = 0;
    for(uint32_t i = beginIndex; i < endIndex; ++i)
    {
        objects[i] = sos[it++];
    }

    finalRightIdx = rightIdxObj;

    // Make sure we always have at least one object in each list. This prevents dangling
    // leaf nodes from being created, as well as solving certain infinite recursion situations.
    if(finalRightIdx == beginIndex) finalRightIdx = beginIndex + 1;
    if(finalRightIdx == endIndex) finalRightIdx = endIndex - 1;
}
예제 #5
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::remove(const ObjectVector& newselection)
{
    if(mDeletionInProgress)
        return;

    if(newselection.size() == 0)
        return;

    NameObjectPairList::iterator it;

    for(unsigned int i = 0;i < newselection.size();i++)
    {
        if(newselection[i] && ((it = mSelectedObjects.find(newselection[i]->getName())) != mSelectedObjects.end()))
        {
            mSelectedObjects.erase(it);

            newselection[i]->setSelected(false);
        }
    }

    _createModifyList();
}
예제 #6
0
//-----------------------------------------------------------------------------
int COFSSceneSerializer::_writeFile(Ogre::String exportfile, const bool forceSave)
{
    if (exportfile.empty())
        return SCF_ERRUNKNOWN;

    OgitorsRoot *ogRoot = OgitorsRoot::getSingletonPtr();
    // Open a stream to output our XML Content and write the general headercopyFile
    std::stringstream outfile;

    outfile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    outfile << "<OGITORSCENE version=\"" << Globals::OGSCENE_FORMAT_VERSION << "\">\n";

    PROJECTOPTIONS *pOpt = ogRoot->GetProjectOptions();
    pOpt->CameraSpeed = ogRoot->GetViewport()->GetCameraSpeed();

    ogRoot->WriteProjectOptions(outfile, pOpt);

    ObjectVector ObjectList;
    OgitorsPropertyValueMap theList;
    OgitorsPropertyValueMap::iterator ni;

    // Start from 1, since 0 means all objects
    for(unsigned int i = 1; i < LAST_EDITOR; i++)
    {
        ogRoot->GetObjectList(i, ObjectList);
        for(unsigned int ob = 0; ob < ObjectList.size(); ob++)
        {
            /// If Object does not have a parent, then it is not part of the scene
            if(ObjectList[ob]->getParent())
            {
                ObjectList[ob]->onSave(forceSave);
                if(ObjectList[ob]->isSerializable())
                {
                    outfile << OgitorsUtils::GetObjectSaveStringV2(ObjectList[ob], 2, true, true).c_str();
                    outfile << "\n";
                }
            }
        }
    }
    outfile << "</OGITORSCENE>\n";

    if (OgitorsUtils::SaveStreamOfs(outfile, exportfile)) {
        return SCF_OK;
    }

    return SCF_ERRFILE;
}
예제 #7
0
AABBTreeUnpacked::AABB AABBTreeUnpacked::Surround(ObjectVector& ov, size_t beginIdx, size_t endIdx)
{
    assert(endIdx >= beginIdx);
    assert(endIdx <= ov.size());

    if(endIdx == beginIdx)
    {
        return AABB(Vector3(0.0f),Vector3(0.0f));
    }

    AABB aabb = ov[beginIdx].aabb;
    if(beginIdx == endIdx - 1) return aabb;
    for(size_t i = beginIdx + 1; i < endIdx; ++i)
    {
        aabb = Union(aabb,ov[i].aabb);
    }
    return aabb;
}
//-----------------------------------------------------------------------------------------
void OgitorsRoot::RegExpByName(const Ogre::String& nameregexp, bool inverse, const ObjectVector& list_in, ObjectVector& list_out)
{
    list_out.clear();
    
    try
    {
        const boost::regex e(nameregexp.c_str());

        for(unsigned int i = 0;i < list_in.size();i++)   
        {
            if(regex_match(list_in[i]->getName().c_str(), e) != inverse)
            {
                list_out.push_back(list_in[i]);
            }
        }
    }
    catch(...)
    {
        list_out.clear();
    }
}
예제 #9
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::setSelection(const ObjectVector& list)
{
    if(mDeletionInProgress)
        return;

    _clearSelection();

    for(unsigned int i = 0;i < list.size();i++)
    {
        if(list[i])
        {
            list[i]->setSelected(true);
            mSelectedObjects.insert(NameObjectPairList::value_type(list[i]->getName(), list[i]));
        }
    }

    _createModifyList();

    SelectionChangeEvent evt(this);
    EventManager::getSingletonPtr()->sendEvent(this, 0, &evt);
}