/// <summary> /// Adds all of the geometry used by a model component to the static geometry. /// This is used by the ModelComponent. /// </summary> public void Add(ModelComponent mc, ThingBlock template, ModelBlock block, ThingDefinition def) { // if the model detail option is low and this model wants imposters, don't even make any static geometry of it if (Options.ModelDetail == ModelDetailOption.Low) { if (def.GetBoolProperty("Imposters", false)) return; } var sceneMgr = LKernel.GetG<SceneManager>(); string meshName = block.GetStringProperty("mesh", null); // map region goes first string sgeomName = template.GetStringProperty("MapRegion", "(Default)"); // static group can override map region sgeomName = block.GetStringProperty("StaticGroup", sgeomName); Entity ent; // get our entity if it already exists if (!ents.TryGetValue(meshName, out ent)) { // getting the entity was not successful, so we have to create it ent = sceneMgr.CreateEntity(meshName + mc.ID, meshName); string material; if (block.StringTokens.TryGetValue("material", out material)) ent.SetMaterialName(material); ents.Add(meshName, ent); } Vector3 pos; // two ways to get the position // inherit it from the lthing, the default (if we were using nodes, this would be the default too) if (block.GetBoolProperty("InheritOrientation", true)) { pos = (mc.Owner.SpawnOrientation * block.GetVectorProperty("position", Vector3.ZERO)) + template.VectorTokens["position"]; } // or we can choose not to inherit it for whatever reason else { pos = block.GetVectorProperty("position", Vector3.ZERO) + template.VectorTokens["position"]; } Quaternion orient = block.GetQuatProperty("orientation", Quaternion.IDENTITY) * template.GetQuatProperty("orientation", Quaternion.IDENTITY); Vector3 sca = block.GetVectorProperty("scale", Vector3.UNIT_SCALE); StaticGeometry sg; if (!sgeoms.TryGetValue(sgeomName, out sg)) { sg = LKernel.GetG<SceneManager>().CreateStaticGeometry(sgeomName); sg.RegionDimensions = regionDimensions; sg.RenderingDistance = 300 / 5f; sgeoms.Add(sgeomName, sg); } sg.AddEntity(ent, pos, orient, sca); }
public void Add(ModelComponent mc, ThingBlock template, ModelBlock block, ThingDefinition def) { // if the model detail option is low and this model wants imposters, don't even make any instanced geometry of it if (Options.ModelDetail == ModelDetailOption.Low) { if (def.GetBoolProperty("Imposters", false)) return; } var sceneMgr = LKernel.GetG<SceneManager>(); string meshName = block.GetStringProperty("mesh", null); string mapRegion = template.GetStringProperty("MapRegion", string.Empty); string key = mapRegion + meshName; // create our entity if it doesn't exist if (!ents.ContainsKey(key)) { Entity ent = sceneMgr.CreateEntity(mc.Name + mc.ID, meshName); ent.SetMaterialName(block.GetStringProperty("Material", string.Empty)); // then add it to our dictionary ents.Add(key, ent); } // get our transforms Vector3 pos; // two ways to get the position // inherit it from the lthing, the default (if we were using nodes, this would be the default too) if (block.GetBoolProperty("InheritOrientation", true)) { pos = (mc.Owner.SpawnOrientation * block.GetVectorProperty("position", Vector3.ZERO)) + template.VectorTokens["position"]; } // or we can choose not to inherit it for whatever reason else { pos = block.GetVectorProperty("position", Vector3.ZERO) + template.VectorTokens["position"]; } Quaternion orient = block.GetQuatProperty("orientation", Quaternion.IDENTITY) * template.GetQuatProperty("orientation", Quaternion.IDENTITY); Vector3 sca = block.GetVectorProperty("scale", Vector3.UNIT_SCALE); // put them in one class Transform trans = new Transform { Position = pos, Orientation = orient, Scale = sca, }; // if the transforms dictionary doesn't contain the mesh yet, add a new one if (!transforms.ContainsKey(key)) { transforms.Add(key, new List<Transform>()); } // then put our transform into the dictionary transforms[key].Add(trans); }
/// <summary> /// Constructor woo! /// </summary> /// <param name="template"> /// This is the part that comes from the .muffin file (if we used one) or somewhere else in the program. It has basic information needed for constructing this /// lthing, such as where it should be in the world, its rotation, etc. /// </param> /// <param name="def"> /// This is the part that comes from the .thing file. It's got all of the properties that specifies what this lthing is, what it should look like, and /// information about all of its components. /// </param> public LThing(ThingBlock template, ThingDefinition def) { ID = IDs.Incremental; Name = template.ThingName; // get our three basic transforms SpawnPosition = template.GetVectorProperty("position", null); SpawnOrientation = template.GetQuatProperty("orientation", Quaternion.IDENTITY); if (SpawnOrientation == Quaternion.IDENTITY) SpawnOrientation = template.GetVectorProperty("rotation", Vector3.ZERO).DegreeVectorToGlobalQuaternion(); SpawnScale = template.GetVectorProperty("scale", Vector3.UNIT_SCALE); // and start setting up this thing! PreSetup(template, def); SetupMogre(template, def); InitialiseComponents(template, def); RootNode.Position = SpawnPosition; RootNode.Orientation = SpawnOrientation; // only scale up the root node if it doesn't have any physics things attached - bullet really does not like scaling. // Need a few variations of identical objects with different scales? Gonna have to make different .things for them. // Though it might be easier to just have one general .thing for them, and all it does is run a script that randomly // gets one of the others. if (ShapeComponents == null) RootNode.Scale(SpawnScale); RootNode.SetInitialState(); PostInitialiseComponents(template, def); SetupPhysics(template, def); // get our script token and run it, if it has one and if this thing was created on the fly instead // of through a .muffin file string script; if (def.StringTokens.TryGetValue("script", out script)) { this.Script = script; RunScript(); } DisposeIfStaticOrInstanced(def); }