Пример #1
0
        //    *
        //	 * Builds the mesh into the given TriangleBuffer
        //	 * @param buffer The TriangleBuffer on where to append the mesh.
        //	 * @exception Ogre::InvalidStateException Either shape or multishape must be defined!
        //	 * @exception Ogre::InvalidStateException Required parameter is zero!
        //
        //-----------------------------------------------------------------------
        //
        //ORIGINAL LINE: void addToTriangleBuffer(TriangleBuffer& buffer) const
        public override void addToTriangleBuffer(ref TriangleBuffer buffer)
        {
            if (mShapeToExtrude == null && mMultiShapeToExtrude == null)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "Either shape or multishape must be defined!", "Procedural::Lathe::addToTriangleBuffer(Procedural::TriangleBuffer)");
            }
            ;

            // Triangulate the begin and end caps
            if (!mClosed && mCapped)
            {
                _latheCapImpl(ref buffer);
            }

            // Extrudes the body
            if (mShapeToExtrude != null)
            {
                _latheBodyImpl(ref buffer, mShapeToExtrude);
            }
            else
            {
                for (uint i = 0; i < mMultiShapeToExtrude.getShapeCount(); i++)
                {
                    _latheBodyImpl(ref buffer, mMultiShapeToExtrude.getShape(i));
                }
            }
        }
Пример #2
0
        //    *
        //	 * Builds the mesh into the given TriangleBuffer
        //	 * @param buffer The TriangleBuffer on where to append the mesh.
        //	 * @exception Ogre::InvalidStateException Either shape or multishape must be defined!
        //	 * @exception Ogre::InvalidStateException Required parameter is zero!
        //
        //-----------------------------------------------------------------------
        //
        //ORIGINAL LINE: void addToTriangleBuffer(TriangleBuffer& buffer) const
        public override void addToTriangleBuffer(ref TriangleBuffer buffer)
        {
            if (mMultiShapeToExtrude.getShapeCount() == 0)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "At least one shape must be defined!", "Procedural::Extruder::addToTriangleBuffer(Procedural::TriangleBuffer)");
            }
            ;

            // Triangulate the begin and end caps
            if (mCapped && mMultiShapeToExtrude.isClosed())
            {
                GlobalMembers._extrudeCapImpl(ref buffer, mMultiShapeToExtrude, mMultiExtrusionPath, mScaleTracks, mRotationTracks);
            }

            // Extrude the paths contained in multiExtrusionPath
            for (uint j = 0; j < mMultiExtrusionPath.getPathCount(); ++j)
            {
                Path  extrusionPath = mMultiExtrusionPath.getPath((int)j);
                Track rotationTrack = null;
                if (mRotationTracks.find(j) != -1)                                        // mRotationTracks.end()) {
                {
                    rotationTrack = mRotationTracks[j];                                   //mRotationTracks.find(j).second;
                    extrusionPath = extrusionPath.mergeKeysWithTrack(mRotationTracks[j]); // (*mRotationTracks.find(j).second);
                }
                Track scaleTrack = null;
                if (mScaleTracks.find(j) != -1)                                        // mScaleTracks.end()) {
                {
                    rotationTrack = mScaleTracks[j];                                   //mScaleTracks.find(j).second;
                    extrusionPath = extrusionPath.mergeKeysWithTrack(mScaleTracks[j]); // (*mScaleTracks.find(j).second);
                }
                Track pathTextureTrack = null;
                if (mPathTextureTracks.find(j) != -1)                                           // mPathTextureTracks.end()) {
                {
                    pathTextureTrack = mPathTextureTracks[j];                                   //mPathTextureTracks.find(j).second;
                    extrusionPath    = extrusionPath.mergeKeysWithTrack(mPathTextureTracks[j]); //(*mPathTextureTracks.find(j).second);
                }

                std_vector <std_pair <uint, uint> > segs = mMultiExtrusionPath.getNoIntersectionParts(j);

                //for (List<std.pair<uint, uint>>.Enumerator it = segs.GetEnumerator(); it.MoveNext(); ++it) {
                foreach (var it in segs)
                {
                    for (uint i = 0; i < mMultiShapeToExtrude.getShapeCount(); i++)
                    {
                        Shape shapeToExtrude    = mMultiShapeToExtrude.getShape(i);
                        Track shapeTextureTrack = null;
                        if (mShapeTextureTracks.find(i) != -1)          // mShapeTextureTracks.end()) {
                        {
                            shapeTextureTrack = mShapeTextureTracks[i]; //mShapeTextureTracks.find(i).second;
                            shapeToExtrude.mergeKeysWithTrack(shapeTextureTrack);
                        }
                        GlobalMembers._extrudeBodyImpl(ref buffer, shapeToExtrude, extrusionPath, (int)it.first, (int)it.second, shapeTextureTrack, rotationTrack, scaleTrack, pathTextureTrack);
                    }
                }

                // Make the intersections
                //typedef std::vector<PathCoordinate> PathIntersection;
                std_vector <std_vector <MultiPath.PathCoordinate> > intersections = mMultiExtrusionPath.getIntersections();
                //for (List<MultiPath.PathIntersection>.Enumerator it = intersections.GetEnumerator(); it.MoveNext(); ++it) {
                foreach (var it in intersections)
                {
                    for (uint i = 0; i < mMultiShapeToExtrude.getShapeCount(); i++)
                    {
                        Track shapeTextureTrack = null;
                        if (mShapeTextureTracks.find(i) != -1)          // mShapeTextureTracks.end())
                        {
                            shapeTextureTrack = mShapeTextureTracks[i]; //mShapeTextureTracks.find(i).second;
                        }
                        GlobalMembers._extrudeIntersectionImpl(ref buffer, it, mMultiExtrusionPath, mMultiShapeToExtrude.getShape(i), shapeTextureTrack);
                    }
                }
            }
        }
