Exemple #1
0
        public override void CopyTo(MObject mo)
        {
            base.CopyTo(mo);

            MModel md = (MModel)mo;

            md.Filename = Filename;
        }
Exemple #2
0
 void SetupTree()
 {
     tree = new MModel(EType.Model, "InstanceTree");
     tree.DistanceThreshold = 15000;
     tree.Load(TreeModel);
     treemesh = (MMesh)tree.FindModuleByType(EType.Mesh);
     treemesh.transform.Scale = new Vector3d(1, 1, 1);
     treemesh.Setup();
     //MScene.Background.Add(tree);
 }
Exemple #3
0
 void SetupMesh()
 {
     tree = new MModel(EType.Model, "BaseModel");
     tree.DistanceThreshold = 5000;
     tree.Load(ModelPath);
     mesh = (MMesh)tree.FindModuleByType(EType.Mesh);
     if (mesh == null)
     {
         return;
     }
     mesh.transform.Scale = new Vector3d(1, 1, 1);
     mesh.Setup();
 }
Exemple #4
0
        public static MModel GetMesh(string sFilename)
        {
            //AssimpContext importer = new AssimpContext();
            //importer.SetConfig(new NormalSmoothingAngleConfig(66.0f));

            if (Pool.ContainsKey(sFilename))
            {
                return(Pool[sFilename]);
            }

            MModel    model = new MModel();
            MMaterial mat   = (MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL);

            model.AddMaterial(mat);
            model.Load(sFilename);
            Pool.Add(sFilename, model);
            return(model);
        }
Exemple #5
0
        public static MModel CreateModel(MObject parent, string sName, string Filename, Vector3d pos)
        {
            if (parent == null)
            {
                parent = MScene.ModelRoot;
            }
            MModel m = new MModel(MObject.EType.Model, sName);

            m.transform.Position = pos;
            try
            {
                m.Load(Filename);
            }
            catch (Exception e)
            {
                Console.WriteLine("CreateModel: Failed to load model:" + sName + " :" + Filename);
            }
            parent.Add(m);
            return(m);
        }
Exemple #6
0
        public static MModel SpawnModel(MObject parent, string TemplateID, string OwnerID, string sName, Vector3d pos)
        {
            MModel mo = (MModel)MScene.TemplateRoot.FindModuleByInstanceID(TemplateID);
            //MMesh sm = (MMesh)mo.FindModuleByType(MObject.EType.Mesh);

            MModel m = new MModel(MObject.EType.Model, sName);

            m.OwnerID            = OwnerID;
            m.transform.Position = pos;
            parent.Add(m);
            for (int i = 0; i < mo.Modules.Count; i++)
            {
                if (mo.Modules[i].Type != MObject.EType.Mesh)
                {
                    continue;
                }

                MMesh mr = (MMesh)mo.Modules[i];

                MMesh mesh = new MMesh(sName);
                mesh.OwnerID = mr.OwnerID;
                m.Add(mesh);
                mesh.VBO            = mr.VBO;
                mesh.VAO            = mr.VAO;
                mesh.EBO            = mr.EBO;
                mesh.Indices        = mr.Indices;
                mesh.IndicesLength  = mr.IndicesLength;
                mesh.Vertices       = mr.Vertices;
                mesh.VerticesLength = mr.VerticesLength;
                mesh.Normals        = mr.Normals;
                //mesh.material = mo.material;
                m.material = mo.material;
            }

            return(m);
        }
