Esempio n. 1
0
        public async Task <GActor> CreateActor(Editor.PlantableItemCreateActorParam param)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var rc = EngineNS.CEngine.Instance.RenderContext;

            var actor = new EngineNS.GamePlay.Actor.GActor();

            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement    = placement;
            placement.Location = param.Location;
            placement.Rotation = EngineNS.Quaternion.GetQuaternion(Vector3.UnitZ, -Vector3.UnitY);
            actor.SpecialName  = "SunActor";

            var initializer = new GDirLightComponentInitializer();

            initializer.SpecialName = "LightData";
            await SetInitializer(rc, actor, actor, initializer);

            this.View = param.View;

            var meshComp     = new EngineNS.GamePlay.Component.GMeshComponent();
            var meshCompInit = new EngineNS.GamePlay.Component.GMeshComponent.GMeshComponentInitializer();

            meshCompInit.SpecialName = "VisualMesh";
            meshCompInit.MeshName    = EngineNS.RName.GetRName("editor/sun.gms", EngineNS.RName.enRNameType.Game);
            var test = meshComp.SetInitializer(rc, actor, actor, meshCompInit);

            actor.AddComponent(meshComp);

            actor.AddComponent(this);
            return(actor);
        }
Esempio n. 2
0
        GActor NewMeshActor(CGfxMesh mesh)
        {
            var rc    = CEngine.Instance.RenderContext;
            var actor = new EngineNS.GamePlay.Actor.GActor();

            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement = placement;
            var meshComp = new EngineNS.GamePlay.Component.GMeshComponent();

            meshComp.SetSceneMesh(rc.ImmCommandList, mesh);
            actor.AddComponent(meshComp);
            return(actor);
        }
Esempio n. 3
0
        public async Task <Actor.GActor> CreateActor(Editor.PlantableItemCreateActorParam param)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var rc = EngineNS.CEngine.Instance.RenderContext;

            var actor = new EngineNS.GamePlay.Actor.GActor();

            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement    = placement;
            placement.Location = param.Location;
            placement.Rotation = EngineNS.Quaternion.GetQuaternion(Vector3.UnitZ, -Vector3.UnitY);

            var meshComp     = new EngineNS.GamePlay.Component.GMeshComponent();
            var meshCompInit = new EngineNS.GamePlay.Component.GMeshComponent.GMeshComponentInitializer();

            meshCompInit.SpecialName = "EditorShow";
            meshCompInit.MeshName    = EngineNS.RName.GetRName("meshes/pointlight.gms", EngineNS.RName.enRNameType.Editor);
            await meshComp.SetInitializer(rc, actor, actor, meshCompInit);

            meshComp.HideInGame = true;
            actor.AddComponent(meshComp);

            meshComp                 = new EngineNS.GamePlay.Component.GMeshComponent();
            meshCompInit             = new EngineNS.GamePlay.Component.GMeshComponent.GMeshComponentInitializer();
            meshCompInit.SpecialName = "SphereVolumeShow";
            meshCompInit.MeshName    = EngineNS.RName.GetRName("meshes/sphere_wireframe.gms", EngineNS.RName.enRNameType.Editor);
            await meshComp.SetInitializer(rc, actor, actor, meshCompInit);

            meshComp.HideInGame = true;
            actor.AddComponent(meshComp);


            var initializer = new GPointLightComponentInitializer();

            initializer.SpecialName = "PointLightComponent";
            await SetInitializer(rc, actor, actor, initializer);

            actor.AddComponent(this);
            actor.AcceptLights = false;

            return(actor);
        }
Esempio n. 4
0
        public override async Task <GamePlay.Actor.GActor> CreateActor(Editor.PlantableItemCreateActorParam param)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var rc = EngineNS.CEngine.Instance.RenderContext;

            var actor = new EngineNS.GamePlay.Actor.GActor();

            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement    = placement;
            placement.Location = param.Location;
            placement.Rotation = EngineNS.Quaternion.GetQuaternion(Vector3.UnitZ, -Vector3.UnitY);

            var meshComp     = new EngineNS.GamePlay.Component.GMeshComponent();
            var meshCompInit = new EngineNS.GamePlay.Component.GMeshComponent.GMeshComponentInitializer();

            meshCompInit.SpecialName = "EditorShow";
            meshCompInit.MeshName    = EngineNS.RName.GetRName("meshes/go_on.gms", EngineNS.RName.enRNameType.Editor);
            await meshComp.SetInitializer(rc, actor, actor, meshCompInit);

            meshComp.HideInGame                = true;
            meshComp.Placement.InheritScale    = false;
            meshComp.Placement.InheritRotation = false;
            actor.AddComponent(meshComp);

            var init = new BoxComponentInitializer();

            init.SpecialName = "NavMeshBoundVolume";
            await SetInitializer(rc, actor, actor, init);

            mLineMeshComponent.Host = actor;
            var mat = actor.Placement.WorldMatrix;

            mLineMeshComponent.OnUpdateDrawMatrix(ref mat);

            actor.AddComponent(this);

            return(actor);
        }
Esempio n. 5
0
        async System.Threading.Tasks.Task <GActor> NewMeshActor(CGfxMeshPrimitives meshPri)
        {
            var rc    = CEngine.Instance.RenderContext;
            var actor = new EngineNS.GamePlay.Actor.GActor();

            actor.ActorId = Guid.NewGuid();
            var placement = new EngineNS.GamePlay.Component.GPlacementComponent();

            actor.Placement = placement;
            var meshComp = new EngineNS.GamePlay.Component.GMeshComponent();
            var mesh     = CEngine.Instance.MeshManager.CreateMesh(rc, meshPri);
            var mtl      = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/defaultmaterial.instmtl"));

            for (int i = 0; i < mesh.MtlMeshArray.Length; ++i)
            {
                await mesh.SetMaterialInstanceAsync(rc, (uint)i, mtl, null);
            }
            meshComp.SetSceneMesh(rc.ImmCommandList, mesh);
            actor.AddComponent(meshComp);

            return(actor);
        }
