OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
VegetationModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Reflection;
30 using log4net;
31 using Mono.Addins;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 
38 namespace OpenSim.Region.CoreModules.World.Vegetation
39 {
40  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "VegetationModule")]
42  {
43  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 
45  protected Scene m_scene;
46 
47  protected static readonly PCode[] creationCapabilities = new PCode[] { PCode.Grass, PCode.NewTree, PCode.Tree };
48  public PCode[] CreationCapabilities { get { return creationCapabilities; } }
49 
50  public void Initialise(IConfigSource source)
51  {
52  }
53 
54  public void AddRegion(Scene scene)
55  {
56  m_scene = scene;
57  m_scene.RegisterModuleInterface<IVegetationModule>(this);
58  }
59 
60  public void RemoveRegion(Scene scene)
61  {
62  m_scene.UnregisterModuleInterface<IVegetationModule>(this);
63  }
64 
65  public void Close() {}
66  public string Name { get { return "Vegetation Module"; } }
67 
68  public Type ReplaceableInterface
69  {
70  get { return null; }
71  }
72 
73  public void RegionLoaded(Scene scene)
74  {
75  }
76 
78  UUID uuid, UUID groupID, Vector3 scale, Quaternion rotation, Vector3 position, Tree treeType, bool newTree)
79  {
80  PrimitiveBaseShape treeShape = new PrimitiveBaseShape();
81  treeShape.PathCurve = 16;
82  treeShape.PathEnd = 49900;
83  treeShape.PCode = newTree ? (byte)PCode.NewTree : (byte)PCode.Tree;
84  treeShape.Scale = scale;
85  treeShape.State = (byte)treeType;
86 
87  return m_scene.AddNewPrim(uuid, groupID, position, rotation, treeShape);
88  }
89 
91  UUID ownerID, UUID groupID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
92  {
93  if (Array.IndexOf(creationCapabilities, (PCode)shape.PCode) < 0)
94  {
95  m_log.DebugFormat("[VEGETATION]: PCode {0} not handled by {1}", shape.PCode, Name);
96  return null;
97  }
98 
99  SceneObjectGroup sceneObject = new SceneObjectGroup(ownerID, pos, rot, shape);
100  SceneObjectPart rootPart = sceneObject.GetPart(sceneObject.UUID);
101 
102  // if grass or tree, make phantom
103  //rootPart.TrimPermissions();
104  rootPart.AddFlag(PrimFlags.Phantom);
105  if (rootPart.Shape.PCode != (byte)PCode.Grass)
106  AdaptTree(ref shape);
107 
108  m_scene.AddNewSceneObject(sceneObject, true);
109  sceneObject.SetGroup(groupID, null);
110 
111  return sceneObject;
112  }
113 
114  protected void AdaptTree(ref PrimitiveBaseShape tree)
115  {
116  // Tree size has to be adapted depending on its type
117  switch ((Tree)tree.State)
118  {
119  case Tree.Cypress1:
120  case Tree.Cypress2:
121  tree.Scale *= new Vector3(8, 8, 20);
122  break;
123 
124  // case... other tree types
125  // tree.Scale *= new Vector3(?, ?, ?);
126  // break;
127 
128  default:
129  tree.Scale *= new Vector3(8, 8, 8);
130  break;
131  }
132  }
133  }
134 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion rotation
Definition: ICM_Api.cs:32
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
SceneObjectGroup AddTree(UUID uuid, UUID groupID, Vector3 scale, Quaternion rotation, Vector3 position, Tree treeType, bool newTree)
Add a new tree to the scene. Used by other modules.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Interactive OpenSim region server
Definition: OpenSim.cs:55
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
SceneObjectGroup CreateEntity(UUID ownerID, UUID groupID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
Create an entity