aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SOPMaterial.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SOPMaterial.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SOPMaterial.cs177
1 files changed, 177 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SOPMaterial.cs b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs
new file mode 100644
index 0000000..d38ef61
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SOPMaterial.cs
@@ -0,0 +1,177 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenMetaverse.StructuredData;
32using OpenSim.Framework;
33
34namespace OpenSim.Region.Framework.Scenes
35{
36 public static class SOPMaterialData
37 {
38 public enum SopMaterial : int // redundante and not in use for now
39 {
40 Stone = 0,
41 Metal = 1,
42 Glass = 2,
43 Wood = 3,
44 Flesh = 4,
45 Plastic = 5,
46 Rubber = 6,
47 light = 7 // compatibility with old viewers
48 }
49
50 private struct MaterialData
51 {
52 public float friction;
53 public float bounce;
54 public MaterialData(float f, float b)
55 {
56 friction = f;
57 bounce = b;
58 }
59 }
60
61 private static MaterialData[] m_materialdata = {
62 new MaterialData(0.8f,0.4f), // Stone
63 new MaterialData(0.3f,0.4f), // Metal
64 new MaterialData(0.2f,0.7f), // Glass
65 new MaterialData(0.6f,0.5f), // Wood
66 new MaterialData(0.9f,0.3f), // Flesh
67 new MaterialData(0.4f,0.7f), // Plastic
68 new MaterialData(0.9f,0.95f), // Rubber
69 new MaterialData(0.0f,0.0f) // light ??
70 };
71
72 public static Material MaxMaterial
73 {
74 get { return (Material)(m_materialdata.Length - 1); }
75 }
76
77 public static float friction(Material material)
78 {
79 int indx = (int)material;
80 if (indx < m_materialdata.Length)
81 return (m_materialdata[indx].friction);
82 else
83 return 0;
84 }
85
86 public static float bounce(Material material)
87 {
88 int indx = (int)material;
89 if (indx < m_materialdata.Length)
90 return (m_materialdata[indx].bounce);
91 else
92 return 0;
93 }
94 }
95
96 public class FaceMaterial
97 {
98 public UUID ID;
99 public UUID NormalMapID = UUID.Zero;
100 public float NormalOffsetX = 0.0f;
101 public float NormalOffsetY = 0.0f;
102 public float NormalRepeatX = 1.0f;
103 public float NormalRepeatY = 1.0f;
104 public float NormalRotation = 0.0f;
105
106 public UUID SpecularMapID = UUID.Zero;
107 public float SpecularOffsetX = 0.0f;
108 public float SpecularOffsetY = 0.0f;
109 public float SpecularRepeatX = 1.0f;
110 public float SpecularRepeatY = 1.0f;
111 public float SpecularRotation = 0.0f;
112
113 public Color4 SpecularLightColor = new Color4(255,255,255,255);
114 public Byte SpecularLightExponent = 51;
115 public Byte EnvironmentIntensity = 0;
116 public Byte DiffuseAlphaMode = 1;
117 public Byte AlphaMaskCutoff = 0;
118
119 public FaceMaterial()
120 { }
121
122 public FaceMaterial(UUID pID, OSDMap mat)
123 {
124 ID = pID;
125 if(mat == null)
126 return;
127 float scale = 0.0001f;
128 NormalMapID = mat["NormMap"].AsUUID();
129 NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal();
130 NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal();
131 NormalRepeatX = scale * (float)mat["NormRepeatX"].AsReal();
132 NormalRepeatY = scale * (float)mat["NormRepeatY"].AsReal();
133 NormalRotation = scale * (float)mat["NormRotation"].AsReal();
134
135 SpecularMapID = mat["SpecMap"].AsUUID();
136 SpecularOffsetX = scale * (float)mat["SpecOffsetX"].AsReal();
137 SpecularOffsetY = scale * (float)mat["SpecOffsetY"].AsReal();
138 SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal();
139 SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal();
140 SpecularRotation = scale * (float)mat["SpecRotation"].AsReal();
141
142 SpecularLightColor = mat["SpecColor"].AsColor4();
143 SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger();
144 EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger();
145 DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger();
146 AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger();
147 }
148
149 public OSDMap toOSD()
150 {
151 OSDMap mat = new OSDMap();
152 float scale = 10000f;
153
154 mat["NormMap"] = NormalMapID;
155 mat["NormOffsetX"] = (int) (scale * NormalOffsetX);
156 mat["NormOffsetY"] = (int) (scale * NormalOffsetY);
157 mat["NormRepeatX"] = (int) (scale * NormalRepeatX);
158 mat["NormRepeatY"] = (int) (scale * NormalRepeatY);
159 mat["NormRotation"] = (int) (scale * NormalRotation);
160
161 mat["SpecMap"] = SpecularMapID;
162 mat["SpecOffsetX"] = (int) (scale * SpecularOffsetX);
163 mat["SpecOffsetY"] = (int) (scale * SpecularOffsetY);
164 mat["SpecRepeatX"] = (int) (scale * SpecularRepeatX);
165 mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY);
166 mat["SpecRotation"] = (int) (scale * SpecularRotation);
167
168 mat["SpecColor"] = SpecularLightColor;
169 mat["SpecExp"] = SpecularLightExponent;
170 mat["EnvIntensity"] = EnvironmentIntensity;
171 mat["DiffuseAlphaMode"] = DiffuseAlphaMode;
172 mat["AlphaMaskCutoff"] = AlphaMaskCutoff;
173
174 return mat;
175 }
176 }
177} \ No newline at end of file