aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/Types/PrimitiveBaseShape.cs
blob: 728767f7cea2f4d9b00a817ef377a7fe58a850d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using libsecondlife;
using libsecondlife.Packets;

namespace OpenSim.Framework.Types
{
    public enum ProfileShape : byte
    {
        Circle = 0,
        Square = 1,
        IsometricTriangle = 2,
        EquilateralTriangle = 3,
        RightTriangle = 4,
        HalfCircle = 5
    }

    public enum HollowShape : byte
    {
        Same = 0,
        Circle = 16,
        Square = 32,
        Triangle = 48
    }

    public enum PCodeEnum : byte
    {
        Primitive = 9,
        Avatar = 47
    }

    public enum Extrusion : byte
    {
        Straight = 16,
        Curve1 = 32,
        Curve2 = 48,
        Flexible = 128
    }

    public class PrimitiveBaseShape
    {
        private static byte[] m_defaultTextureEntry;

        public byte PCode;
        public ushort PathBegin;
        public ushort PathEnd;
        public byte PathScaleX;
        public byte PathScaleY;
        public byte PathShearX;
        public byte PathShearY;
        public sbyte PathSkew;
        public ushort ProfileBegin;
        public ushort ProfileEnd;
        public LLVector3 Scale;
        public byte PathCurve;
        public byte ProfileCurve;
        public ushort ProfileHollow;
        public sbyte PathRadiusOffset;
        public byte PathRevolutions;
        public sbyte PathTaperX;
        public sbyte PathTaperY;
        public sbyte PathTwist;
        public sbyte PathTwistBegin;
        public byte[] TextureEntry; // a LL textureEntry in byte[] format
        public byte[] ExtraParams;

        public ProfileShape ProfileShape
        {
            get
            {
                return (ProfileShape)(ProfileCurve & 0xf);
            }
            set
            {
                byte oldValueMasked = (byte)(ProfileCurve & 0xf0);
                ProfileCurve = (byte)(oldValueMasked | (byte)value);
            }
        }

        public HollowShape HollowShape
        {
            get
            {
                return (HollowShape)(ProfileHollow & 0xf0);
            }
            set
            {
                byte oldValueMasked = (byte)(ProfileHollow & 0xf0);
                ProfileHollow = (byte)(oldValueMasked | (byte)value);
            }
        }

        public LLVector3 PrimScale
        {
            get
            {
                return this.Scale;
            }
        }

        static PrimitiveBaseShape()
        {
            m_defaultTextureEntry = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-9999-000000000005")).ToBytes();
        }

        public PrimitiveBaseShape()
        {
            PCode = (byte)PCodeEnum.Primitive;
            ExtraParams = new byte[1];
            TextureEntry = m_defaultTextureEntry;
        }

        //void returns need to change of course
        public virtual void GetMesh()
        {

        }

        public PrimitiveBaseShape Copy()
        {
            return (PrimitiveBaseShape)this.MemberwiseClone();
        }
    }

    public class GenericShape : PrimitiveBaseShape
    {
        public GenericShape()
            : base()
        {

        }
    }

    public class BoxShape : PrimitiveBaseShape
    {
        public BoxShape()
            : base()
        {
            PathCurve = (byte)Extrusion.Straight;
            ProfileShape = ProfileShape.Square;
            PathScaleX = 100;
            PathScaleY = 100;
        }

        public BoxShape(float side)
            : this()
        {
            SetSide(side);
        }

        public void SetSide(float side)
        {
            Scale = new LLVector3(side, side, side);
        }

        public static BoxShape Default
        {
            get
            {
                BoxShape boxShape = new BoxShape();

                boxShape.SetSide(0.5f);

                return boxShape;
            }
        }
    }
    public class CylinderShape : PrimitiveBaseShape
    {
        public CylinderShape()
            : base()
        {
            PathCurve = (byte)Extrusion.Straight;
            ProfileShape = ProfileShape.Circle;
            PathScaleX = 100;
            PathScaleY = 100;
        }

        public CylinderShape(float radius, float heigth)
            : this()
        {
            SetRadius(radius);
            SetHeigth(heigth);
        }

        private void SetHeigth(float heigth)
        {
            Scale.Z = heigth;
        }

        private void SetRadius(float radius)
        {
            Scale.X = Scale.Y = radius * 2f;
        }
    }
}