diff options
author | Teravus Ovares | 2008-02-19 08:49:38 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-02-19 08:49:38 +0000 |
commit | e789a6bc9b14a8f57b6802a265ca404d389030bc (patch) | |
tree | 67b8267511d1f80ed9aec5cabc4bbbb76be5d7ea /OpenSim/Region | |
parent | More distinct startup logo + include the link to FAQ. (diff) | |
download | opensim-SC-e789a6bc9b14a8f57b6802a265ca404d389030bc.zip opensim-SC-e789a6bc9b14a8f57b6802a265ca404d389030bc.tar.gz opensim-SC-e789a6bc9b14a8f57b6802a265ca404d389030bc.tar.bz2 opensim-SC-e789a6bc9b14a8f57b6802a265ca404d389030bc.tar.xz |
* This patch adds Prism support to the Meshmerizer. Prism is one of the object types in the drop down on the object tab. Positive tapers are slightly incorrect(prim sinks into ground a tiny bit). Everything else that's supported works as expected. Hollow, cut, negative tapers, top shear.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 209 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 3 |
2 files changed, 211 insertions, 1 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 9244402..d7e90c5 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -58,7 +58,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
58 | // Setting baseDir to a path will enable the dumping of raw files | 58 | // Setting baseDir to a path will enable the dumping of raw files |
59 | // raw files can be imported by blender so a visual inspection of the results can be done | 59 | // raw files can be imported by blender so a visual inspection of the results can be done |
60 | // const string baseDir = "rawFiles"; | 60 | // const string baseDir = "rawFiles"; |
61 | private const string baseDir = null; //"rawFiles"; | 61 | private const string baseDir = "rawFiles"; |
62 | 62 | ||
63 | private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, | 63 | private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, |
64 | PhysicsVector r2, ref float lambda, ref float mu) | 64 | PhysicsVector r2, ref float lambda, ref float mu) |
@@ -724,7 +724,209 @@ namespace OpenSim.Region.Physics.Meshing | |||
724 | Mesh result = extr.Extrude(m); | 724 | Mesh result = extr.Extrude(m); |
725 | result.DumpRaw(baseDir, primName, "Z extruded"); | 725 | result.DumpRaw(baseDir, primName, "Z extruded"); |
726 | return result; | 726 | return result; |
727 | |||
727 | } | 728 | } |
729 | |||
730 | |||
731 | private static Mesh CreatePrismMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) | ||
732 | // Builds the z (+ and -) surfaces of a box shaped prim | ||
733 | { | ||
734 | UInt16 hollowFactor = primShape.ProfileHollow; | ||
735 | UInt16 profileBegin = primShape.ProfileBegin; | ||
736 | UInt16 profileEnd = primShape.ProfileEnd; | ||
737 | UInt16 taperX = primShape.PathScaleX; | ||
738 | UInt16 taperY = primShape.PathScaleY; | ||
739 | UInt16 pathShearX = primShape.PathShearX; | ||
740 | UInt16 pathShearY = primShape.PathShearY; | ||
741 | |||
742 | //m_log.Error("pathShear:" + primShape.PathShearX.ToString() + "," + primShape.PathShearY.ToString()); | ||
743 | //m_log.Error("pathTaper:" + primShape.PathTaperX.ToString() + "," + primShape.PathTaperY.ToString()); | ||
744 | //m_log.Error("ProfileBegin:" + primShape.ProfileBegin.ToString() + "," + primShape.ProfileBegin.ToString()); | ||
745 | //m_log.Error("PathScale:" + primShape.PathScaleX.ToString() + "," + primShape.PathScaleY.ToString()); | ||
746 | |||
747 | // Procedure: This is based on the fact that the upper (plus) and lower (minus) Z-surface | ||
748 | // of a block are basically the same | ||
749 | // They may be warped differently but the shape is identical | ||
750 | // So we only create one surface as a model and derive both plus and minus surface of the block from it | ||
751 | // This is done in a model space where the block spans from -.5 to +.5 in X and Y | ||
752 | // The mapping to Scene space is done later during the "extrusion" phase | ||
753 | |||
754 | // Base | ||
755 | Vertex MM = new Vertex(-0.25f, -0.45f, 0.0f); | ||
756 | Vertex PM = new Vertex(+0.5f, 0f, 0.0f); | ||
757 | Vertex PP = new Vertex(-0.25f, +0.45f, 0.0f); | ||
758 | |||
759 | |||
760 | SimpleHull outerHull = new SimpleHull(); | ||
761 | outerHull.AddVertex(MM); | ||
762 | outerHull.AddVertex(PM); | ||
763 | outerHull.AddVertex(PP); | ||
764 | |||
765 | |||
766 | // Deal with cuts now | ||
767 | if ((profileBegin != 0) || (profileEnd != 0)) | ||
768 | { | ||
769 | double fProfileBeginAngle = profileBegin / 50000.0 * 360.0; | ||
770 | // In degree, for easier debugging and understanding | ||
771 | //fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y | ||
772 | double fProfileEndAngle = 360.0 - profileEnd / 50000.0 * 360.0; // Pathend comes as complement to 1.0 | ||
773 | //fProfileEndAngle -= (90.0 + 45.0); | ||
774 | if (fProfileBeginAngle < fProfileEndAngle) | ||
775 | fProfileEndAngle -= 360.0; | ||
776 | |||
777 | // Note, that we don't want to cut out a triangle, even if this is a | ||
778 | // good approximation for small cuts. Indeed we want to cut out an arc | ||
779 | // and we approximate this arc by a polygon chain | ||
780 | // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space | ||
781 | // So it can easily be subtracted from the outer hull | ||
782 | int iSteps = (int)(((fProfileBeginAngle - fProfileEndAngle) / 45.0) + .5); | ||
783 | // how many steps do we need with approximately 45 degree | ||
784 | double dStepWidth = (fProfileBeginAngle - fProfileEndAngle) / iSteps; | ||
785 | |||
786 | Vertex origin = new Vertex(0.0f, 0.0f, 0.0f); | ||
787 | |||
788 | // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull | ||
789 | SimpleHull cutHull = new SimpleHull(); | ||
790 | cutHull.AddVertex(origin); | ||
791 | for (int i = 0; i < iSteps; i++) | ||
792 | { | ||
793 | double angle = fProfileBeginAngle - i * dStepWidth; // we count against the angle orientation!!!! | ||
794 | Vertex v = Vertex.FromAngle(angle * Math.PI / 180.0); | ||
795 | cutHull.AddVertex(v); | ||
796 | } | ||
797 | Vertex legEnd = Vertex.FromAngle(fProfileEndAngle * Math.PI / 180.0); | ||
798 | // Calculated separately to avoid errors | ||
799 | cutHull.AddVertex(legEnd); | ||
800 | |||
801 | //m_log.DebugFormat("Starting cutting of the hollow shape from the prim {1}", 0, primName); | ||
802 | SimpleHull cuttedHull = SimpleHull.SubtractHull(outerHull, cutHull); | ||
803 | |||
804 | outerHull = cuttedHull; | ||
805 | } | ||
806 | |||
807 | // Deal with the hole here | ||
808 | if (hollowFactor > 0) | ||
809 | { | ||
810 | float hollowFactorF = (float)hollowFactor / (float)50000; | ||
811 | Vertex IMM = new Vertex(-0.25f * (float)(hollowFactorF / 1.9), -0.45f * (float)(hollowFactorF / 1.9), 0.0f); | ||
812 | Vertex IPM = new Vertex(+0.5f * (float)(hollowFactorF / 1.9), +0f * (float)(hollowFactorF / 1.9), 0.0f); | ||
813 | Vertex IPP = new Vertex(-0.25f * (float)(hollowFactorF / 1.9), +0.45f * (float)(hollowFactorF / 1.9), 0.0f); | ||
814 | |||
815 | |||
816 | |||
817 | SimpleHull holeHull = new SimpleHull(); | ||
818 | |||
819 | holeHull.AddVertex(IMM); | ||
820 | holeHull.AddVertex(IPP); | ||
821 | holeHull.AddVertex(IPM); | ||
822 | |||
823 | SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull); | ||
824 | |||
825 | outerHull = hollowedHull; | ||
826 | } | ||
827 | |||
828 | Mesh m = new Mesh(); | ||
829 | |||
830 | Vertex Seed1 = new Vertex(0.0f, -10.0f, 0.0f); | ||
831 | Vertex Seed2 = new Vertex(-10.0f, 10.0f, 0.0f); | ||
832 | Vertex Seed3 = new Vertex(10.0f, 10.0f, 0.0f); | ||
833 | |||
834 | m.Add(Seed1); | ||
835 | m.Add(Seed2); | ||
836 | m.Add(Seed3); | ||
837 | |||
838 | m.Add(new Triangle(Seed1, Seed2, Seed3)); | ||
839 | m.Add(outerHull.getVertices()); | ||
840 | |||
841 | InsertVertices(m.vertices, 3, m.triangles); | ||
842 | m.DumpRaw(baseDir, primName, "Proto first Mesh"); | ||
843 | |||
844 | m.Remove(Seed1); | ||
845 | m.Remove(Seed2); | ||
846 | m.Remove(Seed3); | ||
847 | m.DumpRaw(baseDir, primName, "Proto seeds removed"); | ||
848 | |||
849 | m.RemoveTrianglesOutside(outerHull); | ||
850 | m.DumpRaw(baseDir, primName, "Proto outsides removed"); | ||
851 | |||
852 | foreach (Triangle t in m.triangles) | ||
853 | { | ||
854 | PhysicsVector n = t.getNormal(); | ||
855 | if (n.Z < 0.0) | ||
856 | t.invertNormal(); | ||
857 | } | ||
858 | |||
859 | Extruder extr = new Extruder(); | ||
860 | |||
861 | extr.size = size; | ||
862 | |||
863 | if (taperX != 100) | ||
864 | { | ||
865 | if (taperX > 100) | ||
866 | { | ||
867 | extr.taperTopFactorX = 1.0f - ((float)taperX / 200); | ||
868 | //m_log.Warn("taperTopFactorX: " + extr.taperTopFactorX.ToString()); | ||
869 | } | ||
870 | else | ||
871 | { | ||
872 | extr.taperBotFactorX = 1.0f - ((100 - (float)taperX) / 100); | ||
873 | //m_log.Warn("taperBotFactorX: " + extr.taperBotFactorX.ToString()); | ||
874 | } | ||
875 | |||
876 | } | ||
877 | |||
878 | if (taperY != 100) | ||
879 | { | ||
880 | if (taperY > 100) | ||
881 | { | ||
882 | extr.taperTopFactorY = 1.0f - ((float)taperY / 200); | ||
883 | //m_log.Warn("taperTopFactorY: " + extr.taperTopFactorY.ToString()); | ||
884 | } | ||
885 | else | ||
886 | { | ||
887 | extr.taperBotFactorY = 1.0f - ((100 - (float)taperY) / 100); | ||
888 | //m_log.Warn("taperBotFactorY: " + extr.taperBotFactorY.ToString()); | ||
889 | } | ||
890 | } | ||
891 | |||
892 | |||
893 | if (pathShearX != 0) | ||
894 | { | ||
895 | if (pathShearX > 50) | ||
896 | { | ||
897 | // Complimentary byte. Negative values wrap around the byte. Positive values go up to 50 | ||
898 | extr.pushX = (((float)(256 - pathShearX) / 100) * -1f); | ||
899 | // m_log.Warn("pushX: " + extr.pushX); | ||
900 | } | ||
901 | else | ||
902 | { | ||
903 | extr.pushX = (float)pathShearX / 100; | ||
904 | // m_log.Warn("pushX: " + extr.pushX); | ||
905 | } | ||
906 | } | ||
907 | |||
908 | if (pathShearY != 0) | ||
909 | { | ||
910 | if (pathShearY > 50) | ||
911 | { | ||
912 | // Complimentary byte. Negative values wrap around the byte. Positive values go up to 50 | ||
913 | extr.pushY = (((float)(256 - pathShearY) / 100) * -1f); | ||
914 | //m_log.Warn("pushY: " + extr.pushY); | ||
915 | } | ||
916 | else | ||
917 | { | ||
918 | extr.pushY = (float)pathShearY / 100; | ||
919 | //m_log.Warn("pushY: " + extr.pushY); | ||
920 | } | ||
921 | } | ||
922 | |||
923 | |||
924 | |||
925 | Mesh result = extr.Extrude(m); | ||
926 | result.DumpRaw(baseDir, primName, "Z extruded"); | ||
927 | return result; | ||
928 | } | ||
929 | |||
728 | public static void CalcNormals(Mesh mesh) | 930 | public static void CalcNormals(Mesh mesh) |
729 | { | 931 | { |
730 | int iTriangles = mesh.triangles.Count; | 932 | int iTriangles = mesh.triangles.Count; |
@@ -803,6 +1005,11 @@ namespace OpenSim.Region.Physics.Meshing | |||
803 | CalcNormals(mesh); | 1005 | CalcNormals(mesh); |
804 | } | 1006 | } |
805 | break; | 1007 | break; |
1008 | case ProfileShape.EquilateralTriangle: | ||
1009 | mesh = CreatePrismMesh(primName, primShape, size); | ||
1010 | CalcNormals(mesh); | ||
1011 | break; | ||
1012 | |||
806 | default: | 1013 | default: |
807 | mesh = CreateBoxMesh(primName, primShape, size); | 1014 | mesh = CreateBoxMesh(primName, primShape, size); |
808 | CalcNormals(mesh); | 1015 | CalcNormals(mesh); |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 3817868..0cfb5ff 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -1165,6 +1165,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1165 | if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight) | 1165 | if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight) |
1166 | return true; | 1166 | return true; |
1167 | 1167 | ||
1168 | if (pbs.ProfileShape == ProfileShape.EquilateralTriangle) | ||
1169 | return true; | ||
1170 | |||
1168 | return false; | 1171 | return false; |
1169 | } | 1172 | } |
1170 | 1173 | ||