Example #1
0
        /// <summary>
        /// Crée les éléments à classer
        /// </summary>
        public void Populate(int n, int width, int height)
        {
            Random random = new Random();

            for (int i = 0; i < n; i++)
            {
                Troll3D.Entity entity = new Troll3D.Entity(Entity);

                entity.transform_.SetPosition(
                    (float)random.NextDouble() * width - width / 2.0f,
                    (float)random.NextDouble() * height - height / 2.0f,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 0.0f, 0.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                Elements.Add(entity);
                ClusterId.Add(-1);
            }
        }
Example #2
0
        /// <summary>
        /// Construit une représentation graphique du Diagramme de Voronoi de la triangulation
        /// </summary>
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // On va commencer par construire les sommets correspondant aux centre des faces de la triangulation
            // qui sont les noeuds du diagramme de voronoir
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // On récupère le centre de la face (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // On récupère les voisins

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // We start by building the vertices corresponding to the face's center of the triangulation who are node of the Voronoi diagram
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // We get back the face's center (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // We get back the neighbours

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
Example #4
0
        private void Initialize()
        {
            AtlasNode atlasnode = m_fontAtlas.atlas.GetNode(m_character);

            MaterialDX11 mat = new MaterialDX11("vDefault.cso", "pText.cso");

            mat.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f);

            mat.AddShaderResourceView(m_fontAtlas.atlas.SRV);


            transform_.Translate(
                ((float)atlasnode.Width / 2.0f),
                -(atlasnode.Height / 2.0f) - atlasnode.YOffset,
                0.0f);

            transform_.SetScale(
                atlasnode.Width,
                atlasnode.Height,
                1.0f);

            //modelrenderer_ = new MeshRenderer(mat, Quad.GetMesh());

            SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new Color4(0.0f, 1.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinLinearMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = 0,
                MinimumLod         = 0,
                MipLodBias         = 0
            });

            mat.samplers.Add(state);
            mat.SetTextureXOffset((float)atlasnode.X / (float)m_fontAtlas.atlas.Width);
            mat.SetTextureYOffset((float)atlasnode.Y / (float)m_fontAtlas.atlas.Height);
            mat.SetTextureWidth((float)atlasnode.Width / (float)m_fontAtlas.atlas.Width);
            mat.SetTextureHeight((float)atlasnode.Height / (float)m_fontAtlas.atlas.Height);
        }
        public void AddPoint(float x, float y)
        {
            Troll3D.Entity entity = new Troll3D.Entity(Entity);

            entity.transform_.SetPosition(
                x,
                y,
                0.0f);

            entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

            MaterialDX11 material = new MaterialDX11();

            material.SetMainColor(1.0f, 0.0f, 1.0f, 1.0f);
            MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();

            meshrenderer.material_ = material;
            meshrenderer.model_    = Quad.GetMesh();

            Points.Add(entity);
        }
        public void AddCircleCenter(float x, float y, float radius)
        {
            Troll3D.Entity entityCircle = new Troll3D.Entity(Entity);
            entityCircle.transform_.RotateEuler(0.0f, 3.1415f / 2.0f, 0.0f);
            entityCircle.transform_.Translate(x, y, 0.0f);
            entityCircle.transform_.SetScale(radius, 1.0f, radius);
            LineRenderer lineRenderer = entityCircle.AddComponent <LineRenderer>();


            lineRenderer.material_ = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefaultLine.cso");
            lineRenderer.material_.SetMainColor(0.0f, 1.0f, 0.0f, 1.0f);

            lineRenderer.Vertices = Circle.GetLines(30);
            lineRenderer.UpdateRenderer();

            Circles.Add(entityCircle);

            Troll3D.Entity entity = new Troll3D.Entity(Entity);

            entity.transform_.SetPosition(
                x,
                y,
                0.0f);

            entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

            MaterialDX11 material = new MaterialDX11();

            material.SetMainColor(0.0f, 1.0f, 0.0f, 1.0f);
            MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();

            meshrenderer.material_ = material;
            meshrenderer.model_    = Quad.GetMesh();

            CircleCenter.Add(entity);
        }
