예제 #1
0
    void ModelContainerView::fillVertexAndIndexArrays(const SubModel& pSm, Array<Vector3>& vArray, Array<int>& iArray) {
        Array<TriangleBox> tbarray;

        fillRenderArray(pSm, tbarray, &pSm.getTreeNode(0));
        MeshBuilder builder;
        int len = tbarray.size();
        int count = 0;
        for(int i=0;i<len;++i) {
            Triangle t = Triangle(tbarray[i].vertex(0).getVector3() + pSm.getBasePosition(),
                tbarray[i].vertex(1).getVector3() + pSm.getBasePosition(),
                tbarray[i].vertex(2).getVector3() + pSm.getBasePosition());

            vArray.append(t.vertex(0));
            vArray.append(t.vertex(1));
            vArray.append(t.vertex(2));

            iArray.append(count+0);
            iArray.append(count+1);
            iArray.append(count+1);
            iArray.append(count+2);
            iArray.append(count+2);
            iArray.append(count+0);
            count+=3;
        }
    }
예제 #2
0
    void ModelContainer::fillContainer(const AABSPTree<SubModel *>::Node& pNode, int &pSubModelPos, int &pTreeNodePos, int &pTrianglePos, Vector3& pLo, Vector3& pHi, Vector3& pFinalLo, Vector3& pFinalHi)
    {
        // TreeNode for the SubModel
        TreeNode treeNode = TreeNode(pNode.valueArray.size(), pSubModelPos);
        treeNode.setSplitAxis(pNode.splitAxis);
        treeNode.setSplitLocation(pNode.splitLocation);
        int currentTreeNodePos = pTreeNodePos++;

        Vector3 lo = Vector3(inf(),inf(),inf());
        Vector3 hi = Vector3(-inf(),-inf(),-inf());

        for (int i=0; i<pNode.valueArray.size(); i++)
        {
            G3D::_AABSPTree::Handle<SubModel*>* h= pNode.valueArray[i];
            SubModel *m = h->value;

            memcpy(&getTreeNodes()[pTreeNodePos], &m->getTreeNode(0), sizeof(TreeNode) * m->getNNodes());
            memcpy(&getTriangles()[pTrianglePos], &m->getTriangle(0), sizeof(TriangleBox) * m->getNTriangles());

            SubModel newModel = SubModel(m->getNTriangles(), getTriangles(), pTrianglePos, m->getNNodes(), getTreeNodes(), pTreeNodePos);
            newModel.setReletiveBounds(m->getReletiveBounds().getLo(), m->getReletiveBounds().getHi());
            newModel.setBasePosition(m->getBasePosition());
            iSubModel[pSubModelPos++] = newModel;

            pTreeNodePos += m->getNNodes();
            pTrianglePos += m->getNTriangles();

            AABox box = m->getAABoxBounds();
            lo = lo.min(box.low());
            hi = hi.max(box.high());
            pFinalLo = pFinalLo.min(lo);
            pFinalHi = pFinalHi.max(hi);
        }
        /*
        if(pNode.valueArray.size() == 0) {
        int xxx = 0; // just for the breakpoint
        }
        */
        // get absolute bounds

        if(pNode.child[0] != 0)
        {
            treeNode.setChildPos(0, pTreeNodePos);
            fillContainer(*pNode.child[0], pSubModelPos, pTreeNodePos, pTrianglePos, lo, hi,pFinalLo,pFinalHi);
        }
        if(pNode.child[1] != 0)
        {
            treeNode.setChildPos(1, pTreeNodePos);
            fillContainer(*pNode.child[1], pSubModelPos, pTreeNodePos, pTrianglePos, lo, hi,pFinalLo,pFinalHi);
        }

        pLo = pLo.min(lo);
        pHi = pHi.max(hi);

        treeNode.setBounds(lo,hi);

        setTreeNode(treeNode, currentTreeNodePos);

    }
예제 #3
0
 void
 ModelContainerView::fillVertexArray (const SubModel& pSm, Array<Vector3>& vArray)
 {
   //printf("fillVertexArray for %i-%i\n",VMAP::hashCode(SubModel),5);
   //printf("fillVertexArray for %i\n",VMAP::hashCode(pSm));
   Array<TriangleBox> tbarray;
   fillRenderArray (pSm, tbarray, &pSm.getTreeNode (0));
   int len = tbarray.size ();
   Vector3 toconvert[3];
   for (int i = 0; i < len; ++i)
     {
       // TODO: Get correct Conversion of position values.
       // The system between vmaps and MaNGOS differs in that:
       /* from iinternal(xyz) -> MaNGOS(xyz)
       float pos[3];
       pos[0] = z;
       pos[1] = x;
       pos[2] = y;
       double full = 64.0*533.33333333;
       double mid = full/2.0;
       pos[0] = -((mid+pos[0])-full); -> -mid -pos[0] + full -> mid - z
       pos[1] = -((mid+pos[1])-full); -> -mid -pos[0] + full -> mid - x
       */
       TriangleBox old = tbarray[i];
       toconvert[0] = old.vertex(0).getVector3 () + pSm.getBasePosition ();
       toconvert[1] = old.vertex(1).getVector3 () + pSm.getBasePosition ();
       toconvert[2] = old.vertex(2).getVector3 () + pSm.getBasePosition ();
       for (int j = 0; j < 3; j++) {
           toconvert[j] = toconvert[j].zxy();
           toconvert[j].x = MID - toconvert[j].x;
           toconvert[j].y = MID - toconvert[j].y;
       }
       //TODO: playing around with correct range of triangles for detour
       Triangle t = Triangle(toconvert[0],toconvert[1],toconvert[2]);
       Triangle t1 = Triangle(toconvert[2],toconvert[1],toconvert[0]);
       globalTriangleArray.append(t,t1);
       /*
       for (int j = 2; j>= 0; j--) {
           Vector3 vertex = tbarray[i].vertex(j).getVector3() + pSm.getBasePosition();
           // x = [expr {-(($::mid+$x)-$::full)}]
           //printf("x[%.2f] y[%.2f] z[%.2f]",vertex.x,vertex.y,vertex.z);
           // v 152.333 60.0304 -9561.67
           vertex = Vector3(-((64*533.333333333/2 + vertex.z) - 64*533.333333333),
                           -((64*533.333333333/2 + vertex.x) - 64*533.333333333),
                           vertex.y);
           vArray.append(vertex);
       }
       */
     }
 }