Esempio n. 6
0
        private async System.Threading.Tasks.Task BuildNavtion()
        {
            var meshList   = new List <EngineNS.Graphics.Mesh.CGfxMeshPrimitives>();
            var matrixList = new List <EngineNS.Matrix>();

            List <EngineNS.Bricks.PhysicsCore.CPhyShape> physhapes = new List <EngineNS.Bricks.PhysicsCore.CPhyShape>();

            using (var i = VP1.World.DefaultScene.Actors.GetEnumerator())
            {
                while (i.MoveNext())
                {
                    EngineNS.GamePlay.Actor.GActor actor = i.Current.Value;
                    //if ((actor.mComponentFlags & EngineNS.GamePlay.Actor.GActor.EComponentFlags.HasPhysics)
                    EngineNS.Bricks.PhysicsCore.GPhysicsComponent component = actor.GetComponentRecursion <EngineNS.Bricks.PhysicsCore.GPhysicsComponent>();
                    EngineNS.Bricks.PhysicsCore.CollisionComponent.GPhysicsCollisionComponent component2 = actor.GetComponentRecursion <EngineNS.Bricks.PhysicsCore.CollisionComponent.GPhysicsCollisionComponent>();
                    if ((component != null && component.PhyActor != null && component.IsEnableNavgation) || (component2 != null && component2.IsEnableNavgation))
                    {
                        //foreach (EngineNS.Bricks.PhysicsCore.CPhyShape shape in component.PhyActor.Shapes)
                        //{
                        //    if (shape.DebugActor == null)
                        //    {
                        //        shape.OnEditorCommitVisual(EngineNS.CEngine.Instance.RenderContext, VP1.Camera, actor);
                        //    }

                        //    if (shape.DebugActor != null)
                        //    {
                        //        EngineNS.GamePlay.Component.GMeshComponent meshcomponent = shape.DebugActor.GetComponent<EngineNS.GamePlay.Component.GMeshComponent>();
                        //        meshList.Add(meshcomponent.SceneMesh.MeshPrimitives);
                        //        matrixList.Add(actor.Placement.WorldMatrix);
                        //    }

                        //}

                        //if (component.PhyActor != null && component.PhyActor.Shapes != null)
                        //{
                        //foreach (var shape in component.PhyActor.Shapes)
                        //{
                        //    if (shape.AreaType > 1 && shape.AreaType < 16)
                        //    {
                        //        physhapes.Add(shape);
                        //        if (shape.DebugActor == null)
                        //        {
                        //            shape.OnEditorCommitVisual(EngineNS.CEngine.Instance.RenderContext, VP1.Camera, actor);
                        //        }
                        //    }
                        //}
                        //}
                        EngineNS.GamePlay.Component.GMeshComponent meshcomponent = actor.GetComponent <EngineNS.GamePlay.Component.GMeshComponent>();
                        if (meshcomponent != null)
                        {
                            meshList.Add(meshcomponent.SceneMesh.MeshPrimitives);
                            matrixList.Add(actor.Placement.WorldMatrix);
                        }
                    }
                }
            }

            //判断为空就不做任何操作了
            if (meshList.Count == 0)
            {
                return;
            }

            EngineNS.BoundingBox aabb = new EngineNS.BoundingBox();
            var mesh = EngineNS.CGeometryMesh.MergeGeoms(EngineNS.CEngine.Instance.RenderContext, meshList, matrixList, ref aabb);
            var geom = new EngineNS.Bricks.RecastBuilder.RCInputGeom();

            geom.LoadMesh(EngineNS.CEngine.Instance.RenderContext, mesh, 1);
            //处理动态区域
            foreach (var shape in physhapes)
            {
                //EngineNS.BoundingBox aabb = new EngineNS.BoundingBox();
                //await shape.AwaitLoadDebugActor();
                //shape.DebugActor.GetAABB(ref aabb);
                //EngineNS.Vector3[] vpoints = aabb.GetCorners();
                //float[] points = new float[vpoints.Length * 3];
                //for (int i = 0; i < vpoints.Length; i++)
                //{
                //    points[i * 3] = vpoints[i].X;
                //    points[i * 3 + 1] = vpoints[i].Y;
                //    points[i * 3 + 2] = vpoints[i].Z;
                //}

                //EngineNS.Support.CBlobObject blob = new EngineNS.Support.CBlobObject();
                //unsafe
                //{
                //    fixed (float* p = &points[0])
                //    {
                //        IntPtr ptr = (IntPtr)p;
                //        blob.PushData(ptr, (uint)(sizeof(float) * points.Length));
                //    }
                //}
                //geom.CreateConvexVolumes(shape.AreaType, blob);
            }
            RCTileMeshBuilder.InputGeom = geom;

            //单独放这里处理一次 不能放在BuildNavMesh
            foreach (var weak in NavMeshBoundVolumes)
            {
                EngineNS.GamePlay.Actor.GActor actor;
                if (weak.TryGetTarget(out actor))
                {
                    AddActorToNavModifierVolume(actor);
                }
            }

            foreach (var weak in NavModifierVolumes)
            {
                EngineNS.GamePlay.Actor.GActor actor;
                if (weak.TryGetTarget(out actor))
                {
                    AddActorToNavModifierVolume(actor);
                }
            }
            await BuildNavMesh();
        }