Example #7
0
        static void Main()
        {
            ApplicationDX11 application = new ApplicationDX11(1280, 720);

            Camera.Main.Entity.AddComponent <Trackview>();

            RenderTexture renderTexture = new RenderTexture(1280, 720);

            Entity newCamera = new Entity();
            Camera cam       = newCamera.AddComponent <Camera>();

            cam.Initialize(new FrustumProjection(3.141592f / 3.0f, Troll3D.Screen.Instance.GetRatio(), 0.1f, 1000.0f));
            cam.SetRenderTarget(renderTexture);
            cam.Entity.AddComponent <Trackview>();

            // Pour éviter des soucis avec le code existant, pour l'instant, je rajoute
            // manuellement ma renderTexture à la liste des RenderTextures à mettre à jour

            ApplicationDX11.Instance.RenderTextures.Add(renderTexture);

            ////newCamera.AddComponent<CameraBehaviour>();

            ////cam.IsActive = false;
            ////cam.AddRenderTexture(100, 100);

            ////MeshRenderer mr = newCamera.AddComponent<MeshRenderer>();

            //mr = new MeshRenderer( );
            //mr.material_ = new MaterialDX11();
            //mr.model_ = ProjectionMesh.GetModel( cam.GetProjection() ) ;
            //mr.material_.SetMainColor( 1.0F, 1.0f, 1.0f, 1.0f );
            //mr.SetFillMode( SharpDX.Direct3D11.FillMode.Wireframe );

            MaterialDX11 renderMaterial = new MaterialDX11("vDefault.cso", "pUnlit.cso");

            renderMaterial.SetMainColor(0.1f, 0.3f, 0.1f, 1.0f);
            renderMaterial.AddShaderResourceView(renderTexture.SRV);

            MaterialDX11 projectorMaterial = new MaterialDX11("vDefault.cso", "pDiffuse.cso", "gDefault.cso");

            projectorMaterial.samplers.Add
            (
                new SamplerState
                (
                    ApplicationDX11.Instance.Device,
                    new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Border,
                AddressV           = TextureAddressMode.Border,
                AddressW           = TextureAddressMode.Border,
                BorderColor        = new Color4(1.0f, 0.0f, 0.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinMagMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = sizeof(float),
                MinimumLod         = 0,
                MipLodBias         = 0
            }
                )
            );

            //MaterialDX11 testRender = new MaterialDX11("vDefault.cso", "pShowAlphaValue.cso", "gDefault.cso");

            Entity     pointLight = new Entity();
            PointLight pl         = pointLight.AddComponent <PointLight>();

            pl.SetSpecularIntensity(0.01f);
            pl.SetIntensity(1.0f);
            pointLight.transform_.SetPosition(0.0f, 20.0f, 0.0f);

            Entity cube = new Entity();

            cube.AddComponent <RotateCube>();
            MeshRenderer cubemr = cube.AddComponent <MeshRenderer>();

            cubemr.material_ = projectorMaterial;
            cubemr.material_.SetMainColor(0.5f, 0.5f, 0.5f, 1.0F);
            cubemr.model_ = Cube.Mesh;
            cube.transform_.Translate(1.0f, 0.5f, 0.0f);
            cube.transform_.SetScale(4.0f, 4.0f, 4.0f);


            Entity       sphere   = new Entity();
            MeshRenderer spheremr = sphere.AddComponent <MeshRenderer>();

            spheremr.material_ = projectorMaterial;
            spheremr.model_    = Sphere.Mesh(1.0f, 30, 30);

            Entity cube4 = new Entity();

            cube4.AddComponent <RotateCube>();
            MeshRenderer cube4mr = cube4.AddComponent <MeshRenderer>();

            cube4mr.material_ = projectorMaterial;
            cube4mr.material_.SetMainColor(0.5f, 0.5f, 0.5f, 1.0F);
            cube4mr.model_ = Cube.Mesh;
            cube4.transform_.Translate(1.0f, 5.5f, 0.0f);
            cube4.transform_.SetScale(4.0f, 4.0f, 4.0f);


            sphere.transform_.Translate(10.0f, 7.0f, 7.0f);
            sphere.transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            sphere.transform_.SetScale(3.0f, 3.0f, 3.0f);

            Entity       floor   = new Entity();
            MeshRenderer floormr = floor.AddComponent <MeshRenderer>();

            floormr.material_ = projectorMaterial;
            floormr.model_    = Quad.GetMesh();

            floor.transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            floor.transform_.SetScale(40.0f, 40.0f, 40.0f);
            floor.transform_.Translate(0.0f, 0.0f, 0.0f);

            Entity       wallN   = new Entity();
            MeshRenderer wallNmr = wallN.AddComponent <MeshRenderer>();

            wallNmr.material_ = projectorMaterial;
            wallNmr.model_    = Quad.GetMesh();
            wallN.transform_.RotateEuler(0.0f, 0.0f, 0.0f);
            wallN.transform_.SetScale(40.0f, 40.0f, 40.0f);
            wallN.transform_.Translate(0.0f, 20.0f, 20.0f);

            Entity       wallS   = new Entity();
            MeshRenderer wallSmr = wallS.AddComponent <MeshRenderer>();

            wallSmr.material_ = projectorMaterial;
            wallSmr.model_    = Quad.GetMesh();

            wallS.transform_.RotateEuler(3.141592f, 0.0f, 0.0f);
            wallS.transform_.SetScale(40.0f, 40.0f, 40.0f);
            wallS.transform_.Translate(0.0f, 20.0f, -20.0f);

            Entity       wallE   = new Entity();
            MeshRenderer wallEmr = wallE.AddComponent <MeshRenderer>();

            wallEmr.material_ = projectorMaterial;
            wallEmr.model_    = Quad.GetMesh();


            wallE.transform_.RotateEuler(-3.141592f / 2.0f, 0.0f, 0.0f);
            wallE.transform_.SetScale(40.0f, 40.0f, 40.0f);
            wallE.transform_.Translate(-20.0f, 20.0f, 0.0f);

            Entity    frontQuad = new Entity();
            FrontQuad fq        = frontQuad.AddComponent <FrontQuad>();

            fq.SetQuad(0, 0, 300, 300);
            fq.Material.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f);
            fq.Material.AddShaderResourceView(renderTexture.SRV);



            ////application.scene_.Append(new BitmapImage(application.shadowmap.shaderResourceView_, testRender));

            //Entity proj = new Entity();


            //    (new Projector(
            //    cam.GetRenderTextureSRV(),
            //    new FrustumProjection(3.141592f / 3.0f,

            //        cam.GetViewport().Width / (float)cam.GetViewport().Height, 1, 80.0f))

            //    );
            //proj.transform_.Translate(0.0f, 10.0f, -10.0f);
            //proj.AddComponent<ProjectorBehavior>();
            application.Run();
        }
