Exemplo n.º 1
0
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            if (SchemaMaterial == null)
            {
                SchemaMaterial = GameObject.Instantiate(MaterialFactory.GetDefaultMaterial());
            }

            MaterialTarget.SetValue(SchemaMaterial, newSchema);

            Router.TransmitAllSchema(newSchema);
        }
Exemplo n.º 2
0
        public void Apply()
        {
            {
                m_used.Clear();
                foreach (var kv in m_materialColorMap)
                {
                    var key = MaterialTarget.Create(kv.Key);
                    PreviewMaterialItem item;
                    if (m_materialMap.TryGetValue(key.MaterialName, out item))
                    {
                        // 初期値(コンストラクタで記録)
                        var initial = item.PropMap[kv.Key.BindType].DefaultValues;
                        if (!m_used.Contains(key))
                        {
                            //
                            // m_used に入っていない場合は、このフレームで初回の呼び出しになる。
                            // (Apply はフレームに一回呼ばれる想定)
                            // 初回は、値を初期値に戻す。
                            //
                            item.Material.SetColor(key.ValueName, initial);
                            m_used.Add(key);
                        }

                        // 現在値
                        var current = item.Material.GetVector(key.ValueName);
                        // 変化量
                        var value = (kv.Key.TargetValue - initial) * kv.Value;
                        // 適用
                        item.Material.SetColor(key.ValueName, current + value);
                    }
                    else
                    {
                        // エラー?
                    }
                }
                m_materialColorMap.Clear();
            }

            {
                foreach (var kv in m_materialUVMap)
                {
                    PreviewMaterialItem item;
                    if (m_materialMap.TryGetValue(kv.Key, out item))
                    {
                        //
                        // Standard and MToon use _MainTex_ST as uv0 scale/offset
                        //
                        item.Material.SetVector("_MainTex_ST", kv.Value);
                    }
                }
                m_materialUVMap.Clear();
            }
        }
Exemplo n.º 3
0
        public void Apply()
        {
            // clear
            //RestoreMaterialInitialValues(m_clips);
            m_used.Clear();

            // (binding.Value-Base) * weight を足す
            foreach (var kv in m_materialValueMap)
            {
                var key = MaterialTarget.Create(kv.Key);
                if (!m_used.Contains(key))
                {
                    // restore value
                    Material material;
                    if (m_materialMap.TryGetValue(key.MaterialName, out material))
                    {
                        var value     = kv.Key.BaseValue;
                        var valueName = key.ValueName;
                        if (valueName.EndsWith("_ST_S"))
                        {
                            valueName = valueName.Substring(0, valueName.Length - 2);
                            var v = material.GetVector(valueName);
                            value.y = v.y;
                            value.w = v.w;
                        }
                        else if (valueName.EndsWith("_ST_T"))
                        {
                            valueName = valueName.Substring(0, valueName.Length - 2);
                            var v = material.GetVector(valueName);
                            value.x = v.x;
                            value.z = v.z;
                        }
                        material.SetColor(valueName, value);
                    }
                    m_used.Add(key);
                }

                Setter setter;
                if (m_materialSetterMap.TryGetValue(kv.Key, out setter))
                {
                    setter(kv.Value, false);
                }
            }
            m_materialValueMap.Clear();
        }
