示例#1
0
        void AddPhysXComponentsRecursive(ShapeComponentCollection list, ShapeCollection entityList, ShapeBase parent)
        {
            if (parent.ShapeVirtualCounter > 0 || !parent.Modifiable)
            {
                return;
            }
            if (parent.ComponentCount > 0)
            {
                foreach (ShapeComponent comp in parent.Components)
                {
                    if (!comp.Missing)
                    {
                        continue;
                    }
                    if (comp.DisplayName == "vPhysXRigidBody" || comp.DisplayName == "vPhysXCharacterController")
                    {
                        // Catch invalid casts
                        try
                        {
                            UInt32 iValue = System.Convert.ToUInt32(comp.GetPropertyValue("m_iCollisionBitmask", false));
                            if (iValue != 0)
                            {
                                list.Add(comp);
                            }
                        }
                        catch (InvalidCastException)
                        {}
                    }
                }
            }
            EntityShape entity = parent as EntityShape;

            if (entity != null && (entity.EntityClass == "vPhysXEntity" || entity.EntityClass == "LineFollowerEntity_cl"))
            {
                entityList.Add(entity);
            }

            if (parent.HasChildren())
            {
                foreach (ShapeBase shape in parent.ChildCollection)
                {
                    AddPhysXComponentsRecursive(list, entityList, shape);
                }
            }
        }
