Exemple #1
0
    public IEnumerable <bool> UpdateMultiChakras()
    {
        this.MultiChakras = this.gameObject.transform.parent
                            .GetComponentsInChildren <VolumeTextureBehavior>()
                            //.Where(k => (k.IsAura)||(k.name.Contains("Solar"))).ToArray()
        ;
        List <Matrix4x4> worldToChakras = new List <Matrix4x4>();

        foreach (var c in this.MultiChakras)
        {
            c.EnsureSetup();
            worldToChakras.Add(c.transform.worldToLocalMatrix);
        }

        Debug.Log("MULTI CHAKRA from " + this.MultiChakras.Length + " children.");

        var m2w = this.transform.localToWorldMatrix;

        bool debugMe = true;

        var proj = SpanAPI.spanProjFromCubicDomainAndRange(
            mColorBuffer.Size.Select(k => SpanAPI.span(0, k - 1)),
            Cubic <SpanF> .CreateSame(SpanAPI.span(-0.5, 0.5))
            );
        var invProj = SpanAPI.spanProjFromCubicDomainAndRange(
            Cubic <SpanF> .CreateSame(SpanAPI.span(-0.5, 0.5)),
            mColorBuffer.Size.Select(k => SpanAPI.span(0, k - 1))
            );
        var invProjForMath = SpanAPI.spanProjFromCubicDomainAndRange(
            Cubic <SpanF> .CreateSame(SpanAPI.span(-0.5, 0.5)),
            Cubic <SpanF> .CreateSame(SpanAPI.span(-1.0, 1.0))
            );

        //var proj = SpanAPI.Example_SetupProjection (mColorBuffer.Size.X, mColorBuffer.Size.Y, mColorBuffer.Size.Z);
        //var invProj = SpanAPI.Example_SetupSignedUnitToIntProjection(mColorBuffer.Size.X, mColorBuffer.Size.Y, mColorBuffer.Size.Z);
        Color defaultVal = Color.clear;

        for (int i = 0; i < this.mColorBuffer.Length; i++)
        {
            var   ndx      = this.mColorBuffer.UnprojectIndex(i);
            var   mpos     = SpanAPI.spanProjCubicInt(proj, ndx);
            Color curColor = defaultVal;

            if (this.mColorBuffer.IsEdge(ndx))
            {
                // it's an edge, ignore it
            }
            else
            {
                //foreach (var chakra in this.MultiChakras)
                for (int ci = 0; ci < this.MultiChakras.Length; ci++)
                {
                    var chakra = this.MultiChakras[ci];
                    var w2c    = worldToChakras[ci];

                    var cpos = MultiplySpanByMatrix(mpos, w2c * m2w);// m2w * w2c);
                    //cpos = cpos.Select(k => SpanAPI.spanMult(k, SpanAPI.spanExactly(1.5)));

                    if (MultiChakraFullEval && (!chakra.IsAura))
                    {
                        var suSpan  = SpanAPI.spanProjCubicSpan(invProjForMath, cpos);
                        var suVal   = chakra.ChakraFieldFromSignedUnit(suSpan);
                        var suColor = chakra.ColorFromChakraField(suVal);
                        curColor = MixColors(curColor, suColor);
                        continue;
                    }


                    var fspan = SpanAPI.spanProjCubicSpan(invProj, cpos);
                    fspan = fspan.Select(k => SpanAPI.spanMult(k, SpanAPI.spanExactly(1.01)));
                    var ispan  = fspan.Select(k => SpanI.FromSpanF(k));
                    var sample = chakra.mColorBuffer.SampleSpan(ispan, Color.clear, (a, b) => MixColors(a, b));

                    if (debugMe)
                    {
                        debugMe = false;
                        Debug.Log("proj = " + proj);
                        Debug.Log("invProj = " + invProj);

                        Debug.Log("ndx = " + ndx);
                        Debug.Log("mpos = " + mpos);
                        var testInvPos = SpanAPI.spanProjCubicSpan(invProj, mpos);
                        Debug.Log("testInvPos = " + testInvPos);
                        var testISpan = testInvPos.Select(k => SpanI.FromSpanF(k));
                        Debug.Log("testISpan = " + testISpan);

                        Debug.Log("mpos = " + mpos);
                        Debug.Log("cpos = " + cpos);
                        Debug.Log("fspan = " + fspan);
                        Debug.Log("ispan = " + ispan);
                        Debug.Log("sample = " + sample);
                    }

                    curColor = MixColors(curColor, sample);
                }
            }

            this.mColorBuffer.Write(ndx, curColor);

            if (((i % 100)) == 99)
            {
                this.UpdateTextureFromBuffer();
                yield return(false);
            }
        }

        //return;

        this.UpdateTextureFromBuffer();
        this.TrySaveToCache();

        Debug.Log("MULTI CHAKRAS UPDATED!");
    }