Exemple #7
0
        public void InitializePlanets()
        {
            //GravityIndicator = Helper.CreateCube(MScene.AstroRoot, "GravitySphere", Vector3d.Zero);
            //GravityIndicator.transform.Scale = new Vector3d(0.05, 0.1, 0.1);
            //GravityIndicator.OwnerID = "MasterAstronomer";
            //MScene.AstroRoot.Add(GravityIndicator);
            //GravityIndicator.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL));
            CreateShaders();

            for (int i = 0; i < Bodies.Count; i++)
            {
                MAstroBody m = Bodies[i];
                //m.Radius = m.Radius * 0.5;
                if (m.IsTemplate == true)
                {
                    continue;
                }
                m.ListIndex = i;
                Vector3d    pos  = m.Position + new Vector3d(-m.Radius.X, 0, 0) * (m.HasRings == true ? 3.0 : 1.1);
                MServerZone zone = new MServerZone("MASTER_ASTRONOMER", m.Name, "Astronomical",
                                                   MassiveTools.ToVector3_Server(pos));
                zone.Rotation    = MassiveTools.ArrayFromQuaterniond(Quaterniond.Identity);
                zone.Description = m.Description + " \nRadius:" + m.Radius;
                MMessageBus.AddZone(this, zone);
                //Extensions.LookAt(m.Position + m.Radius * 2, m.Position), m.Name));

                MSceneObject mo;
                //planet files contain uvs for mercator
                if (m.HasAtmosphere)
                {
                    CurrentNear = m;
                    mo          = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\earth.3ds", Vector3d.Zero);
                    //mo = Helper.CreateSphere(MScene.AstroRoot, 3, "Planet");
                    //mo.transform.Scale = m.Radius * 1.00055;
                    mo.transform.Scale = m.Radius;
                }
                else
                {
                    mo = Helper.CreateModel(MScene.AstroRoot, m.Name, @"Models\planets\planet_sphere2.3ds", Vector3d.Zero);
                    mo.transform.Scale = m.Radius;
                }

                if (m.HasRings)
                {
                    MModel ring = Helper.CreateModel(MScene.Priority2, m.Name + "_rings", @"Models\planets\planet_rings.3ds", Vector3d.Zero);
                    ring.transform.Position = m.Position;
                    ring.transform.Rotation = Quaterniond.FromEulerAngles(0, 0, 5 * Math.PI / 180);
                    ring.transform.Scale    = m.Radius;
                    ring.InstanceID         = m.Name;
                    ring.TemplateID         = m.Name;
                    ring.DistanceThreshold  = m.Radius.X * 12;
                    ring.OwnerID            = "MasterAstronomer";
                    MMaterial ringmat = new MMaterial(m.Name + "_mat");
                    ringmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                    MTexture ringtex = Globals.TexturePool.GetTexture(@"Textures\Planets\saturn_rings.png");
                    ringmat.SetDiffuseTexture(ringtex);
                    ring.SetMaterial(ringmat);

                    MPhysicsObject ringpo = new MPhysicsObject(ring, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh, false, m.Radius);
                    ringpo.SetLinearFactor(0, 0, 0);
                    ringpo.SetRestitution(0.5);
                }

                mo.transform.Position = m.Position;
                //mo.transform.Scale = m.Radius * 1.9999;

                mo.InstanceID        = m.Name;
                mo.TemplateID        = m.Name;
                mo.OwnerID           = "MasterAstronomer";
                mo.DistanceThreshold = m.Radius.X * 110002; //distance at which it becomes visible
                //MModel mod = (MModel)mo.FindModuleByType(EType.Model);
                //mod.DistanceThreshold = mo.DistanceThreshold;
                //MMesh met = (MMesh)mod.FindModuleByType(EType.Mesh);
                //if ( met != null ) {
                //met.DistanceThreshold = mo.DistanceThreshold;
                //}
                mo.Tag = m;
                m.Tag  = mo;

                //now that we have a 3d model, apply some progressive textures (will auto-switch with smooth transition in shader)
                MMaterial mat = new MMaterial(m.Name + "_mat");
                mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                MTexture tex = Globals.TexturePool.GetTexture(m.TextureName);
                mat.SetDiffuseTexture(tex);
                mo.SetMaterial(mat);
                MTexture tex2 = Globals.TexturePool.GetTexture("Textures\\terrain\\sand01b.jpg");
                mat.SetMultiTexture(tex2);
                MTexture tex3 = Globals.TexturePool.GetTexture("Textures\\terrain\\water.jpg");
                mat.SetNormalMap(tex3);

                double dia = 2.0 * Math.PI * m.Radius.X * 0.0000001;
                //double dia = 1;
                mat.Tex2CoordScale = new Vector2((float)dia, (float)dia);
                mo.SetMaterial(mat);

                MScene.MaterialRoot.Add(mat);

                if (m.HasAtmosphere)
                {
                    if (Settings.DrawTerrains == true)
                    {
                        m.AddDynamicTerrain(); //adds tile based terrain (from e.g. tile service)
                    }

                    //MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.ConcaveMesh,
                    //false, m.Radius);
                    MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere,
                                                           false, m.Radius);
                    //po.SetLinearFactor(0, 0, 0);
                    //po.SetRestitution(0.5);
                    //MSphere moc = Helper.CreateSphere(MScene.AstroRoot, 3, m.Name+ "Clouds", Vector3d.Zero);

                    MModel moc = Helper.CreateModel(MScene.AstroRoot, m.Name + "_clouds", @"Models\planets\clouds.3ds", Vector3d.Zero);
                    moc.CastsShadow        = false;
                    moc.transform.Position = m.Position;
                    moc.transform.Scale    = m.Radius;
                    moc.DistanceThreshold  = m.Radius.X * 3;
                    //moc.transform.Scale = m.Radius*2.1;
                    moc.InstanceID = m.Name;
                    moc.TemplateID = m.Name;
                    moc.OwnerID    = "MasterAstronomer";
                    moc.Tag        = m;

                    MMaterial cmat = new MMaterial("CloudMat");
                    cmat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                    cmat.Opacity = 1;
                    cmat.IsSky   = 1;
                    // = new MTexture("CloudTex");
                    MTexture ctex = Globals.TexturePool.GetTexture(CloudTexURL);
                    ctex.Additive = false;
                    cmat.SetDiffuseTexture(ctex);
                    moc.SetMaterial(cmat);
                    MScene.MaterialRoot.Add(cmat);

                    MModel sky = Helper.CreateModel(MScene.AstroRoot, m.Name + "_sky", @"Models\sky.3ds", Vector3d.Zero);
                    sky.CastsShadow        = false;
                    sky.transform.Position = m.Position;
                    sky.transform.Scale    = m.Radius;
                    //moc.transform.Scale = m.Radius*2.1;
                    sky.InstanceID = m.Name;
                    sky.TemplateID = m.Name;
                    sky.OwnerID    = "MasterAstronomer";
                    sky.Tag        = m;
                    sky.SetMaterial(cmat);
                    sky.DistanceThreshold = m.Radius.X * 4;
                    MObjectAnimation ani = new MObjectAnimation();
                    ani.AngleOffset = Quaterniond.FromEulerAngles(0, 0.002, 0);
                    ani.Speed       = 1;
                    sky.Add(ani);

                    sky.SetMaterial(MSkyMaterial);

                    /*MMaterial csky = new MMaterial("Skymat");
                     * csky.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER));
                     * csky.Opacity = 0.5;
                     * csky.IsSky = 1;
                     * // = new MTexture("CloudTex");
                     * MTexture cSkyTex = Globals.TexturePool.GetTexture(OpaqueCloudTexURL);
                     * cSkyTex.Additive = false;
                     * csky.SetDiffuseTexture(cSkyTex);
                     * sky.SetMaterial(csky);
                     * MScene.MaterialRoot.Add(csky);
                     */



                    /* MSphere water = Helper.CreateSphere(MScene.ModelRoot, 5, "Water");
                     * water.transform.Position = m.Position;
                     * water.transform.Scale = m.Radius * 2.00;
                     * MMaterial waterman = new MMaterial("Watermat");
                     * MShader shader = new MShader("watershader");
                     * shader.Load("ocean_vs.glsl", "ocean_fs.glsl");
                     * shader.Bind();
                     * shader.SetInt("diffuseTexture", 0);
                     * shader.SetInt("shadowMap", 1);
                     * waterman.AddShader(shader);
                     * water.SetMaterial(waterman);
                     */
                    //water.SetMaterial((MMaterial)MScene.MaterialRoot.FindModuleByName(MMaterial.DEFAULT_MATERIAL));
                }
                else
                {
                    MPhysicsObject po = new MPhysicsObject(mo, "Physics", 0, MPhysicsObject.EShape.Sphere, false,
                                                           m.Radius * 0.999);
                    po.SetLinearFactor(0, 0, 0);
                    po.SetRestitution(0.5);
                }
                m.Setup();
                //Console.WriteLine("Created:" + mo.Name + ":" + (mo.transform.Position) + " R:" + m.Radius);
            }
        }