public PrimitiveModelEntity(string modelname, Region tregion)
     : base(tregion, false)
 {
     model = tregion.TheClient.Models.GetModel(modelname);
     Gravity = Location.Zero;
     Velocity = Location.Zero;
 }
Beispiel #2
0
 public GrenadeEntity(Region tregion, bool shadows)
     : base(tregion, true, shadows)
 {
     model = TheClient.Models.Sphere;
     GColor = new Color4(0f, 0f, 0f, 1f);
     Shape = new CylinderShape(0.2f, 0.05f);
     Bounciness = 0.95f;
     SetMass(1);
 }
Beispiel #3
0
 public PlayerEntity(Region tregion)
     : base(tregion)
 {
     SetMass(tmass);
     mod_scale = 1.5f;
     CanRotate = false;
     EID = -1;
     model = TheClient.Models.GetModel("players/human_male_004");
     model.LoadSkin(TheClient.Textures);
     CGroup = CollisionUtil.Player;
     NMTWOWorld.ForceUpdater.Gravity = TheRegion.PhysicsWorld.ForceUpdater.Gravity;
     NMTWOWorld.TimeStepSettings.MaximumTimeStepsPerFrame = 10;
     SetPosition(new Location(0, 0, 1000));
 }
Beispiel #4
0
 public void ShadersCheck()
 {
     string def = CVars.r_good_graphics.ValueB ? "#MCM_GOOD_GRAPHICS" : "#";
     s_shadow = Shaders.GetShader("shadow" + def);
     s_shadowvox = Shaders.GetShader("shadowvox" + def);
     s_fbo = Shaders.GetShader("fbo" + def);
     s_fbot = Shaders.GetShader("fbo" + def + ",MCM_TRANSP_ALLOWED");
     s_fbov = Shaders.GetShader("fbo_vox" + def);
     s_fbo_refract = Shaders.GetShader("fbo" + def + ",MCM_REFRACT");
     s_fbov_refract = Shaders.GetShader("fbo_vox" + def + ",MCM_REFRACT");
     s_shadowadder = Shaders.GetShader("lightadder" + def + ",MCM_SHADOWS");
     s_lightadder = Shaders.GetShader("lightadder" + def);
     s_transponly = Shaders.GetShader("transponly" + def);
     s_transponlyvox = Shaders.GetShader("transponlyvox" + def);
     s_transponlylit = Shaders.GetShader("transponly" + def + ",MCM_LIT");
     s_transponlyvoxlit = Shaders.GetShader("transponlyvox" + def + ",MCM_LIT");
     s_transponlylitsh = Shaders.GetShader("transponly" + def + ",MCM_LIT,MCM_SHADOWS");
     s_transponlyvoxlitsh = Shaders.GetShader("transponlyvox" + def + ",MCM_LIT,MCM_SHADOWS");
     s_godray = Shaders.GetShader("godray" + def);
     s_mapvox = Shaders.GetShader("map_vox" + def);
     s_transpadder = Shaders.GetShader("transpadder" + def);
     s_finalgodray = Shaders.GetShader("finalgodray" + def);
     s_finalgodray_toonify = Shaders.GetShader("finalgodray" + def + ",MCM_TOONIFY");
     s_finalgodray_lights = Shaders.GetShader("finalgodray" + def + ",MCM_LIGHTS");
     s_finalgodray_lights_toonify = Shaders.GetShader("finalgodray" + def + ",MCM_LIGHTS,MCM_TOONIFY");
     s_finalgodray_lights_motblur = Shaders.GetShader("finalgodray" + def + ",MCM_LIGHTS,MCM_MOTBLUR");
     s_forw = Shaders.GetShader("forward" + def);
     s_forw_vox = Shaders.GetShader("forward" + def + ",MCM_VOX");
     s_forw_trans = Shaders.GetShader("forward" + def + ",MCM_TRANSP");
     s_forw_vox_trans = Shaders.GetShader("forward" + def + ",MCM_VOX,MCM_TRANSP");
     s_transponly_ll = Shaders.GetShader("transponly" + def + ",MCM_LL");
     s_transponlyvox_ll = Shaders.GetShader("transponlyvox" + def + ",MCM_LL");
     s_transponlylit_ll = Shaders.GetShader("transponly" + def + ",MCM_LIT,MCM_LL");
     s_transponlyvoxlit_ll = Shaders.GetShader("transponlyvox" + def + ",MCM_LIT,MCM_LL");
     s_transponlylitsh_ll = Shaders.GetShader("transponly" + def + ",MCM_LIT,MCM_SHADOWS,MCM_LL");
     s_transponlyvoxlitsh_ll = Shaders.GetShader("transponlyvox" + def + ",MCM_LIT,MCM_SHADOWS,MCM_LL");
     s_ll_clearer = Shaders.GetShader("clearer" + def);
     s_ll_fpass = Shaders.GetShader("fpass" + def);
     s_hdrpass = Shaders.GetShader("hdrpass" + def);
     s_forw_grass = Shaders.GetShader("forward" + def + ",MCM_GEOM_ACTIVE?grass");
     s_fbo_grass = Shaders.GetShader("fbo" + def + ",MCM_GEOM_ACTIVE,MCM_PRETTY?grass");
     s_forw_particles = Shaders.GetShader("forward" + def + ",MCM_GEOM_ACTIVE,MCM_TRANSP,MCM_NO_ALPHA_CAP?particles");
     // TODO: Better place for models?
     RainCyl = Models.GetModel("raincyl");
     RainCyl.LoadSkin(Textures);
     SnowCyl = Models.GetModel("snowcyl");
     SnowCyl.LoadSkin(Textures);
 }