Exemplo n.º 4
0
 public ProcessingTarget(MaterialTarget target, Protocol defaultProtocol, Process defaultProcess)
     : base(target)
 {
     m_defaultProtocol = defaultProtocol;
     m_defaultProcess  = defaultProcess;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Expands all the processing (i.e. ProcessRefs, ProcedureRef, etc...) under this destination into procedures. By converting all processing into procedures, searching and tracing is considerably easier.
        /// </summary>
        /// <param name="parentDestination">The parent destination to convert into procedures.</param>
        /// <param name="startProcedureIndex">The start procedure within the material target on the parent destination from which to begin converting.</param>
        /// <param name="defaultTarget">The default target describing the current procotol and process.</param>
        /// <returns>The expanded list of procedures</returns>
        private List <Procedure> ExpandToProcedures(MaterialDestination parentDestination, Int32 startProcedureIndex, ProcessingTarget defaultTarget)
        {
            List <Procedure> procedures = new List <Procedure>();

            // Does this destination have a target to expand ? if not then just return an empty procedure list
            if (parentDestination == null || !parentDestination.HasTarget)
            {
                return(procedures);
            }

            // Invalid target ?
            if (!parentDestination.IsValidTarget)
            {
                this.OnValidationEvent(new ValidationResult(ErrorCodes.SampleProcessingHistory, ErrorLevel.Error, String.Format(Languages.Strings.valResultInvalidMaterialTarget, parentDestination.Target == null ? "?" : parentDestination.Target.ToString())));
            }

            // Does this destination have a list of procedures as its target ? if so then expand each procedure
            if (parentDestination.Target.HasProcedure())
            {
                // Add each procedure in the target and expand the procedure's destinations
                for (Int32 i = startProcedureIndex; i < parentDestination.Target.Procedure.Length; i++)
                {
                    procedures.Add(parentDestination.Target.Procedure[i]);

                    // Expand each destination into procedures
                    List <MaterialDestination> destinations = parentDestination.Target.Procedure[i].GetDestinations();
                    foreach (MaterialDestination destination in destinations)
                    {
                        MaterialTarget target = new MaterialTarget();
                        target.Procedure   = this.ExpandToProcedures(destination, 0, defaultTarget).ToArray();
                        destination.Target = target;
                    }
                }
            }

            // Does the destination have references to a protocol, process or procedure name instead?
            // if so then set the default target to the current protocol etc... and expand the reference
            else if (parentDestination.Target.IsSpecified)
            {
                ProcessingTarget searchTarget = new ProcessingTarget(defaultTarget);

                // Is there a protocol reference ?
                if (parentDestination.Target.HasProtocol())
                {
                    searchTarget.ProtocolRef = parentDestination.Target.ProtocolRef;
                }

                // Is there a process reference ?
                if (parentDestination.Target.HasProcessName())
                {
                    searchTarget.ProcessRef = parentDestination.Target.ProcessRef;
                }

                // Is there a procedure reference ?
                if (parentDestination.Target.HasProcedureName())
                {
                    searchTarget.ProcedureRef = parentDestination.Target.ProcedureRef;
                }

                // Is there a material source reference ?
                if (parentDestination.Target.HasMaterialSourceName())
                {
                    searchTarget.MaterialSourceRef = parentDestination.Target.MaterialSourceRef;
                }

                // Is the current target's references valid (i.e. is there a protocol or process that matches the specified protocol or process, etc...).
                SearchForTargetDetails match = this.SearchForTarget(searchTarget);

                // If the target is valid and points to another position in the ADX document then jump to that place and continue expanding into procedures
                if (match != null && match.destination != null)
                {
                    searchTarget.DefaultProcess  = match.process;
                    searchTarget.DefaultProtocol = match.protocol;
                    procedures.AddRange(this.ExpandToProcedures(match.destination.Clone(), match.procedureIndex, searchTarget));
                }
            }

            return(procedures);
        }
Exemplo n.º 6
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var currentWidth = 0f;

            var flagColorImpact = FlagColorImpact.GetFirstValue(payload.Data);

            var sections = SectionScope.GetEntries(payload.Data).ToList();

            var totalSize = (float)(from entry in SectionScope.GetEntries(payload.Data)
                                    select
                                    SectionMemorySize.GetValue(entry)).Aggregate((a, b) => a + b);

            ColorGradient sectionGradient = new ColorGradient(2 * sections.Count);

            foreach (var section in SectionScope.GetEntries(payload.Data))
            {
                var bandColor = Color.Lerp(
                    SectionColorMapping.GetSectionTypeColor(SectionType.GetValue(section)),
                    SectionColorMapping.GetSectionFlagColor(SectionFlag.GetValue(section)),
                    flagColorImpact);
                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += SectionMemorySize.GetValue(section);

                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += Epsilon * totalSize;
            }

            var textureWidth  = TextureWidth.GetFirstValue(payload.Data);
            var textureHeight = TextureHeight.GetFirstValue(payload.Data);

            sectionGradient.RescaleColorKeys(currentWidth);


            var resultTexture = new Texture2D(textureWidth, textureHeight);

            var outColors = new Color[textureWidth * textureHeight];

            for (int x = 0; x < textureWidth; x++)
            {
                var localColor = sectionGradient.Evaluate(x / (float)textureWidth);
                for (int y = 0; y < textureHeight; y++)
                {
                    outColors[x + textureWidth * y] = localColor;
                }
            }

            resultTexture.SetPixels(outColors);
            resultTexture.Apply();

            var quadMaterial = GameObject.Instantiate(MaterialFactory.GetDefaultMaterial());

            quadMaterial.mainTexture = resultTexture;

            MaterialTarget.SetValue(quadMaterial, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }