Exemplo n.º 1
0
        public static void EX1()
        {
            // sem generics
            Abstraction abstracao = new Abstraction(new ImplementationA());
            abstracao.Operacao();
            abstracao = new Abstraction(new ImplementationB());
            abstracao.Operacao();

            // com generics
            new GenericAbstraction<ImplementationA>().Operacao();
            new GenericAbstraction<ImplementationB>().Operacao();
        }
Exemplo n.º 2
0
    public override List <RepresentationMesh> PlaceRepresentations(Ensemble ensemble, Abstraction abstraction, GameObject compositionGameObject)
    {
        List <RepresentationMesh> resultMesh       = new List <RepresentationMesh> ();
        List <Structure>          resultStructures = new List <Structure> ();

        this.ensemble = ensemble;

        List <KeyValuePair <string, float> > paramsValues = new List <KeyValuePair <string, float> > ();

        for (int i = 0; i < axisParameters.Count; i++)
        {
            paramsValues.Add(new KeyValuePair <string, float>(axisParameters[i].name, axisParameters[i].value));
        }

        ParameterInfo xPI    = ensemble.parametersInfo [axisParameters [0].name];
        float         xDelta = (xPI.maxValue - xPI.minValue) / (float)(xPI.count - 1);
        ParameterInfo zPI    = ensemble.parametersInfo [axisParameters [1].name];
        float         zDelta = (zPI.maxValue - zPI.minValue) / (float)(zPI.count - 1);

        List <float> xDeltas = new List <float> ();

        for (float i = xPI.minValue; i <= xPI.maxValue; i += xDelta)
        {
            xDeltas.Add(i);
        }

        if (xDeltas.Count > dimSizeX)
        {
            int diffCount = xDeltas.Count - dimSizeX;
            for (int i = 0; i < diffCount; i++)
            {
                xDeltas.RemoveAt(Random.Range(0, xDeltas.Count - 1));
            }
        }

        List <float> zDeltas = new List <float> ();

        for (float i = zPI.minValue; i <= zPI.maxValue; i += zDelta)
        {
            zDeltas.Add(i);
        }

        foreach (float xValue in xDeltas)
        {
            foreach (float zValue in zDeltas)
            {
                paramsValues[0] = new KeyValuePair <string, float>(paramsValues[0].Key, xValue);
                paramsValues[1] = new KeyValuePair <string, float>(paramsValues[1].Key, zValue);
                resultStructures.Add(ensemble.GetStructure(paramsValues));
            }
        }

        Camera cam = Camera.main;

        yPosStart = cam.gameObject.transform.position.y - cam.orthographicSize / 2f + (float)camOffset;

        int val = 0;

        if (abstraction.GetType() == typeof(AbstractionScale1D))
        {
            xPosStart += itemSizeX / 2f;
        }

        foreach (Structure structure in resultStructures)
        {
            (structure.representation as RepresentationMesh).gameObject.SetActive(true);
            RepresentationMesh newRep = abstraction.Process(structure.representation as RepresentationMesh) as RepresentationMesh;
            (structure.representation as RepresentationMesh).gameObject.SetActive(false);

            newRep.gameObject.transform.parent = compositionGameObject.transform;

            float valX = (float)(val / dimSizeZ);
            float valZ = (float)(val % dimSizeZ);

            newRep.gameObject.transform.parent = compositionGameObject.transform;

            newRep.gameObject.transform.position = new Vector3(xPosStart + valX * (itemSizeX + itemOffset) + newRep.offset.x, yPosStart, zPosStart + valZ);
            val++;

            switch (type)
            {
            case SPType.None:
            {
                break;
            }

            case SPType.Transparent:
            {
                newRep.SetMaterialTransparency(0.25f);
                break;
            }

            case SPType.Colorify:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.SetMaterialColor(zColor);
                break;
            }

            case SPType.BlendColor:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.BlendMaterialColor(zColor);
                break;
            }

            case SPType.ColorTransparent:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.SetMaterialColorTransparency(zColor, 0.25f);
                break;
            }

            default:
            {
                newRep.SetMaterialTransparency(0.25f);
                break;
            }
            }
        }

        GameObject uiGO     = GameObject.Find("UI") as GameObject;
        GameObject xPanel   = uiGO.transform.Find("X Axis Panel").gameObject;
        GameObject sliderGO = xPanel.transform.Find("Slider").gameObject;

        sliderGO.SetActive(true);
        Slider slider = sliderGO.GetComponent <Slider> ();

        slider.minValue = xPI.minValue;
        slider.maxValue = xPI.maxValue;
        slider.value    = xPI.minValue;

        slider.onValueChanged.RemoveAllListeners();
        slider.onValueChanged.AddListener(CameraPositionChanged);

        cameraXEndPos = xPosStart + ((float)xPI.count - 0.5f) * itemSizeX + ((float)xPI.count - 1f) * itemOffset - cam.orthographicSize + camOffset;

        return(resultMesh);
    }
Exemplo n.º 3
0
 private void SetShapeSize(Shape shape, Abstraction.Rectangle rectangle)
 {
     shape.SetValue(Canvas.LeftProperty, rectangle.X);
     shape.SetValue(Canvas.TopProperty, rectangle.Y);
     shape.Width = rectangle.Width;
     shape.Height = rectangle.Height;
 }
Exemplo n.º 4
0
    public override List <RepresentationMesh> PlaceRepresentations(Ensemble ensemble, Abstraction abstraction, GameObject compositionGameObject)
    {
        List <RepresentationMesh> resultMesh       = new List <RepresentationMesh> ();
        List <Structure>          resultStructures = new List <Structure> ();

        this.ensemble = ensemble;

        List <KeyValuePair <string, float> > paramsValues = new List <KeyValuePair <string, float> > ();

        for (int i = 0; i < axisParameters.Count; i++)
        {
            paramsValues.Add(new KeyValuePair <string, float> (axisParameters [i].name, axisParameters [i].value));
        }

        ParameterInfo xPI    = ensemble.parametersInfo [axisParameters [0].name];
        float         xDelta = (xPI.maxValue - xPI.minValue) / (float)(xPI.count - 1);
        ParameterInfo yPI    = ensemble.parametersInfo [axisParameters [1].name];
        float         yDelta = (yPI.maxValue - yPI.minValue) / (float)(yPI.count - 1);

        List <float> xDeltas = new List <float> ();

        for (float i = xPI.minValue; i <= xPI.maxValue; i += xDelta)
        {
            xDeltas.Add(i);
        }

        if (xDeltas.Count > dimSizeX)
        {
            int diffCount = xDeltas.Count - dimSizeX;
            for (int i = 0; i < diffCount; i++)
            {
                xDeltas.RemoveAt(Random.Range(0, xDeltas.Count - 1));
            }
        }

        List <float> yDeltas = new List <float> ();

        for (float i = yPI.minValue; i <= yPI.maxValue; i += yDelta)
        {
            yDeltas.Add(i);
        }

        if (yDeltas.Count > dimSizeY)
        {
            int diffCount = yDeltas.Count - dimSizeY;
            for (int i = 0; i < diffCount; i++)
            {
                yDeltas.RemoveAt(Random.Range(0, yDeltas.Count - 1));
            }
        }

        foreach (float xValue in xDeltas)
        {
            foreach (float yValue in yDeltas)
            {
                paramsValues[0] = new KeyValuePair <string, float>(paramsValues[0].Key, xValue);
                paramsValues[1] = new KeyValuePair <string, float>(paramsValues[1].Key, yValue);
                resultStructures.Add(ensemble.GetStructure(paramsValues));
            }
        }

        yPosStart -= itemSizeY / 2f;

        int val = 0;

        foreach (Structure structure in          resultStructures)
        {
            (structure.representation as RepresentationMesh).gameObject.SetActive(true);
            RepresentationMesh newRep = abstraction.Process(structure.representation as RepresentationMesh) as RepresentationMesh;
            (structure.representation as RepresentationMesh).gameObject.SetActive(false);

            newRep.gameObject.transform.parent = compositionGameObject.transform;

            float valX = (float)(val / dimSizeY);
            float valY = (float)(val % dimSizeY);

            newRep.gameObject.transform.position = new Vector3(
                xPosStart + valX * (itemSizeX + itemOffset) + newRep.offset.x,
                yPosStart + valY * (itemSizeY + itemOffset),
                0);

            val++;
        }

        return(resultMesh);
    }
Exemplo n.º 5
0
        public static IEnumerable <FunctionTerm> GetDerivatives(this FunctionTerm term)
        {
            if (term is Sum)
            {
                Variable x = new Variable(1, "x");
                Variable y = new Variable(1, "y");

                return(Enumerables.Create
                       (
                           Term.Constant(1).Abstract(x, y),
                           Term.Constant(1).Abstract(x, y)
                       ));
            }
            if (term is Product)
            {
                Variable x = new Variable(1, "x");
                Variable y = new Variable(1, "y");

                return(Enumerables.Create
                       (
                           y.Abstract(x, y),
                           x.Abstract(x, y)
                       ));
            }
            if (term is Exponentiation)
            {
                Variable x = new Variable(1, "x");
                Variable y = new Variable(1, "y");

                return(Enumerables.Create
                       (
                           Term.Product(y, Term.Exponentiation(x, Term.Difference(y, Term.Constant(1)))).Abstract(x, y),
                           Term.Product(Term.Logarithm(x), Term.Exponentiation(x, y)).Abstract(x, y)
                       ));
            }
            if (term is Logarithm)
            {
                Variable x = new Variable(1, "x");

                return(Enumerables.Create(Term.Invert(x).Abstract(x)));
            }
            if (term is FunctionDefinition)
            {
                FunctionDefinition functionDefinitionTerm = (FunctionDefinition)term;

                IEnumerable <FunctionTerm> derivatives = GetDerivatives(functionDefinitionTerm.Function).ToArray();

                return
                    ((
                         from index in Enumerable.Range(0, derivatives.Count())
                         let derivative = derivatives.ElementAt(index)
                                          select new FunctionDefinition
                                          (
                             string.Format("{0}_d{1}", functionDefinitionTerm.Name, index),
                             Rewriting.CompleteNormalization.Rewrite(derivative),
                             new BasicSyntax(string.Format("{0}'{1}", functionDefinitionTerm.Syntax.GetText(), index.ToString().ToSuperscript()))
                                          )
                         )
                     .ToArray());
            }
            if (term is Abstraction)
            {
                Abstraction abstractionTerm = (Abstraction)term;

                return
                    ((
                         from variable in abstractionTerm.Variables
                         from derivative in GetDerivatives(abstractionTerm.Term, variable)
                         select derivative.Abstract(abstractionTerm.Variables)
                         )
                     .ToArray());
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 6
0
 public virtual List <RepresentationMesh> PlaceRepresentations(Ensemble ensemble, Abstraction abstraction, GameObject compositionGameObject)
 {
     return(new List <RepresentationMesh> ());
 }
Exemplo n.º 7
0
        public override T Rewrite <T>(T term)
        {
            T rewrittenTerm = rule.Rewrite(term);

            if (rewrittenTerm != null)
            {
                return(rewrittenTerm);
            }

            if (term is BasicValueTerm)
            {
                return(null);
            }
            if (term is BasicFunctionTerm)
            {
                return(null);
            }
            if (term is Variable)
            {
                return(null);
            }
            if (term is Abstraction)
            {
                Abstraction abstraction = (Abstraction)(BaseTerm)term;

                ValueTerm rewrittenAbstractionTerm = Rewrite(abstraction.Term);
                if (rewrittenAbstractionTerm != null)
                {
                    return((T)(BaseTerm) new Abstraction(abstraction.Variables, rewrittenAbstractionTerm));
                }

                return(null);
            }
            if (term is Application)
            {
                Application application = (Application)(BaseTerm)term;

                FunctionTerm rewrittenApplicationFunction = Rewrite(application.Function);
                if (rewrittenApplicationFunction != null)
                {
                    return((T)(BaseTerm) new Application(rewrittenApplicationFunction, application.Parameter));
                }

                ValueTerm rewrittenApplicationParameter = Rewrite(application.Parameter);
                if (rewrittenApplicationParameter != null)
                {
                    return((T)(BaseTerm) new Application(application.Function, rewrittenApplicationParameter));
                }

                return(null);
            }
            if (term is Vector)
            {
                Vector vector = (Vector)(BaseTerm)term;

                IEnumerable <ValueTerm> rewrittenVectorTerms = RewriteOne(vector.Terms);
                if (rewrittenVectorTerms != null)
                {
                    return((T)(BaseTerm) new Vector(rewrittenVectorTerms));
                }

                return(null);
            }
            if (term is Selection)
            {
                Selection selection = (Selection)(BaseTerm)term;

                ValueTerm rewrittenSelectionTerm = Rewrite(selection.Term);
                if (rewrittenSelectionTerm != null)
                {
                    return((T)(BaseTerm) new Selection(rewrittenSelectionTerm, selection.Index));
                }

                return(null);
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 8
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    /// <param name="abs"></param>
    public void SetAbstractionAttached(Abstraction abs)
    {
        _AbstractionAttached = abs;
    }
Exemplo n.º 9
0
 public static Syntax Abstraction(Abstraction abstraction)
 {
     return(new AbstractionSyntax(abstraction.Variables, abstraction.Term));
 }
Exemplo n.º 10
0
        public void Init(string platformPath, string folder64Bit, string folder32Bit)
        {
            // pre-load native libs
            string libFolderBit;

            if (IntPtr.Size == 8)
            {
                libFolderBit = folder64Bit;
            }
            else if (IntPtr.Size == 4)
            {
                libFolderBit = folder32Bit;
            }
            else
            {
                throw new NotSupportedException("Unsupported bit size: " + IntPtr.Size.ToString());
            }

                        #if RELEASE
            const string config = "Release";
                        #else
            const string config = "Debug";
                        #endif

            // load api abstraction (api-instance and hardware-device)
            var abstractionDesc = new AbstractionDesc(AbstractionInitType.MultiGPU_BestAvaliable_AFR);
            abstractionDesc.supportedAPIs = new AbstractionAPI[] { AbstractionAPI.D3D12 };

            abstractionDesc.deviceDescD3D12.window = window;
            //abstractionDesc.deviceDescD3D12.adapterIndex = 1;
            //abstractionDesc.deviceDescD3D12.vSyncMode = SwapChainVSyncMode.VSyncOff;
                        #if DEBUG
            abstractionDesc.nativeLibPathD3D12 = Path.Combine(platformPath, @"Shared\Orbital.Video.D3D12.Native\bin", libFolderBit, config);
                        #else
            abstractionDesc.nativeLibPathD3D12 = string.Empty;
                        #endif

            abstractionDesc.deviceDescVulkan.window = window;
                        #if DEBUG
            abstractionDesc.nativeLibPathVulkan = Path.Combine(platformPath, @"Shared\Orbital.Video.Vulkan.Native\bin", libFolderBit, config);
                        #else
            abstractionDesc.nativeLibPathVulkan = string.Empty;
                        #endif

            if (!Abstraction.InitFirstAvaliable(abstractionDesc, out instance, out device))
            {
                throw new Exception("Failed to init abstraction");
            }

            // create render texture test objects
            renderTextureTest = new RenderTextureTest(device);

            // create msaa render texture
            if (!device.GetMaxMSAALevel(TextureFormat.Default, out var msaaLevel))
            {
                throw new Exception("Failed to get MSAA level");
            }
            var windowSize = window.GetSize(WindowSizeType.WorkingArea);
            renderTextureMSAA = device.CreateRenderTexture2D(windowSize.width, windowSize.height, TextureFormat.Default, RenderTextureUsage.Discard, TextureMode.GPUOptimized, StencilUsage.Discard, DepthStencilFormat.DefaultDepth, DepthStencilMode.GPUOptimized, msaaLevel, false, MultiGPUNodeResourceVisibility.All);

            // create command list
            commandList         = device.CreateRasterizeCommandList();
            commandList_Compute = device.CreateComputeCommandList();

            // create render pass
            var renderPassDesc = RenderPassDesc.CreateDefault(new Color4F(0, .2f, .4f, 1), 1);
            //renderPass = device.CreateRenderPass(renderPassDesc, device.swapChain.depthStencil);
            renderPass = renderTextureMSAA.CreateRenderPass(renderPassDesc, renderTextureMSAA.GetDepthStencil());

            // create texture
            int textureWidth = 256, textureHeight = 256;
            var textureData = new byte[textureWidth * textureHeight * 4];
            for (int y = 0; y != textureHeight; ++y)
            {
                for (int x = 0; x != textureWidth; ++x)
                {
                    int i = (x * 4) + (y * textureWidth * 4);
                    if (x % 16 <= 7 && y % 16 <= 7)
                    {
                        textureData[i + 0] = 0;
                        textureData[i + 1] = 0;
                        textureData[i + 2] = 0;
                        textureData[i + 3] = 0;
                    }
                    else
                    {
                        textureData[i + 0] = 255;
                        textureData[i + 1] = 255;
                        textureData[i + 2] = 255;
                        textureData[i + 3] = 255;
                    }
                }
            }
            texture = device.CreateTexture2D(textureWidth, textureHeight, TextureFormat.R8G8B8A8, textureData, TextureMode.GPUOptimized, MultiGPUNodeResourceVisibility.Self);

            // create texture 2
            textureWidth  = 100;
            textureHeight = 100;
            textureData   = new byte[textureWidth * textureHeight * 4];
            for (int y = 0; y != textureHeight; ++y)
            {
                for (int x = 0; x != textureWidth; ++x)
                {
                    int i = (x * 4) + (y * textureWidth * 4);
                    if (x % 16 <= 7 && y % 16 <= 7)
                    {
                        textureData[i + 0] = 0;
                        textureData[i + 1] = 0;
                        textureData[i + 2] = 0;
                        textureData[i + 3] = 0;
                    }
                    else
                    {
                        textureData[i + 0] = 255;
                        textureData[i + 1] = 255;
                        textureData[i + 2] = 255;
                        textureData[i + 3] = 255;
                    }
                }
            }
            texture2 = device.CreateTexture2D(textureWidth, textureHeight, TextureFormat.R8G8B8A8, textureData, TextureMode.GPUOptimized, MultiGPUNodeResourceVisibility.Self);

            // load shaders
            // TODO: load CS2X compiled ShaderEffect

            /*using (var stream = new FileStream("Shader.se", FileMode.Open, FileAccess.Read, FileShare.Read))
             * {
             *      shaderEffect = device.CreateShaderEffect(stream, ShaderEffectSamplerAnisotropy.Default);
             * }*/

            using (var vsStream = new FileStream("Shaders\\Shader_D3D12.vs", FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var psStream = new FileStream("Shaders\\Shader_D3D12.ps", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var vs = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.VS);
                    var ps = new Video.D3D12.Shader((Video.D3D12.Device)device, ShaderType.PS);
                    if (!vs.Init(vsStream))
                    {
                        throw new Exception("Failed to init VS shader");
                    }
                    if (!ps.Init(psStream))
                    {
                        throw new Exception("Failed to init PS shader");
                    }
                    var desc = new ShaderEffectDesc();
                    desc.constantBuffers    = new ShaderEffectConstantBuffer[1];
                    desc.constantBuffers[0] = new ShaderEffectConstantBuffer()
                    {
                        registerIndex = 0,
                        usage         = ShaderEffectResourceUsage.VS,
                        variables     = new ShaderVariable[2]
                    };
                    desc.constantBuffers[0].variables[0] = new ShaderVariable()
                    {
                        name = "constrast",
                        type = ShaderVariableType.Float
                    };
                    desc.constantBuffers[0].variables[1] = new ShaderVariable()
                    {
                        name = "camera",
                        type = ShaderVariableType.Float4x4
                    };
                    desc.textures    = new ShaderEffectTexture[3];
                    desc.textures[0] = new ShaderEffectTexture()
                    {
                        registerIndex = 0,
                        usage         = ShaderEffectResourceUsage.PS
                    };
                    desc.textures[1] = new ShaderEffectTexture()
                    {
                        registerIndex = 1,
                        usage         = ShaderEffectResourceUsage.PS
                    };
                    desc.textures[2] = new ShaderEffectTexture()
                    {
                        registerIndex = 2,
                        usage         = ShaderEffectResourceUsage.PS
                    };
                    desc.samplers    = new ShaderEffectSampler[1];
                    desc.samplers[0] = new ShaderEffectSampler()
                    {
                        registerIndex = 0,
                        filter        = ShaderSamplerFilter.Default,
                        anisotropy    = ShaderSamplerAnisotropy.Default,
                        addressU      = ShaderSamplerAddress.Wrap,
                        addressV      = ShaderSamplerAddress.Wrap,
                        addressW      = ShaderSamplerAddress.Wrap,
                        usage         = ShaderEffectResourceUsage.PS
                    };
                    shaderEffect = device.CreateShaderEffect(vs, ps, null, null, null, desc, true);
                }

            if (!shaderEffect.FindVariable("constrast", out shaderEffectVar_Constrast))
            {
                throw new Exception("Failed to find shader effect variable");
            }
            if (!shaderEffect.FindVariable("camera", out shaderEffectVar_Camera))
            {
                throw new Exception("Failed to find shader effect variable");
            }

            // create constant buffer
            constantBuffer = device.CreateConstantBuffer(shaderEffect.constantBufferMappings[0].size, ConstantBufferMode.Write);

            // create vertex buffer
            const float size            = 1 / 2f;
            var         rotUpAxisMat    = Mat3.FromEuler(0, MathTools.DegToRad(90), 0);
            var         rotRightAxisMat = Mat3.FromEuler(MathTools.DegToRad(90), 0, 0);
            var         vertices        = new Vertex[4 * 6]; // 4 vertices per face
            var         indices         = new ushort[6 * 6]; // 6 indices per face
            var         colorKey        = new Color4[4]
            {
                Color4.blue,
                Color4.red,
                Color4.white,
                Color4.white
            };
            for (int v = 0, i = 0, r = 0; v < (4 * 4); v += 4, i += 6, ++r)            // caluclate front, right, back, left faces
            {
                vertices[v + 0] = new Vertex(new Vec3(-size, -size, size), colorKey[r], new Vec2(0, 0)).Transform(rotUpAxisMat, r);
                vertices[v + 1] = new Vertex(new Vec3(-size, size, size), colorKey[r], new Vec2(0, 1)).Transform(rotUpAxisMat, r);
                vertices[v + 2] = new Vertex(new Vec3(size, size, size), colorKey[r], new Vec2(1, 1)).Transform(rotUpAxisMat, r);
                vertices[v + 3] = new Vertex(new Vec3(size, -size, size), colorKey[r], new Vec2(1, 0)).Transform(rotUpAxisMat, r);
                indices[i + 0]  = (ushort)(v + 0);
                indices[i + 1]  = (ushort)(v + 1);
                indices[i + 2]  = (ushort)(v + 2);
                indices[i + 3]  = (ushort)(v + 0);
                indices[i + 4]  = (ushort)(v + 2);
                indices[i + 5]  = (ushort)(v + 3);
            }
            colorKey = new Color4[2]
            {
                Color4.green,
                Color4.white
            };
            for (int v = (4 * 4), i = (6 * 4), r = 1; v < (4 * 6); v += 4, i += 6, r = 3)            // caluclate top, bottom faces
            {
                vertices[v + 0] = new Vertex(new Vec3(-size, -size, size), colorKey[r / 3], new Vec2(0, 0)).Transform(rotRightAxisMat, r);
                vertices[v + 1] = new Vertex(new Vec3(-size, size, size), colorKey[r / 3], new Vec2(0, 1)).Transform(rotRightAxisMat, r);
                vertices[v + 2] = new Vertex(new Vec3(size, size, size), colorKey[r / 3], new Vec2(1, 1)).Transform(rotRightAxisMat, r);
                vertices[v + 3] = new Vertex(new Vec3(size, -size, size), colorKey[r / 3], new Vec2(1, 0)).Transform(rotRightAxisMat, r);
                indices[i + 0]  = (ushort)(v + 0);
                indices[i + 1]  = (ushort)(v + 1);
                indices[i + 2]  = (ushort)(v + 2);
                indices[i + 3]  = (ushort)(v + 0);
                indices[i + 4]  = (ushort)(v + 2);
                indices[i + 5]  = (ushort)(v + 3);
            }
            vertexBuffer = device.CreateVertexBuffer <Vertex>(vertices, indices, VertexBufferMode.GPUOptimized);

            // create vertex buffer streamer
            var vertexBufferStreamLayout = new VertexBufferStreamLayout()
            {
                descs    = new VertexBufferStreamDesc[1],
                elements = new VertexBufferStreamElement[3]
            };
            vertexBufferStreamLayout.descs[0] = new VertexBufferStreamDesc()
            {
                vertexBuffer = vertexBuffer,
                type         = VertexBufferStreamType.VertexData
            };
            vertexBufferStreamLayout.elements[0] = new VertexBufferStreamElement()
            {
                type   = VertexBufferStreamElementType.Float3,
                usage  = VertexBufferStreamElementUsage.Position,
                offset = 0
            };
            vertexBufferStreamLayout.elements[1] = new VertexBufferStreamElement()
            {
                type   = VertexBufferStreamElementType.RGBAx8,
                usage  = VertexBufferStreamElementUsage.Color,
                offset = (sizeof(float) * 3)
            };
            vertexBufferStreamLayout.elements[2] = new VertexBufferStreamElement()
            {
                type   = VertexBufferStreamElementType.Float2,
                usage  = VertexBufferStreamElementUsage.UV,
                offset = (sizeof(float) * 3) + 4
            };
            vertexBufferStreamer = device.CreateVertexBufferStreamer(vertexBufferStreamLayout);

            // create render state
            var renderStateDesc = new RenderStateDesc()
            {
                renderPass           = renderPass,
                shaderEffect         = shaderEffect,
                constantBuffers      = new ConstantBufferBase[1],
                textures             = new TextureBase[3],
                vertexBufferTopology = VertexBufferTopology.Triangle,
                vertexBufferStreamer = vertexBufferStreamer,
                triangleCulling      = TriangleCulling.Back,
                triangleFillMode     = TriangleFillMode.Solid,
                depthStencilDesc     = DepthStencilDesc.StandardDepthTesting()
            };
            //renderStateDesc.blendDesc.renderTargetBlendDescs = new RenderTargetBlendDesc[1] {RenderTargetBlendDesc.AlphaBlending()};
            renderStateDesc.constantBuffers[0] = constantBuffer;
            renderStateDesc.textures[0]        = texture;
            renderStateDesc.textures[1]        = texture2;
            renderStateDesc.textures[2]        = renderTextureTest.renderTexture;
            renderState = device.CreateRenderState(renderStateDesc);

            // create compute shader
            using (var csStream = new FileStream("Shaders\\Compute_D3D12.cs", FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var csDesc = new ComputeShaderDesc()
                {
                    randomAccessBuffers = new ComputeShaderRandomAccessBuffer[1]
                };
                csDesc.randomAccessBuffers[0] = new ComputeShaderRandomAccessBuffer()
                {
                    registerIndex = 0
                };
                computeShader = device.CreateComputeShader(csStream, csDesc);
            }

            // create compute state
            var computeStateDesc = new ComputeStateDesc()
            {
                computeShader       = computeShader,
                randomAccessBuffers = new object[1]
            };
            computeStateDesc.randomAccessBuffers[0] = renderTextureTest.renderTexture;
            computeState = device.CreateComputeState(computeStateDesc);

            // print all GPUs this abstraction supports
            if (!instance.QuerySupportedAdapters(false, out var adapters))
            {
                throw new Exception("Failed: QuerySupportedAdapters");
            }
            foreach (var adapter in adapters)
            {
                Debug.WriteLine(adapter.name);
            }

            // setup camera
            camera = new Camera();
        }
Exemplo n.º 11
0
 public void Operation(Abstraction service)
 {
     service.Opretation();
 }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    /// <param name="eventdata"></param>
    public void OnPointerEnter(PointerEventData eventdata)
    {
        if (SelectionWheel != null && _ObjectRefComponent != null && _ButtonComponent != null)
        {
            // Update the highlight text in the selection wheel
            if (_ObjectRefComponent.AbstractRef != null)
            {
                // Get selection wheel reference
                SelectionWheel selectionWheel = null;
                if (GameManager.Instance._IsRadialMenu)
                {
                    selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
                }
                else
                {
                    selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
                }
                selectionWheel.ShowItemPurchaseInfoPanel();

                // Detail window
                SelectionWheel.DetailedHighlightTitle.text            = _ObjectRefComponent.AbstractRef.ObjectName.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionShort.text = _ObjectRefComponent.AbstractRef.ObjectDescriptionShort.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionLong.text  = _ObjectRefComponent.AbstractRef.ObjectDescriptionLong;

                // Center panel
                SelectionWheel.CenterHighlightTitle.text = _ObjectRefComponent.AbstractRef.ObjectName;
                SelectionWheel.CenterTechLevelText.text  = _ObjectRefComponent.AbstractRef.CostTechLevel.ToString();
                SelectionWheel.CenterSupplyText.text     = _ObjectRefComponent.AbstractRef.CostSupplies.ToString();
                SelectionWheel.CenterPowerText.text      = _ObjectRefComponent.AbstractRef.CostPower.ToString();
                SelectionWheel.CenterPopulationText.text = _ObjectRefComponent.AbstractRef.CostPopulation.ToString();

                Player player = GameManager.Instance.Players[0];
                SelectionWheelUnitRef unitRef = GetComponent <SelectionWheelUnitRef>();
                Abstraction           item    = unitRef.AbstractRef;

                bool unlock      = player.Level >= item.CostTechLevel;
                bool purchasable = player.SuppliesCount >= item.CostSupplies &&
                                   player.PowerCount >= item.CostPower &&
                                   (player.MaxPopulation - player.PopulationCount) >= item.CostPopulation;

                // Update selection marker colours
                if (selectionWheel.SelectionMarkerImage)
                {
                    if (!unlock)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.red;
                    }
                    if (!purchasable)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.red;
                    }
                    else if (unlock)
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.green;
                    }
                    else
                    {
                        selectionWheel.SelectionMarkerImage.color = Color.grey;
                    }
                }

                // Update cost texts colour based on state
                /// Tech level
                if (player.Level >= item.CostTechLevel)
                {
                    selectionWheel.CenterTechLevelText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterTechLevelText.color = Color.red;
                }

                /// Population
                if ((player.MaxPopulation - player.PopulationCount) >= item.CostPopulation)
                {
                    selectionWheel.CenterPopulationText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterPopulationText.color = Color.red;
                }

                /// Supplies
                if (player.SuppliesCount >= item.CostSupplies)
                {
                    selectionWheel.CenterSupplyText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterSupplyText.color = Color.red;
                }

                /// Power
                if (player.PowerCount >= item.CostPower)
                {
                    selectionWheel.CenterPowerText.color = Color.black;
                }
                else
                {
                    selectionWheel.CenterPowerText.color = Color.red;
                }

                // Play hover button sound
                SoundManager.Instance.PlaySound("SFX/_SFX_Back_Alt", 1f, 1f, false);
            }
            else
            {
                // Get selection wheel reference
                SelectionWheel selectionWheel = null;
                if (GameManager.Instance._IsRadialMenu)
                {
                    selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
                }
                else
                {
                    selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
                }
                selectionWheel.ShowItemPurchaseInfoPanel();

                // Detail window
                SelectionWheel.DetailedHighlightTitle.text            = SelectionWheel.GetBuildingSlotInstigator().ObjectName.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionShort.text = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionShort.ToUpper();
                SelectionWheel.DetailedHighlightDescriptionLong.text  = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionLong;

                // Center panel
                SelectionWheel.CenterHighlightTitle.text = SelectionWheel.GetBuildingSlotInstigator().ObjectName;
                SelectionWheel.CenterTechLevelText.text  = "1";
                SelectionWheel.CenterSupplyText.text     = "0";
                SelectionWheel.CenterPowerText.text      = "0";
                SelectionWheel.CenterPopulationText.text = "0";

                // Update selection marker colour
                selectionWheel.SelectionMarkerImage.color = Color.grey;
            }
        }
    }
Exemplo n.º 13
0
    public override List <RepresentationMesh> PlaceRepresentations(Ensemble ensemble, Abstraction abstraction, GameObject compositionGameObject)
    {
        List <RepresentationMesh> resultMesh       = new List <RepresentationMesh> ();
        List <Structure>          resultStructures = new List <Structure> ();

        this.ensemble = ensemble;

        List <KeyValuePair <string, float> > paramsValues = new List <KeyValuePair <string, float> > ();

        for (int i = 0; i < axisParameters.Count; i++)
        {
            paramsValues.Add(new KeyValuePair <string, float>(axisParameters[i].name, axisParameters[i].value));
        }

        ParameterInfo zPI    = ensemble.parametersInfo [axisParameters [0].name];
        float         zDelta = (zPI.maxValue - zPI.minValue) / (float)(zPI.count - 1);

        for (float i = zPI.minValue; i <= zPI.maxValue; i += zDelta)
        {
            paramsValues[0] = new KeyValuePair <string, float>(paramsValues[0].Key, i);
            resultStructures.Add(ensemble.GetStructure(paramsValues));
        }

        Camera cam = Camera.main;

        yPosStart = cam.gameObject.transform.position.y - cam.orthographicSize;

        /*
         * float xPosStart = cam.gameObject.transform.position.x;
         * float yPosStart = cam.gameObject.transform.position.y - cam.orthographicSize;
         * float zPosStart = 0;
         */

        foreach (Structure structure in resultStructures)
        {
            (structure.representation as RepresentationMesh).gameObject.SetActive(true);
            RepresentationMesh newRep = abstraction.Process(structure.representation as RepresentationMesh) as RepresentationMesh;
            (structure.representation as RepresentationMesh).gameObject.SetActive(false);

            newRep.gameObject.transform.parent = compositionGameObject.transform;

            float valZ = (structure.parameters [axisParameters[0].name].value - zPI.minValue) / zDelta;

            newRep.gameObject.transform.position = new Vector3(xPosStart, yPosStart, zPosStart + valZ * (itemSizeZ + itemOffset));

            switch (type)
            {
            case SPType.None:
            {
                break;
            }

            case SPType.Transparent:
            {
                newRep.SetMaterialTransparency(0.25f);
                break;
            }

            case SPType.Colorify:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.SetMaterialColor(zColor);
                break;
            }

            case SPType.BlendColor:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.BlendMaterialColor(zColor);
                break;
            }

            case SPType.ColorTransparent:
            {
                float zVal   = valZ / zPI.count;
                Color zColor = Color.white;

                if (zVal <= 0.5f)
                {
                    zColor = new Color(1f, zVal * 2f, zVal * 2f);
                }
                else
                {
                    zColor = new Color(2f - 2f * zVal, 2f - 2f * zVal, 1f);
                }

                newRep.SetMaterialColorTransparency(zColor, 0.25f);
                break;
            }

            default:
            {
                newRep.SetMaterialTransparency(0.25f);
                break;
            }
            }
        }

        Vector3 target = new Vector3(xPosStart, yPosStart, zPosStart + (zPI.count / 2) * (itemSizeZ + itemOffset));

        Camera.main.gameObject.GetComponent <MouseCameraControl> ().yaw.target   = target;
        Camera.main.gameObject.GetComponent <MouseCameraControl> ().pitch.target = target;

        return(resultMesh);
    }
Exemplo n.º 14
0
    public override List <RepresentationMesh> PlaceRepresentations(Ensemble ensemble, Abstraction abstraction, GameObject compositionGameObject)
    {
        List <RepresentationMesh> resultMesh       = new List <RepresentationMesh> ();
        List <Structure>          resultStructures = new List <Structure> ();

        this.ensemble = ensemble;

        List <KeyValuePair <string, float> > paramsValues = new List <KeyValuePair <string, float> > ();

        for (int i = 0; i < axisParameters.Count; i++)
        {
            paramsValues.Add(new KeyValuePair <string, float>(axisParameters[i].name, axisParameters[i].value));
        }

        ParameterInfo pi     = ensemble.parametersInfo [axisParameters [0].name];
        float         xDelta = (pi.maxValue - pi.minValue) / (float)(pi.count - 1);

        List <float> xDeltas = new List <float> ();

        for (float i = pi.minValue; i <= pi.maxValue; i += xDelta)
        {
            xDeltas.Add(i);
        }

        if (xDeltas.Count > itemCount)
        {
            int diffCount = xDeltas.Count - itemCount;
            for (int i = 0; i < diffCount; i++)
            {
                xDeltas.RemoveAt(Random.Range(0, xDeltas.Count - 1));
            }
        }

        foreach (float value in xDeltas)
        {
            paramsValues[0] = new KeyValuePair <string, float>(paramsValues[0].Key, value);
            resultStructures.Add(ensemble.GetStructure(paramsValues));
        }

        Camera cam = Camera.main;

        yPosStart = cam.gameObject.transform.position.y - cam.orthographicSize + (float)camOffset;

        int val = 0;

        foreach (Structure structure in resultStructures)
        {
            (structure.representation as RepresentationMesh).gameObject.SetActive(true);
            RepresentationMesh newRep = abstraction.Process(structure.representation as RepresentationMesh) as RepresentationMesh;
            (structure.representation as RepresentationMesh).gameObject.SetActive(false);

            newRep.gameObject.transform.parent = compositionGameObject.transform;

            newRep.gameObject.transform.position = new Vector3(xPosStart + val * (itemSizeX + itemOffset) + newRep.offset.x, yPosStart, 0);
            val++;
        }

        GameObject uiGO     = GameObject.Find("UI") as GameObject;
        GameObject xPanel   = uiGO.transform.Find("X Axis Panel").gameObject;
        GameObject sliderGO = xPanel.transform.Find("Slider").gameObject;

        sliderGO.SetActive(true);
        Slider slider = sliderGO.GetComponent <Slider> ();

        slider.minValue = pi.minValue;
        slider.maxValue = pi.maxValue;
        slider.value    = pi.minValue;

        slider.onValueChanged.RemoveAllListeners();
        slider.onValueChanged.AddListener(CameraPositionChanged);

        cameraXEndPos = xPosStart + ((float)resultStructures.Count - 0.5f) * itemSizeX + ((float)resultStructures.Count - 1f) * itemOffset - cam.orthographicSize + camOffset;

        cam.transform.position = new Vector3(0, yPosStart / 2f, -300f);

        return(resultMesh);
    }