예제 #1
0
        void SetMaterial(MSceneObject mo, string sMaterialID)
        {
            if (sMaterialID == null)
            {
                sMaterialID = MMaterial.DEFAULT_MATERIAL;
            }
            //MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID);
            MObject   o   = MScene.MaterialRoot.FindModuleByName(sMaterialID);
            MMaterial mat = null;

            if (o != null && o.Type == MObject.EType.Material)
            {
                mat = (MMaterial)o;
                if (mat != null)
                {
                    mo.SetMaterial(mat);
                    mat.MaterialID = sMaterialID;
                }
            }

            if (MassiveTools.IsURL(sMaterialID))
            {
                mat = (MMaterial) new MMaterial("URLShader");
                MShader DefaultShader = (MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER);
                mat.AddShader(DefaultShader);
                mat.ReplaceTexture(Globals.TexturePool.GetTexture(sMaterialID));
                mat.MaterialID = sMaterialID;
                MScene.MaterialRoot.Add(mat);
                mo.SetMaterial(mat);
                mo.material.Setup();
            }
        }
예제 #2
0
        private void Network_TextureHandler(object sender, Massive.Events.TextureEvent e)
        {
            MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID);
            MObject      o  = MScene.MaterialRoot.FindModuleByName(e.TextureID);

            if (o != null && o.Type == MObject.EType.Material)
            {
                MMaterial mat = (MMaterial)o;
                mo.SetMaterial(mat);
            }
            else
            {
                if (MassiveTools.IsURL(e.TextureID))
                {
                    MMaterial mat           = (MMaterial) new MMaterial("URLShader");
                    MShader   DefaultShader = (MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER);
                    mat.AddShader(DefaultShader);
                    mat.ReplaceTexture(Globals.TexturePool.GetTexture(e.TextureID));
                    MScene.MaterialRoot.Add(mat);
                    mo.SetMaterial(mat);
                    mo.material.Setup();
                    MMessageBus.ChangedTexture(this, e.InstanceID, e.TextureID);
                }
                else
                {
                    Console.WriteLine("Object " + e.InstanceID + " was null");
                    MMessageBus.Error(this, "Could not find Material:" + e.TextureID);
                }
            }
        }
예제 #3
0
        public static MSceneObject LoadTemplate(string TemplateID)
        {
            MBuildingBlock bb = MBuildParts.GetBlock(TemplateID);

            if (bb == null)
            {
                Console.WriteLine("WARNING: MSpawnHandler.LoadTemplate " + TemplateID + " not found in blocks");
                return(null);
            }

            MSceneObject o = null;

            if (bb.Type == MBuildParts.MAnimatedModel)
            {
                o = Helper.CreateAnimatedModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
                MAnimatedModel man = (MAnimatedModel)o;
                man.BoneOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
            }

            if (bb.Type == MBuildParts.MModel)
            {
                o = Helper.CreateModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
            }

            MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(bb.MaterialID);

            if (mat == null)
            {
                Console.WriteLine("MSpawnHandler.LoadTemplate " + bb.MaterialID + " was null");
            }
            o.SetMaterial(mat);

            Vector3d size = MassiveTools.VectorFromArray(bb.Size);

            MPhysicsObject.EShape shape = GetShape(bb.PhysicsShape);
            if (shape != MPhysicsObject.EShape.NULL)
            {
                MPhysicsObject mpo = new MPhysicsObject(o, TemplateID + "_physics", bb.Weight, shape,
                                                        true, size);
                mpo.SetSleep(5);
                mpo.SetFriction(0.5);
                if (shape != MPhysicsObject.EShape.Sphere)
                {
                    mpo.SetAngularFactor(0.0, 0.0, 0.0);
                    mpo.SetDamping(0.5, 0.5);
                    mpo.SetRestitution(0.5);
                }
                else
                {
                    mpo.SetDamping(0.1, 0.1);
                    mpo.SetRestitution(0.8);
                }
            }

            o.TemplateID               = TemplateID;
            o.InstanceID               = TemplateID;
            o.IsTransparent            = bb.IsTransparent;
            o.transform.RotationOffset = Quaterniond.FromEulerAngles(MassiveTools.VectorFromArray(bb.RotationOffset));
            o.Setup();

            AddSubmodules(bb, o);

            return(o);
        }