Example #1
0
        //  Lazy-loading and then returning reference to model
        //  Doesn't load vertex/index shader and doesn't touch GPU. Use it when you need model data - vertex, triangles, octre...
        public static MyModel GetModelOnlyData(string modelAsset)
        {
            if (string.IsNullOrEmpty(modelAsset))
                return null;

            MyModel model;
            if (!m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            model.LoadData();
            return model;
        }
Example #2
0
        public void RefreshModels(string model, string modelCollision)
        {
            if (model != null)
            {
                Render.ModelStorage = VRage.Game.Models.MyModels.GetModelOnlyData(model);
                var renderModel = Render.GetModel();
                PositionComp.LocalVolumeOffset = renderModel == null ? Vector3.Zero : renderModel.BoundingSphere.Center;
            }

            if (modelCollision != null)
                m_modelCollision = VRage.Game.Models.MyModels.GetModelOnlyData(modelCollision);

            if (Render.ModelStorage != null)
            {
                this.PositionComp.LocalAABB = Render.GetModel().BoundingBox;

                bool idAllocationState = MyEntityIdentifier.AllocationSuspended;
                try
                {
                    MyEntityIdentifier.AllocationSuspended = false;

                    if (Subparts == null)
                        Subparts = new Dictionary<string, MyEntitySubpart>();
                    else
                    {
                        foreach (var existingSubpart in Subparts)
                        {
                            Hierarchy.RemoveChild(existingSubpart.Value);
                            existingSubpart.Value.Close();
                        }
                        Subparts.Clear();
                    }

                    MyEntitySubpart.Data data = new MyEntitySubpart.Data();
                    foreach (var dummy in Render.GetModel().Dummies)
                    {
                        // Check of mirrored matrix of dummy object is under fake, because characters have mirrored dummies
                        // VRAGE TODO: Reenable this check after moving/splitting MyFakes?
                        //if (MyFakes.ENABLE_DUMMY_MIRROR_MATRIX_CHECK)
                        //{
                        //    // This should not be here but if you want to check bad matrices of other types
                        //    if (!(this is MyCharacter))
                        //    {
                        //        Debug.Assert(!dummy.Value.Matrix.IsMirrored());
                        //    }
                        //}

                        if (!MyEntitySubpart.GetSubpartFromDummy(model, dummy.Key, dummy.Value, ref data))
                            continue;

                        MyEntitySubpart subpart = new MyEntitySubpart();
                        subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv;
                        subpart.Render.ColorMaskHsv = Render.ColorMaskHsv;
                        subpart.Init(null, data.File, this, null);

                        // Set this to false becase no one else is responsible for rendering subparts
                        subpart.Render.NeedsDrawFromParent = false;

                        subpart.PositionComp.LocalMatrix = data.InitialTransform;
                        Subparts[data.Name] = subpart;

                        if (InScene)
                            subpart.OnAddedToScene(this);
                    }
                }
                finally
                {
                    MyEntityIdentifier.AllocationSuspended = idAllocationState;
                }

                if (Render.GetModel().GlassData != null)
                {
                    Render.NeedsDraw = true;
                    Render.NeedsDrawFromParent = true;
                }

            }
            else
            {   //entities without model has box with side length = 1 by default
                float defaultBoxHalfSize = 0.5f;
                this.PositionComp.LocalAABB = new BoundingBox(new Vector3(-defaultBoxHalfSize), new Vector3(defaultBoxHalfSize));
            }
        }
 public MyQuantizedBvhAdapter(GImpactQuantizedBvh bvh, MyModel model)
 {
     m_bvh = bvh;
     m_model = model;
 }
        public static List<MyCubeBlockDefinition.MountPoint> AutogenerateMountpoints(MyModel model, float gridSize)
        {
            var shapes = model.HavokCollisionShapes;

            if (shapes == null)
            {
                if (model.HavokBreakableShapes == null)
                    return new List<MyCubeBlockDefinition.MountPoint>();
                shapes = new HkShape[] { model.HavokBreakableShapes[0].GetShape() };
            }

            return AutogenerateMountpoints(shapes, gridSize);
        }
        private static void DebugDrawTexturesInfo(MyModel model, ref int row)
        {
            HashSet<string> textures = new HashSet<string>();
            foreach (MyMesh mesh in model.GetMeshList())
            {
                Debug.Assert(mesh.Material.Textures != null);
                if (mesh.Material.Textures == null) continue;
                foreach (string texture in mesh.Material.Textures.Values)
                    if (!string.IsNullOrWhiteSpace(texture)) textures.Add(texture);
            }

            foreach (string texture in textures.OrderBy(s=>s, StringComparer.InvariantCultureIgnoreCase))
                MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), texture, Color.White, DEBUG_SCALE);
            row++;
        }