示例#2
0
 void SynchronizeOwnComponents()
 {
     if (Components == null)
     Components = new ShapeComponentCollection();
       EngineEntity.SynchronizeOwnComponents(this, Components);
       if (ComponentCount == 0)
     Components = null;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="_v3dLayer"></param>
 /// <param name="_newConfig"></param>
 public PostProcessorsChangedAction(V3DLayer v3dLayer, ShapeComponentCollection oldConfig, ShapeComponentCollection newConfig)
 {
     _v3dLayer = v3dLayer;
       _oldConfig = oldConfig;
       _newConfig = newConfig;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="_v3dLayer"></param>
 /// <param name="_newConfig"></param>
 public PostProcessorsChangedAction(V3DLayer v3dLayer, ShapeComponentCollection oldConfig, ShapeComponentCollection newConfig)
 {
     _v3dLayer  = v3dLayer;
     _oldConfig = oldConfig;
     _newConfig = newConfig;
 }
        /// <summary>
        /// This function converts all physX related entities/components to new Havok plugin
        /// </summary>
        void MigrateToHavokComponents()
        {
            // PhysX plugin is still loaded? Then don't do anything
              IEditorPluginModule physXPlugin = EditorManager.GetPluginByName("PhysXEditorPlugin.EditorPlugin");
              if (physXPlugin != null && physXPlugin.Initialized)
            return;

              // collect all physX specific components
              ShapeComponentCollection physXComponents = new ShapeComponentCollection();
              ShapeCollection physXEntities = new ShapeCollection();
              foreach (Layer layer in EditorManager.Scene.Layers)
            if (layer.Modifiable && layer.Loaded)
              AddPhysXComponentsRecursive(physXComponents, physXEntities, layer.Root);

              if (physXComponents.Count == 0 && physXEntities.Count == 0)
            return;

              // prompt a dialog
              DialogResult res = EditorManager.ShowMessageBox("nVidia PhysX binding specific components/entities have been found in loaded layers.\n\nShould these be permanently converted to Havok components?", "nVidia PhysX plugin not loaded", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
              if (res != DialogResult.Yes)
            return;

              int iConvertedCount = 0;

              // build a list of actions for the component replacement
              if (physXComponents.Count > 0)
              {
            GroupAction actions = new GroupAction("Migrate to Havok components");
            foreach (ShapeComponent oldComp in physXComponents)
            {

              ShapeComponent newComp = null;
              if (oldComp.DisplayName == "vPhysXRigidBody")
              {
            newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokRigidBody");
            MigrateRigidBodyProperties(oldComp, newComp);
              }
              else if (oldComp.DisplayName == "vPhysXCharacterController")
              {
            newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokCharacterController");
            MigrateCharacterControllerProperties(oldComp, newComp);
              }
              if (newComp == null)
            continue;
              // action to remove the old component and add the new one
              actions.Add(new RemoveShapeComponentAction((ShapeBase)oldComp.Owner, oldComp));
              actions.Add(new AddShapeComponentAction((ShapeBase)oldComp.Owner, newComp));
              iConvertedCount++;
            }
            // trigger the conversion action
            EditorManager.Actions.Add(actions);
              }

              if (physXEntities.Count > 0)
              {
            GroupAction actions = new GroupAction("Migrate entities classes");
            foreach (EntityShape entity in physXEntities)
            {
              ShapeComponent newComp = null;
              if (entity.EntityClass == "vPhysXEntity")
              {
            newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokRigidBody");
            MigratePhysXEntityProperties(entity.EntityProperties, newComp);
              }
              else if (entity.EntityClass == "LineFollowerEntity_cl")
              {
            newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "VLineFollowerComponent");
            MigrateLineFollowerEntityProperties(entity.EntityProperties, newComp);
              }
              if (newComp == null)
            continue;
              // we convert to base entity class and attach a component instead
              actions.Add(SetPropertyAction.CreateSetPropertyAction(entity, "EntityClass", "VisBaseEntity_cl"));
              actions.Add(new AddShapeComponentAction(entity, newComp));
              iConvertedCount++;
            }
            // trigger the conversion action
            EditorManager.Actions.Add(actions);
            }

              EditorManager.ShowMessageBox(iConvertedCount.ToString()+" Component(s) have been successfully converted.\n\nSince physics engine have quite different behavior, the parameters might have to be tweaked to match old behavior.", "PhysX to Havok component conversion", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        void AddPhysXComponentsRecursive(ShapeComponentCollection list, ShapeCollection entityList, ShapeBase parent)
        {
            if (parent.ShapeVirtualCounter > 0 || !parent.Modifiable)
            return;
              if (parent.ComponentCount > 0)
              {
            foreach (ShapeComponent comp in parent.Components)
            {
              if (!comp.Missing)
            continue;
              if (comp.DisplayName == "vPhysXRigidBody" || comp.DisplayName == "vPhysXCharacterController")
              {
            // Catch invalid casts
            try
            {
              UInt32 iValue = System.Convert.ToUInt32(comp.GetPropertyValue("m_iCollisionBitmask", false));
              if (iValue != 0)
                list.Add(comp);
            }
            catch(InvalidCastException)
            {}
              }
            }
              }
              EntityShape entity = parent as EntityShape;
              if (entity != null && (entity.EntityClass == "vPhysXEntity" || entity.EntityClass == "LineFollowerEntity_cl"))
              {
            entityList.Add(entity);
              }

              if (parent.HasChildren())
            foreach (ShapeBase shape in parent.ChildCollection)
              AddPhysXComponentsRecursive(list, entityList, shape);
        }
示例#7
0
        /// <summary>
        /// This function converts all physX related entities/components to new Havok plugin
        /// </summary>
        void MigrateToHavokComponents()
        {
            // PhysX plugin is still loaded? Then don't do anything
            IEditorPluginModule physXPlugin = EditorManager.GetPluginByName("PhysXEditorPlugin.EditorPlugin");

            if (physXPlugin != null && physXPlugin.Initialized)
            {
                return;
            }

            // collect all physX specific components
            ShapeComponentCollection physXComponents = new ShapeComponentCollection();
            ShapeCollection          physXEntities   = new ShapeCollection();

            foreach (Layer layer in EditorManager.Scene.Layers)
            {
                if (layer.Modifiable && layer.Loaded)
                {
                    AddPhysXComponentsRecursive(physXComponents, physXEntities, layer.Root);
                }
            }

            if (physXComponents.Count == 0 && physXEntities.Count == 0)
            {
                return;
            }

            // prompt a dialog
            DialogResult res = EditorManager.ShowMessageBox("nVidia PhysX binding specific components/entities have been found in loaded layers.\n\nShould these be permanently converted to Havok components?", "nVidia PhysX plugin not loaded", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res != DialogResult.Yes)
            {
                return;
            }

            int iConvertedCount = 0;

            // build a list of actions for the component replacement
            if (physXComponents.Count > 0)
            {
                GroupAction actions = new GroupAction("Migrate to Havok components");
                foreach (ShapeComponent oldComp in physXComponents)
                {
                    ShapeComponent newComp = null;
                    if (oldComp.DisplayName == "vPhysXRigidBody")
                    {
                        newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokRigidBody");
                        MigrateRigidBodyProperties(oldComp, newComp);
                    }
                    else if (oldComp.DisplayName == "vPhysXCharacterController")
                    {
                        newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokCharacterController");
                        MigrateCharacterControllerProperties(oldComp, newComp);
                    }
                    if (newComp == null)
                    {
                        continue;
                    }
                    // action to remove the old component and add the new one
                    actions.Add(new RemoveShapeComponentAction((ShapeBase)oldComp.Owner, oldComp));
                    actions.Add(new AddShapeComponentAction((ShapeBase)oldComp.Owner, newComp));
                    iConvertedCount++;
                }
                // trigger the conversion action
                EditorManager.Actions.Add(actions);
            }

            if (physXEntities.Count > 0)
            {
                GroupAction actions = new GroupAction("Migrate entities classes");
                foreach (EntityShape entity in physXEntities)
                {
                    ShapeComponent newComp = null;
                    if (entity.EntityClass == "vPhysXEntity")
                    {
                        newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "vHavokRigidBody");
                        MigratePhysXEntityProperties(entity.EntityProperties, newComp);
                    }
                    else if (entity.EntityClass == "LineFollowerEntity_cl")
                    {
                        newComp = (ShapeComponent)EditorManager.EngineManager.ComponentClassManager.CreateCollection(null, "VLineFollowerComponent");
                        MigrateLineFollowerEntityProperties(entity.EntityProperties, newComp);
                    }
                    if (newComp == null)
                    {
                        continue;
                    }
                    // we convert to base entity class and attach a component instead
                    actions.Add(SetPropertyAction.CreateSetPropertyAction(entity, "EntityClass", "VisBaseEntity_cl"));
                    actions.Add(new AddShapeComponentAction(entity, newComp));
                    iConvertedCount++;
                }
                // trigger the conversion action
                EditorManager.Actions.Add(actions);
            }

            EditorManager.ShowMessageBox(iConvertedCount.ToString() + " Component(s) have been successfully converted.\n\nSince physics engine have quite different behavior, the parameters might have to be tweaked to match old behavior.", "PhysX to Havok component conversion", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }