public void ValidityCheck(ModelComponent targetToValidate)
 {
     IsValid = targetToValidate == null ||
               Entity == null ||
               targetToValidate.Entity == null ||
               (targetToValidate.Entity.Id != Entity.Id &&
                RecurseCheckChildren(Entity.Transform.Children, targetToValidate.Entity.Transform) &&
                CheckParent(targetToValidate.Entity.Transform)
               );
 }
Beispiel #2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            font = Content.Load<SpriteFont>("Font");
            teapot = Content.Load<Model>("Teapot");
            batch = new SpriteBatch(GraphicsDevice);

            BuildUI();

            spriteComponent = new SpriteComponent { SpriteProvider = new SpriteFromSheet { Sheet = Content.Load<SpriteSheet>("SpriteSheet") } };
            modelComponent = new ModelComponent { Model = teapot };
            modelComponent2 = new ModelComponent { Model = teapot };
            modelComponent3 = new ModelComponent { Model = teapot };
            entity = new Entity { spriteComponent, modelComponent };
            entity2 = new Entity { modelComponent2 };
            entity3 = new Entity { modelComponent3 };
            SceneSystem.SceneInstance.Scene.Entities.Add(entity);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity2);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity3);

            if (Input.Accelerometer.IsSupported)
                Input.Accelerometer.IsEnabled = true;

            if (Input.Compass.IsSupported)
                Input.Compass.IsEnabled = true;

            if (Input.Gyroscope.IsSupported)
                Input.Gyroscope.IsEnabled = true;

            if (Input.UserAcceleration.IsSupported)
                Input.UserAcceleration.IsEnabled = true;

            if (Input.Gravity.IsSupported)
                Input.Gravity.IsEnabled = true;

            if (Input.Orientation.IsSupported)
                Input.Orientation.IsEnabled = true;

            ChangeScene(0);
        }
Beispiel #3
0
 public ModelNodeTransformLink(ModelComponent parentModelComponent, string nodeName, bool forceRecursive)
 {
     this.parentModelComponent = parentModelComponent;
     this.nodeName             = nodeName;
     this.forceRecursive       = forceRecursive;
 }
 public ModelNodeTransformLink(ModelComponent parentModelComponent, string nodeName, bool forceRecursive)
 {
     this.parentModelComponent = parentModelComponent;
     this.nodeName = nodeName;
     this.forceRecursive = forceRecursive;
 }
Beispiel #5
0
 public ModelViewHierarchyTransformOperation(ModelComponent modelComponent)
 {
     ModelComponent = modelComponent;
 }
Beispiel #6
0
        public void Test()
        {
            var prefab = new PrefabAsset();

            var modelComponent = new ModelComponent();
            var entity = new Entity()
            {
                modelComponent
            };
            prefab.Hierarchy.Entities.Add(entity);
            prefab.Hierarchy.RootEntities.Add(entity.Id);

            var material1 = new MaterialNull();
            IdentifiableHelper.SetId(material1, new Guid("39E2B226-8752-4678-8E93-76FFBFBA337B"));
            var material2 = new MaterialNull();
            IdentifiableHelper.SetId(material2, new Guid("CC4F1B31-FBB7-4360-A3E7-060BDFDA0695"));
            modelComponent.Materials.Add(material1);
            modelComponent.Materials.Add(material2);

            Action<PrefabAsset> checkPrefab = (newPrefab) =>
            {
                var previousEntityDesign = newPrefab.Hierarchy.Entities.FirstOrDefault();

                Assert.NotNull(previousEntityDesign);

                var previousEntity = previousEntityDesign.Entity;


                var component = previousEntity.Get<ModelComponent>();
                Assert.NotNull(component);

                Assert.AreEqual(2, component.Materials.Count);

                var newMaterial1 = component.Materials[0];
                Assert.AreEqual(IdentifiableHelper.GetId(material1), IdentifiableHelper.GetId(newMaterial1));
                var newMaterial2 = component.Materials[1];
                Assert.AreEqual(IdentifiableHelper.GetId(material2), IdentifiableHelper.GetId(newMaterial2));
            };

            // Test yaml serialization
            {
                using (var stream = new MemoryStream())
                {
                    AssetSerializer.Save(stream, prefab);

                    stream.Position = 0;
                    var serializedVersion = Encoding.UTF8.GetString(stream.ToArray());
                    Console.WriteLine(serializedVersion);

                    stream.Position = 0;
                    var newPrefab = (PrefabAsset)AssetSerializer.Load(stream, "myentity");
                    checkPrefab(newPrefab);
                }
            }

            // Test cloning
            var newPrefabClone = (PrefabAsset)AssetCloner.Clone(prefab);
            checkPrefab(newPrefabClone);

            // Test runtime serialization (runtime serialization is removing MaterialNull and replacing it by a null)
            {
                var stream = new MemoryStream();
                var writer = new BinarySerializationWriter(stream) { Context = { SerializerSelector = SerializerSelector.AssetWithReuse } };
                writer.SerializeExtended(entity, ArchiveMode.Serialize);
                writer.Flush();
                stream.Position = 0;

                var reader = new BinarySerializationReader(stream) { Context = { SerializerSelector = SerializerSelector.AssetWithReuse } };

                Entity newEntity = null;
                reader.SerializeExtended(ref newEntity, ArchiveMode.Deserialize);

                Assert.NotNull(newEntity);

                var component = newEntity.Get<ModelComponent>();
                Assert.NotNull(component);

                Assert.AreEqual(2, component.Materials.Count);

                Assert.Null(component.Materials[0]);
                Assert.Null(component.Materials[1]);
            }
        }
Beispiel #7
0
        public static async Task GenerateTestPrefabs(EngineContext engineContext)
        {
            var entityCube = new Entity("Cube");
            var meshComponent = new ModelComponent();
            meshComponent.SubMeshes.Add(new EffectMeshData { EffectData = new EffectData("SimpleCube"), MeshData = MeshDataHelper.CreateBox(100.0f, 100.0f, 100.0f, Color.Gray) });
            entityCube.Set(ModelComponent.Key, meshComponent);
            entityCube.Set(TransformationComponent.Key, new TransformationComponent());
            engineContext.AssetManager.Url.Set(entityCube, "/global_data/cube.hotei#/root");
            engineContext.AssetManager.Save(entityCube);

            var entitySphere = new Entity("Cube");
            meshComponent = new ModelComponent();
            meshComponent.SubMeshes.Add(new EffectMeshData { EffectData = new EffectData("SimpleCube"), MeshData = MeshDataHelper.CreateSphere(100.0f, 30, 30, Color.Gray) });
            entitySphere.Set(ModelComponent.Key, meshComponent);
            entitySphere.Set(TransformationComponent.Key, new TransformationComponent());
            engineContext.AssetManager.Url.Set(entitySphere, "/global_data/sphere.hotei#/root");
            engineContext.AssetManager.Save(entitySphere);
        }
 public RenderModel(ModelComponent modelComponent)
 {
     ModelComponent = modelComponent;
 }
Beispiel #9
0
 public RenderModel(ModelComponent modelComponent)
 {
     RenderMeshesPerEffectSlot = new FastListStruct<FastListStruct<RenderMesh>>(4);
     ModelComponent = modelComponent;
 }
 public ModelViewHierarchyTransformOperation(ModelComponent modelComponent)
 {
     this.modelComponent = modelComponent;
 }