Beispiel #5
0
 public override void SetModelName(string name)
 {
     Mod = TheClient.Models.GetModel(name);
 }
Beispiel #6
0
 public void PreHandleSpawn()
 {
     model = TheClient.Models.GetModel(mod);
     model.LoadSkin(TheClient.Textures);
     int ignoreme;
     if (mode == ModelCollisionMode.PRECISE)
     {
         Shape = TheClient.Models.Handler.MeshToBepu(model.Original, out ignoreme);
     }
     else if (mode == ModelCollisionMode.CONVEXHULL)
     {
         Shape = TheClient.Models.Handler.MeshToBepuConvex(model.Original, out ignoreme);
     }
     else if (mode == ModelCollisionMode.AABB)
     {
         List<BEPUutilities.Vector3> vecs = TheClient.Models.Handler.GetCollisionVertices(model.Original);
         Location zero = new Location(vecs[0]);
         AABB abox = new AABB() { Min = zero, Max = zero };
         for (int v = 1; v < vecs.Count; v++)
         {
             abox.Include(new Location(vecs[v]));
         }
         Location size = abox.Max - abox.Min;
         Location center = abox.Max - size / 2;
         Shape = new BoxShape((float)size.X * (float)scale.X, (float)size.Y * (float)scale.Y, (float)size.Z * (float)scale.Z);
         Offset = -center;
     }
     else
     {
         List<BEPUutilities.Vector3> vecs = TheClient.Models.Handler.GetCollisionVertices(model.Original);
         // Location zero = new Location(vecs[0].X, vecs[0].Y, vecs[0].Z);
         double distSq = 0;
         for (int v = 1; v < vecs.Count; v++)
         {
             if (vecs[v].LengthSquared() > distSq)
             {
                 distSq = vecs[v].LengthSquared();
             }
         }
         double size = Math.Sqrt(distSq);
         Offset = Location.Zero;
         Shape = new SphereShape((float)size * (float)scale.X);
     }
 }