Пример #3
0
        //    *
        //	 * Executes the Constrained Delaunay Triangulation algorithm
        //	 * @param output A vector of index where is outputed the resulting triangle indexes
        //	 * @param outputVertices A vector of vertices where is outputed the resulting triangle vertices
        //	 * @exception Ogre::InvalidStateException Either shape or multishape or segment list must be defined
        //
        //void triangulate(ref List<int>& output, ref List<Vector2>& outputVertices) const;
        public void triangulate(std_vector <int> output, PointList outputVertices)
        {
            if (mShapeToTriangulate == null && mMultiShapeToTriangulate == null && mSegmentListToTriangulate == null)
            {
                throw new NullReferenceException("Ogre::Exception::ERR_INVALID_STATE," + "Either shape or multishape or segment list must be defined!" + ",  Procedural::Triangulator::triangulate(std::vector<int>&, PointList&)");
            }
            //Ogre::Timer mTimer;
            //Mogre.Timer mTimer = new Timer();
            //mTimer.Reset();
            DelaunayTriangleBuffer dtb = new std_list <Triangle>();
            // Do the Delaunay triangulation
            std_vector <int> segmentListIndices = new std_vector <int>();

            if (mShapeToTriangulate != null)
            {
                outputVertices = new std_vector <Vector2>(mShapeToTriangulate.getPoints());
                for (int i = 0; i < mShapeToTriangulate.getSegCount(); ++i)
                {
                    segmentListIndices.push_back(i);
                    segmentListIndices.push_back(mShapeToTriangulate.getBoundedIndex(i + 1));
                }
            }
            else if (mMultiShapeToTriangulate != null)
            {
                outputVertices = new std_vector <Vector2>(mMultiShapeToTriangulate.getPoints());
                int index = 0;
                for (int i = 0; i < mMultiShapeToTriangulate.getShapeCount(); ++i)
                {
                    Shape shape = mMultiShapeToTriangulate.getShape((uint)i);
                    for (int j = 0; j < shape.getSegCount(); j++)
                    {
                        segmentListIndices.push_back(index + j);
                        segmentListIndices.push_back(index + shape.getBoundedIndex(j + 1));
                    }
                    index += shape.getSegCount();
                }
            }
            else if (mSegmentListToTriangulate != null)
            {
                //std_map<Vector2, int, Vector2Comparator> backMap;
                std_map <Vector2, int> backMap = new std_map <Vector2, int>(new Vector2Comparator());
                //for (std::vector<Segment2D>::iterator it = mSegmentListToTriangulate->begin(); it!= mSegmentListToTriangulate->end(); it++)
                foreach (var it in mSegmentListToTriangulate)
                {
                    if ((it.mA - it.mB).SquaredLength < 1e-6)
                    {
                        continue;
                    }

                    //std::map<Vector2, int, Vector2Comparator>::iterator it2 = backMap.find(it->mA);
                    int it2_pos = backMap.find(it.mA);
                    //if (it2 != backMap.end())
                    if (it2_pos != -1)
                    {
                        //segmentListIndices.push_back(it2->second);
                        segmentListIndices.push_back(backMap[it.mA]);
                    }
                    else
                    {
                        //backMap[it->mA] = outputVertices.size();
                        backMap.insert(it.mA, outputVertices.size());
                        segmentListIndices.push_back(outputVertices.size());
                        outputVertices.push_back(it.mA);
                    }

                    //it2 = backMap.find(it.mB);
                    it2_pos = backMap.find(it.mB);
                    //if (it2 != backMap.end())
                    if (it2_pos != -1)
                    {
                        //segmentListIndices.push_back(it2.second);
                        segmentListIndices.push_back(backMap[it.mB]);
                    }
                    else
                    {
                        //backMap[it->mB] = outputVertices.size();
                        backMap.insert(it.mB, outputVertices.size());
                        segmentListIndices.push_back(outputVertices.size());
                        outputVertices.push_back(it.mB);
                    }
                }

                if (mManualSuperTriangle != null)
                {
                    Triangle superTriangle = new Triangle(outputVertices);
                    for (int i = 0; i < 3; i++)
                    {
                        //std::map<Vector2, int, Vector2Comparator>::iterator it = backMap.find(mManualSuperTriangle->mPoints[i]);
                        int it_pos = backMap.find(mManualSuperTriangle.mPoints[i]);
                        //if (it != backMap.end())
                        if (it_pos != -1)
                        {
                            //segmentListIndices.push_back(it->second);
                            //superTriangle.i[i] = it->second;
                            superTriangle.i[i] = backMap[mManualSuperTriangle.mPoints[i]];
                        }
                        else
                        {
                            //backMap[mManualSuperTriangle->mPoints[i]] = outputVertices.size();
                            backMap.insert(mManualSuperTriangle.mPoints[i], outputVertices.size());
                            //segmentListIndices.push_back(outputVertices.size());
                            superTriangle.i[i] = outputVertices.size();
                            outputVertices.push_back(mManualSuperTriangle.mPoints[i]);
                        }
                    }

                    dtb.push_back(superTriangle);
                }
            }
            //Utils::log("Triangulator preparation : " + StringConverter::toString(mTimer.getMicroseconds() / 1000.0f) + " ms");
            delaunay(outputVertices, ref dtb);
            //Utils::log("Triangulator delaunay : " + StringConverter::toString(mTimer.getMicroseconds() / 1000.0f) + " ms");
            // Add contraints
            _addConstraints(ref dtb, outputVertices, segmentListIndices);
            //Utils::log("Triangulator constraints : " + StringConverter::toString(mTimer.getMicroseconds() / 1000.0f) + " ms");
            //Outputs index buffer
            //for (DelaunayTriangleBuffer::iterator it = dtb.begin(); it!=dtb.end(); ++it)
            foreach (var it in dtb)
            {
                if (!it.isDegenerate())
                {
                    output.push_back(it.i[0]);
                    output.push_back(it.i[1]);
                    output.push_back(it.i[2]);
                }
            }
            // Remove super triangle
            if (mRemoveOutside)
            {
                outputVertices.pop_back();
                outputVertices.pop_back();
                outputVertices.pop_back();
            }
            //Utils::log("Triangulator output : " + StringConverter::toString(mTimer.getMicroseconds() / 1000.0f) + " ms");
        }