Example #8
0
        static void Main()
        {
            ApplicationDX11 application = new ApplicationDX11(1920, 1080);

            Camera.Main.Entity.AddComponent <Trackview>();

            //Troll3D.View.Main.AddStencilTexture(100, 100);

            Entity lightEntity = new Entity();

            DirectionalLight dl = lightEntity.AddComponent <DirectionalLight>();

            dl.SetSpecularIntensity(1.0f);
            dl.SetIntensity(1.0F);
            dl.SetAmbiantColor(new Vector4(0.0f, 0.0f, 0.0f, 1.0f));

            lightEntity.transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            lightEntity.transform_.SetPosition(0.0f, 50.0f, 50.0f);

            dl.AddProjection(new OrthoProjection(200.0f, 200.0f, 0.1f, 150.0f));
            dl.AddShadowMap(4000, 4000);

            lightEntity.AddComponent <LightBehaviour>();

            MaterialDX11 floorMaterial = new MaterialDX11("vDefault.cso", "pShadowMapping.cso", "gDefault.cso");

            floorMaterial.SetMainColor(0.5f, 0.5f, 0.5f, 1.0F);

            floorMaterial.samplers.Add
            (
                new SamplerState
                (
                    ApplicationDX11.Instance.Device,
                    new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Border,
                AddressV           = TextureAddressMode.Border,
                AddressW           = TextureAddressMode.Border,
                BorderColor        = new Color4(0.0f, 0.0f, 1.0f, 1.0f),
                ComparisonFunction = Comparison.LessEqual,
                Filter             = Filter.MinMagLinearMipPoint,
                MaximumAnisotropy  = 0,
                MaximumLod         = sizeof(float),
                MinimumLod         = 0,
                MipLodBias         = 0
            }
                )
            );

            Entity cube = new Entity();

            cube.AddComponent <RotateCube>();
            MeshRenderer cubeRenderer = cube.AddComponent <MeshRenderer>();

            cubeRenderer.material_ = floorMaterial;
            cubeRenderer.model_    = Cube.Mesh;

            cube.transform_.Translate(-10.0f, 5.5f, 5.0f);
            cube.transform_.SetScale(4.0f, 4.0f, 4.0f);

            Entity       sphere   = new Entity();
            MeshRenderer sphereMr = sphere.AddComponent <MeshRenderer>();

            sphereMr.material_ = floorMaterial;
            sphereMr.model_    = Sphere.Mesh(1.0f, 30, 30);

            sphere.transform_.Translate(10.0f, 7.0f, 7.0f);
            sphere.transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            sphere.transform_.SetScale(3.0f, 3.0f, 3.0f);


            Entity       cube2             = new Entity();
            MeshRenderer cubeMeshRenderer2 = cube2.AddComponent <MeshRenderer>();

            cubeMeshRenderer2.material_ = floorMaterial;
            cubeMeshRenderer2.model_    = Cube.Mesh;
            cube2.transform_.Translate(20.0f, 7.0f, 2.0f);
            cube2.transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f);
            cube2.transform_.SetScale(2.0f, 2.0f, 10.0f);

            Entity       floor             = new Entity();
            MeshRenderer floorMeshRenderer = floor.AddComponent <MeshRenderer>();

            floorMeshRenderer.material_ = floorMaterial;
            floorMeshRenderer.model_    = Cube.Mesh;
            floor.transform_.SetScale(80.0f, 1.0f, 80.0f);
            floor.transform_.Translate(0.0f, 0.0f, 0.0f);

            Entity Obj = new Entity();

            Obj.AddComponent <RotateCube>();
            MeshRenderer ObjMeshRenderer = Obj.AddComponent <MeshRenderer>();

            ObjMeshRenderer.material_ = floorMaterial;
            ObjMeshRenderer.model_    = MeshManager.LoadObj("StanfordBunny.obj");
            Obj.transform_.SetScale(80.0f, 80.0f, 80.0f);
            Obj.transform_.Translate(10.0f, 10.0f, 0.0f);

            Entity dragon = new Entity();

            dragon.AddComponent <RotateCube>();
            MeshRenderer dragonr = dragon.AddComponent <MeshRenderer>();

            dragonr.material_ = floorMaterial;
            dragonr.model_    = MeshManager.LoadObj("dragon.obj");
            dragon.transform_.SetScale(2.0f, 2.0f, 2.0f);
            dragon.transform_.Translate(-25.0f, 3.0f, 10.0f);



            Entity       Wall             = new Entity();
            MeshRenderer WallMeshRenderer = Wall.AddComponent <MeshRenderer>();

            WallMeshRenderer.material_ = floorMaterial;
            WallMeshRenderer.model_    = Cube.Mesh;

            Wall.transform_.SetScale(80.0f, 30.0f, 2.0f);
            Wall.transform_.Translate(0.0f, 15.0f, 40.0f);

            Entity    frontQuad = new Entity();
            FrontQuad fq        = frontQuad.AddComponent <FrontQuad>();

            fq.m_meshRenderer.material_ = new MaterialDX11("vDefault.cso", "pOneChannel.cso");
            fq.SetQuad(0, 0, 300, 300);
            fq.Material.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f);
            fq.m_meshRenderer.material_.AddShaderResourceView(dl.shadowmap_.shaderResourceView_);

            application.Run();
        }