Example #6
0
        //  Lazy-loading and then returning reference to model
        //  Param forceReloadMwm: Reloads MWM even when it is already in cache. Useful when debugging.
        //  May return null on failure.
        public static MyModel GetModelOnlyAnimationData(string modelAsset, bool forceReloadMwm = false)
        {
            MyModel model;
            if (forceReloadMwm || !m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            try
            {
                model.LoadAnimationData();
                return model;
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine(e);
                Debug.Fail("Cannot load asset \"" + modelAsset + "\".\n" + e.Message);
                return null;
            }
        }
Example #7
0
        public static MyModel GetModelOnlyModelInfo(string modelAsset)
        {
            Debug.Assert(modelAsset != null);
            MyModel model;
            if (!m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            model.LoadOnlyModelInfo();
            return model;

        }
Example #8
0
        //  Lazy-loading and then returning reference to model
        //  Doesn't load vertex/index shader and doesn't touch GPU. Use it when you need model data - vertex, triangles, octre...
        public static MyModel GetModelOnlyDummies(string modelAsset)
        {
            MyModel model;
            if (!m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            model.LoadOnlyDummies();
            return model;
        }
        // Don't call remove reference on this, this shape is pooled
        public HkShape GetDebrisShape(MyModel model, HkShapeType shapeType)
        {
            MyModelShapeInfo info = new MyModelShapeInfo();
            info.Model = model;
            info.ShapeType = shapeType;

            HkShape shape;
            if (!m_shapes.TryGetValue(info, out shape))
            {
                shape = CreateShape(model, shapeType);
                m_shapes.Add(info, shape);
            }
            return shape;
        }
        HkShape CreateShape(MyModel model, HkShapeType shapeType)
        {
            if (model.HavokCollisionShapes != null && model.HavokCollisionShapes.Length > 0)
            {
                HkShape sh;
                if (model.HavokCollisionShapes.Length == 1)
                {
                    sh = model.HavokCollisionShapes[0];
                    sh.AddReference();
                }
                else
                {
                    sh = new HkListShape(model.HavokCollisionShapes,HkReferencePolicy.None);
                }
                return sh;          
            }

            switch(shapeType)
            {
                case HkShapeType.Box:
                    Vector3 halfExtents = (model.BoundingBox.Max - model.BoundingBox.Min) / 2;
                    return new HkBoxShape(Vector3.Max(halfExtents - 0.1f, new Vector3(0.05f)), 0.02f);
                    break;

                case HkShapeType.Sphere:
                    return new HkSphereShape(model.BoundingSphere.Radius);
                    break;

                case HkShapeType.ConvexVertices:
                    m_tmpVerts.Clear();
                    for (int i = 0; i < model.GetVerticesCount(); i++)
                    {
                        m_tmpVerts.Add(model.GetVertex(i));
                    }

                    return new HkConvexVerticesShape(m_tmpVerts.GetInternalArray(), m_tmpVerts.Count, true, 0.1f);
                    break;
            }
            throw new InvalidOperationException("This shape is not supported");
        }
Example #11
0
 public MyQuantizedBvhAdapter(GImpactQuantizedBvh bvh, MyModel model)
 {
     m_bvh   = bvh;
     m_model = model;
 }
Example #12
0
        //  Lazy-loading and then returning reference to model
        public static MyModel GetModelOnlyAnimationData(string modelAsset)
        {
            MyModel model;
            if (!m_models.TryGetValue(modelAsset, out model))
            {
                model = new MyModel(modelAsset);
                m_models[modelAsset] = model;
            }

            model.LoadAnimationData();
            return model;
        }