Beispiel #7
0
 void PopulateChildren(ModelNode node, Model3DNode orin, Model model, AnimationEngine engine, List<ModelNode> allNodes)
 {
     allNodes.Add(node);
     if (engine.HeadBones.Contains(node.Name))
     {
         node.Mode = 0;
     }
     else if (engine.LegBones.Contains(node.Name))
     {
         node.Mode = 2;
     }
     else
     {
         node.Mode = 1;
     }
     for (int i = 0; i < orin.Children.Count; i++)
     {
         ModelNode child = new ModelNode() { Parent = node, Name = orin.Children[i].Name.ToLowerFast() };
         PopulateChildren(child, orin.Children[i], model, engine, allNodes);
         node.Children.Add(child);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Prepares the model system.
 /// </summary>
 public void Init(AnimationEngine engine, Client tclient)
 {
     TheClient = tclient;
     AnimEngine = engine;
     Handler = new ModelHandler();
     LoadedModels = new List<Model>();
     Cube = GetModel("cube");
     Cylinder = GetModel("cylinder");
     Sphere = GetModel("sphere");
 }
Beispiel #9
0
 /// <summary>
 /// Gets the model object for a specific model name.
 /// </summary>
 /// <param name="modelname">The name of the model.</param>
 /// <returns>A valid model object.</returns>
 public Model GetModel(string modelname)
 {
     lock (Locker)
     {
         modelname = FileHandler.CleanFileName(modelname);
         for (int i = 0; i < LoadedModels.Count; i++)
         {
             if (LoadedModels[i].Name == modelname)
             {
                 return LoadedModels[i];
             }
         }
         Model Loaded = null;
         try
         {
             Loaded = LoadModel(modelname);
         }
         catch (Exception ex)
         {
             SysConsole.Output(OutputType.ERROR, ex.ToString());
         }
         if (Loaded == null)
         {
             if (norecurs)
             {
                 Loaded = new Model(modelname) { Engine = this, Root = Matrix4.Identity, Meshes = new List<ModelMesh>(), RootNode = null };
             }
             else
             {
                 norecurs = true;
                 Model m = GetModel("cube");
                 norecurs = false;
                 Loaded = new Model(modelname) { Engine = this, Root = m.Root, RootNode = m.RootNode, Meshes = m.Meshes, Original = m.Original };
             }
         }
         LoadedModels.Add(Loaded);
         return Loaded;
     }
 }
Beispiel #10
0
 public Model FromScene(Model3D scene, string name, AnimationEngine engine)
 {
     if (scene.Meshes.Count == 0)
     {
         throw new Exception("Scene has no meshes! (" + name + ")");
     }
     Model model = new Model(name);
     model.Engine = this;
     model.Original = scene;
     model.Root = convert(scene.MatrixA);
     foreach (Model3DMesh mesh in scene.Meshes)
     {
         if (mesh.Name.ToLowerFast().Contains("collision") || mesh.Name.ToLowerFast().Contains("norender"))
         {
             continue;
         }
         ModelMesh modmesh = new ModelMesh(mesh.Name);
         modmesh.vbo.Prepare();
         bool hastc = mesh.TexCoords.Count == mesh.Vertices.Count;
         bool hasn = mesh.Normals.Count == mesh.Vertices.Count;
         if (!hasn)
         {
             SysConsole.Output(OutputType.WARNING, "Mesh has no normals! (" + name + ")");
         }
         if (!hastc)
         {
             SysConsole.Output(OutputType.WARNING, "Mesh has no texcoords! (" + name + ")");
         }
         for (int i = 0; i < mesh.Vertices.Count; i++)
         {
             BEPUutilities.Vector3 vertex = mesh.Vertices[i];
             modmesh.vbo.Vertices.Add(new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z));
             if (!hastc)
             {
                 modmesh.vbo.TexCoords.Add(new Vector3(0, 0, 0));
             }
             else
             {
                 BEPUutilities.Vector2 texCoord = mesh.TexCoords[i];
                 modmesh.vbo.TexCoords.Add(new Vector3((float)texCoord.X, 1 - (float)texCoord.Y, 0));
             }
             if (!hasn)
             {
                 modmesh.vbo.Normals.Add(new Vector3(0, 0, 1));
             }
             else
             {
                 modmesh.vbo.Normals.Add(new Vector3((float)mesh.Normals[i].X, (float)mesh.Normals[i].Y, (float)mesh.Normals[i].Z));
             }
             modmesh.vbo.Colors.Add(new Vector4(1, 1, 1, 1)); // TODO: From the mesh?
         }
         for (int i = 0; i < mesh.Indices.Count; i++)
         {
             modmesh.vbo.Indices.Add((uint)mesh.Indices[i]);
         }
         int bc = mesh.Bones.Count;
         if (bc > 200)
         {
             SysConsole.Output(OutputType.WARNING, "Mesh has " + bc + " bones! (" + name + ")");
             bc = 200;
         }
         modmesh.vbo.BoneIDs = new Vector4[modmesh.vbo.Vertices.Count].ToList();
         modmesh.vbo.BoneWeights = new Vector4[modmesh.vbo.Vertices.Count].ToList();
         modmesh.vbo.BoneIDs2 = new Vector4[modmesh.vbo.Vertices.Count].ToList();
         modmesh.vbo.BoneWeights2 = new Vector4[modmesh.vbo.Vertices.Count].ToList();
         int[] pos = new int[modmesh.vbo.Vertices.Count];
         for (int i = 0; i < bc; i++)
         {
             for (int x = 0; x < mesh.Bones[i].Weights.Count; x++)
             {
                 int IDa = mesh.Bones[i].IDs[x];
                 float Weighta = (float)mesh.Bones[i].Weights[x];
                 int spot = pos[IDa]++;
                 if (spot > 7)
                 {
                     //SysConsole.Output(OutputType.WARNING, "Too many bones influencing " + vw.VertexID + "!");
                     ForceSet(modmesh.vbo.BoneWeights, IDa, 3, modmesh.vbo.BoneWeights[IDa][3] + Weighta);
                 }
                 else if (spot > 3)
                 {
                     ForceSet(modmesh.vbo.BoneIDs2, IDa, spot - 4, i);
                     ForceSet(modmesh.vbo.BoneWeights2, IDa, spot - 4, Weighta);
                 }
                 else
                 {
                     ForceSet(modmesh.vbo.BoneIDs, IDa, spot, i);
                     ForceSet(modmesh.vbo.BoneWeights, IDa, spot, Weighta);
                 }
             }
         }
         model.Meshes.Add(modmesh);
     }
     model.RootNode = new ModelNode() { Parent = null, Name = scene.RootNode.Name.ToLowerFast() };
     List<ModelNode> allNodes = new List<ModelNode>();
     PopulateChildren(model.RootNode, scene.RootNode, model, engine, allNodes);
     for (int i = 0; i < model.Meshes.Count; i++)
     {
         for (int x = 0; x < scene.Meshes[i].Bones.Count; x++)
         {
             ModelNode nodet = null;
             string nl = scene.Meshes[i].Bones[x].Name.ToLowerFast();
             for (int n = 0; n < allNodes.Count; n++)
             {
                 if (allNodes[n].Name == nl)
                 {
                     nodet = allNodes[n];
                     break;
                 }
             }
             ModelBone mb = new ModelBone() { Offset = convert(scene.Meshes[i].Bones[x].MatrixA) };
             nodet.Bones.Add(mb);
             model.Meshes[i].Bones.Add(mb);
         }
     }
     return model;
 }