Exemple #1
0
        public void SetParameter(string varName, object varValue)
        {
            EffectVariable ev = DXEffect.GetVariableByName(varName);

            if (ev.IsValid)
            {
                if (varValue is bool)
                {
                    ev.AsScalar().Set((bool)varValue);
                }
                else if (varValue is int)
                {
                    ev.AsScalar().Set((int)varValue);
                }
                else if (varValue is uint)
                {
                    ev.AsScalar().Set((uint)varValue);
                }
                else if (varValue is float)
                {
                    ev.AsScalar().Set((float)varValue);
                }
                else if (varValue is double)
                {
                    ev.AsScalar().Set((float)(double)varValue);
                }
                else if (varValue is Vector2)
                {
                    ev.AsVector().Set((Vector2)varValue);
                }
                else if (varValue is Vector3)
                {
                    ev.AsVector().Set((Vector3)varValue);
                }
                else if (varValue is Vector4[])
                {
                    ev.AsVector().Set((Vector4[])varValue);
                }
                else if (varValue is Vector4)
                {
                    ev.AsVector().Set((Vector4)varValue);
                }
                else if (varValue is Matrix)
                {
                    ev.AsMatrix().SetMatrix((Matrix)varValue);
                }
                //else if (varValue is DXTexture2DClass) ev.AsShaderResource().SetResource((varValue as DXTexture2DClass).TextureResourceView);
                else if (varValue is ShaderResourceView)
                {
                    ev.AsShaderResource().SetResource(varValue as ShaderResourceView);
                }
                else if (varValue == null)
                {
                    ev.AsShaderResource().SetResource(null);
                }
                else /* ... */ } {
        }
    }
Exemple #2
0
 protected void SetAsVector(Vector4 vec, EffectVariable variable, bool isVector3)
 {
     if (!isVector3)
     {
         variable.AsVector().Set(vec);
     }
     else
     {
         variable.AsVector().Set(new Vector3(vec.X, vec.Y, vec.Z));
     }
 }
Exemple #3
0
 public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
 {
     if (this.Object == ObjectAnnotationType.Camera)
     {
         subscribeTo.AsVector().Set(variable.Context.MatrixManager.ViewMatrixManager.CameraPosition);
     }
     else
     {
         subscribeTo.AsVector().Set(variable.Context.LightManager.Position);
     }
 }
Exemple #4
0
 protected void エフェクト変数にベクトルを設定する(Vector4 vector4, EffectVariable d3dEffectVariable, bool Vector3である)
 {
     if (Vector3である)
     {
         d3dEffectVariable.AsVector().Set(new Vector3(vector4.X, vector4.Y, vector4.Z));
     }
     else
     {
         d3dEffectVariable.AsVector().Set(vector4);
     }
 }
Exemple #5
0
 public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
 {
     if (this.Object == ObjectAnnotationType.Camera)
     {
         Vector3 direction =
             Vector3.Normalize(variable.Context.MatrixManager.ViewMatrixManager.CameraLookAt -
                               variable.Context.MatrixManager.ViewMatrixManager.CameraPosition);
         subscribeTo.AsVector().Set(direction);
     }
     else
     {
         subscribeTo.AsVector().Set(variable.Context.LightManager.Direction);
     }
 }
        public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
        {
            Viewport vp       = variable.Context.DeviceManager.Context.Rasterizer.GetViewports()[0];
            Vector2  argument = new Vector2(vp.Width, vp.Height);

            subscribeTo.AsVector().Set(argument);
        }
Exemple #7
0
        protected override void SetDefault(InputAttribute attr, EffectVariable var)
        {
            Vector4 vec = var.AsVector().GetVector();

            attr.DefaultValues = new double[] { vec.X, vec.Y, vec.Z, vec.W };
            attr.AsInt         = true;
        }
        public override void  数を更新する(EffectVariable 数, 数更新時引数 引数)
        {
            // 変数には、登録値に関係なく、現在の RenderContext の内容を反映する。

            switch (Object)
            {
            case Object種別.カメラ:
                数.AsVector().Set(RenderContext.Instance.行列管理.ビュー行列管理.カメラの位置);
                break;

            case Object種別.ライト:
                数.AsVector().Set(RenderContext.Instance.照明行列管理.照明の位置);
                break;

            default:
                throw new System.NotSupportedException();
            }
        }
        protected override void CreatePin(EffectVariable variable)
        {
            var visible = variable.Visible();

            this.factory.PluginHost.CreateColorInput(variable.UiName(), TSliceMode.Dynamic, visible ? TPinVisibility.True : TPinVisibility.OnlyInspector, out this.pin);

            Vector4 vec = variable.AsVector().GetVector();

            this.pin.SetSubType(new RGBAColor(vec.X, vec.Y, vec.Z, vec.W), true);
        }
Exemple #10
0
        public static void UpdateCommonEffectVars(Shader effect, Matrix world)
        {
            if (effect == null)
            {
                return;
            }
            Dictionary <string, EffectVariable> vars = effect.Vars;

            if (vars == null)
            {
                return;
            }

            foreach (KeyValuePair <string, EffectVariable> pair in vars)
            {
                EffectVariable v = pair.Value;

                if (pair.Key == ViewMatrix)
                {
                    v.AsMatrix().SetMatrix(Camera.ViewMatrix);
                }
                else if (pair.Key == ProjectionMatrix)
                {
                    v.AsMatrix().SetMatrix(Camera.ProjectionMatrix);
                }
                else if (pair.Key == WorldMatrix)
                {
                    v.AsMatrix().SetMatrix(world);
                }
                else if (pair.Key == WVP)
                {
                    v.AsMatrix().SetMatrix(world * Camera.ViewMatrix * Camera.ProjectionMatrix);
                }
                else if (pair.Key == WorldView)
                {
                    v.AsMatrix().SetMatrix(world * Camera.ViewMatrix);
                }
                else if (pair.Key == ViewProj)
                {
                    v.AsMatrix().SetMatrix(Camera.ProjectionMatrix * Camera.ViewMatrix);
                }
                else if (pair.Key == CameraPosition)
                {
                    v.AsVector().Set(new Vector4(Camera.Position, 1));
                }
            }
        }
 public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
 {
     subscribeTo.AsVector().Set(variable.Material.SphereAddValue);
 }
Exemple #12
0
        /// <summary>
        /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド
        /// </summary>
        /// <param name="variable">エフェクト変数</param>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="defaultFormat"></param>
        /// <param name="defaultViewPortRatio"></param>
        /// <param name="width">テクスチャの幅</param>
        /// <param name="height">テクスチャの高さ</param>
        /// <param name="depth">テクスチャの深さ(ない場合は-1)</param>
        /// <param name="mip">mipレベル</param>
        /// <param name="textureFormat">指定されているフォーマット</param>
        public static void GetBasicTextureAnnotations(EffectVariable variable, RenderContext context, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth,
                                                      out int mip, out Format textureFormat)
        {
            width         = -1;
            height        = -1;
            depth         = -1;
            mip           = 0;
            textureFormat = defaultFormat;
            EffectVariable rawWidthVal  = EffectParseHelper.getAnnotation(variable, "width", "int");
            EffectVariable rawHeightVal = EffectParseHelper.getAnnotation(variable, "height", "int");
            EffectVariable rawDepthVal  = EffectParseHelper.getAnnotation(variable, "depth", "int");

            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            EffectVariable rawViewportRatio = EffectParseHelper.getAnnotation(variable, "viewportratio", "float2");

            if (rawViewportRatio != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                            variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4  rawRatio = rawViewportRatio.AsVector().GetVector();
                    Viewport vp       = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            EffectVariable rawDimensions = EffectParseHelper.getAnnotation(variable, "dimension", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.GetVariableType().Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(2);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                    }
                    else
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(3);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                        depth  = rawDimension[2];
                    }
                }
            }
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    Viewport port = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShaderException(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            EffectVariable rawMipLevel = EffectParseHelper.getAnnotation(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.getAnnotation(variable, "levels", "int");

            if (rawMipLevel != null && rawLevel != null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。",
                                        variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
            }
            else if (rawMipLevel != null || rawLevel != null)
            {
                EffectVariable mipVal = rawMipLevel ?? rawLevel;
                mip = mipVal.AsScalar().GetInt();
            }
            EffectVariable rawFormat = EffectParseHelper.getAnnotation(variable, "format", "string");

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                textureFormat = TextureFormat(formatString);
            }
        }
 public override void  数を更新する(EffectVariable 数, 数更新時引数 引数)
 {
     数.AsVector().Set(RenderContext.Instance.パネル監視.MousePosition);
 }
        public ImageShaderPass(EffectPass pd)
        {
            this.Mips           = false;
            this.CustomFormat   = false;
            this.ScaleVector    = new Vector2(1, 1);
            this.DoScale        = false;
            this.Reference      = eImageScaleReference.Previous;
            this.BlendPreset    = "";
            this.DepthPreset    = "";
            this.UseDepth       = false;
            this.HasState       = false;
            this.KeepTarget     = false;
            this.Absolute       = false;
            this.IterationCount = 1;

            this.ComputeData = new ImageComputeData(pd);

            EffectVariable var = pd.GetAnnotationByName("format");

            if (var.IsValid)
            {
                string fmt = var.AsString().GetString();
                this.CustomFormat = true;
                this.Format       = (SlimDX.DXGI.Format)Enum.Parse(typeof(SlimDX.DXGI.Format), fmt, true);
            }

            var = pd.GetAnnotationByName("mips");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.Mips = b;
            }

            var = pd.GetAnnotationByName("scale");
            if (var.IsValid)
            {
                if (var.GetVariableType().Description.Class == ShaderVariableClass.Scalar)
                {
                    float s = var.AsScalar().GetFloat();
                    this.ScaleVector = new Vector2(s, s);
                    this.DoScale     = true;
                }
                if (var.GetVariableType().Description.Class == ShaderVariableClass.Vector)
                {
                    Vector4 s = var.AsVector().GetVector();
                    this.ScaleVector = new Vector2(s.X, s.Y);
                    this.DoScale     = true;
                }
                var = pd.GetAnnotationByName("absolute");
                if (var.IsValid && var.GetVariableType().Description.Class == ShaderVariableClass.Scalar)
                {
                    this.Absolute = var.AsScalar().GetFloat() > 0.5f;
                }
            }

            var = pd.GetAnnotationByName("initial");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.Reference = b ? eImageScaleReference.Initial : eImageScaleReference.Previous;
            }

            var = pd.GetAnnotationByName("iterations");
            if (var.IsValid)
            {
                try
                {
                    int i = var.AsScalar().GetInt();

                    this.IterationCount = Math.Max(1, i);
                }
                catch
                {
                }
            }

            var = pd.GetAnnotationByName("clear");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.Clear = b;
            }

            var = pd.GetAnnotationByName("usedepth");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.UseDepth = b;
            }

            var = pd.GetAnnotationByName("keeptarget");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.KeepTarget = b;
            }

            var = pd.GetAnnotationByName("hasstate");
            if (var.IsValid)
            {
                bool b = var.AsScalar().GetFloat() > 0.5f;
                this.HasState = b;
            }


            var = pd.GetAnnotationByName("blendpreset");
            if (var.IsValid)
            {
                string blend = var.AsString().GetString();
                this.BlendPreset = blend;
            }


            var = pd.GetAnnotationByName("depthpreset");
            if (var.IsValid)
            {
                string depth = var.AsString().GetString();
                this.DepthPreset = depth;
            }
        }
        /// <summary>
        /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド
        /// </summary>
        /// <param name="variable">エフェクト変数</param>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="defaultFormat"></param>
        /// <param name="defaultViewPortRatio"></param>
        /// <param name="width">テクスチャの幅</param>
        /// <param name="height">テクスチャの高さ</param>
        /// <param name="depth">テクスチャの深さ(ない場合は-1)</param>
        /// <param name="mip">mipレベル</param>
        /// <param name="textureFormat">指定されているフォーマット</param>
        public static void 解析する(EffectVariable variable, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth, out int mip, out Format textureFormat, out Format viewFormat, out Format resourceFormat)
        {
            width          = -1;
            height         = -1;
            depth          = -1;
            mip            = 0;
            textureFormat  = defaultFormat;
            viewFormat     = defaultFormat;
            resourceFormat = defaultFormat;

            #region " int width = ... "
            //----------------
            EffectVariable rawWidthVal = EffectParseHelper.アノテーションを取得する(variable, "width", "int");
            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int height = ... "
            //----------------
            EffectVariable rawHeightVal = EffectParseHelper.アノテーションを取得する(variable, "height", "int");
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int depth = ... "
            //----------------
            EffectVariable rawDepthVal = EffectParseHelper.アノテーションを取得する(variable, "depth", "int");
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " float2 ViewportRatio = ... "
            //----------------
            EffectVariable rawViewportRatio = EffectParseHelper.アノテーションを取得する(variable, "viewportratio", "float2");
            if (rawViewportRatio != null)

            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。", variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4 rawRatio = rawViewportRatio.AsVector().GetFloatVector();
                    var     vp       = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            //----------------
            #endregion

            #region " uing2/uint3 Dimensions = ... "
            //----------------
            EffectVariable rawDimensions = EffectParseHelper.アノテーションを取得する(variable, "dimensions", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.TypeInfo.Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                    }
                    else
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                        depth  = rawDimension.Z;
                    }
                }
            }
            //----------------
            #endregion

            #region "width, height チェック "
            //----------------
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    var port = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShader例外(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            //----------------
            #endregion

            #region " int MipLevels = ... / int RawLevel = ... "
            //----------------
            EffectVariable rawMipLevel = EffectParseHelper.アノテーションを取得する(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.アノテーションを取得する(variable, "levels", "int");

            if (rawMipLevel != null && rawLevel != null)
            {
                throw new InvalidMMEEffectShader例外(
                          string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。",
                                        variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
            }
            else if (rawMipLevel != null || rawLevel != null)
            {
                EffectVariable mipVal = rawMipLevel ?? rawLevel;
                mip = mipVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " string Format = ... "
            //----------------
            EffectVariable rawFormat = EffectParseHelper.アノテーションを取得する(variable, "format", "string");

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                テクスチャフォーマットを返す(formatString, out textureFormat, out viewFormat, out resourceFormat);
            }
            //----------------
            #endregion
        }
Exemple #16
0
 public override void Execute(ISubset ipmxSubset, Action <ISubset> drawAction)
 {
     context.CurrentClearColor = new Color4(sourceVariable.AsVector().GetVector());
 }
 public EffectOnlyVectorArrayVariable(EffectVariable v)
 {
     _v = v.AsVector();
 }
 public override void  数を更新する(EffectVariable 数, 数更新時引数 引数)
 {
     // ターゲットオブジェクトに依存しない
     数.AsVector().Set(引数.材質.テクスチャ乗算値);
 }
        public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
        {
            var currentModel = variable.Context.CurrentTargetContext.WorldSpace.getDrawableByFileName(name);

            if (currentModel == null)
            {
                return;
            }
            IDrawable targetDrawable = isSelf ? variable.Model : currentModel;

            if (target == TargetObject.UnUsed)
            {
                switch (variableType)
                {
                case VariableType.Float4x4:
                    subscribeTo.AsMatrix().SetMatrix(variable.Context.MatrixManager.WorldMatrixManager.getWorldMatrix(targetDrawable));
                    break;

                case VariableType.Float3:
                    subscribeTo.AsVector().Set(targetDrawable.Transformer.Position);
                    break;

                case VariableType.Float4:
                    subscribeTo.AsVector().Set(new Vector4(targetDrawable.Transformer.Position, 1f));
                    break;

                case VariableType.Float:
                    subscribeTo.AsScalar().Set(targetDrawable.Transformer.Scale.Length());
                    break;

                case VariableType.Bool:
                    subscribeTo.AsScalar().Set(targetDrawable.Visibility);
                    break;

                default:
                    break;
                }
            }
            else
            if (target == TargetObject.BoneName)
            {
                IEnumerable <PMXBone> targetBone = (from bone in ((PMXModel)targetDrawable).Skinning.Bone where bone.BoneName == itemName select bone);
                foreach (var bone in targetBone)
                {
                    Matrix mat = bone.GlobalPose * variable.Context.MatrixManager.WorldMatrixManager.getWorldMatrix(targetDrawable);
                    switch (variableType)
                    {
                    case VariableType.Float4x4:
                        subscribeTo.AsMatrix().SetMatrix(mat);
                        break;

                    case VariableType.Float3:
                        subscribeTo.AsVector().Set(Vector3.TransformCoordinate(bone.Position, mat));
                        break;

                    case VariableType.Float4:
                        subscribeTo.AsVector().Set(new Vector4(Vector3.TransformCoordinate(bone.Position, mat), 1f));
                        break;

                    default:
                        break;
                    }
                    break;
                }
            }
            else
            if (target == TargetObject.FaceName)
            {
                IMorphManager morphManager = ((PMXModel)targetDrawable).Morphmanager;
                subscribeTo.AsScalar().Set(morphManager.getMorphProgress(name));
            }
            else
            {
                switch (target)
                {
                case TargetObject.X:
                    subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.X);
                    break;

                case TargetObject.Y:
                    subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.Y);
                    break;

                case TargetObject.Z:
                    subscribeTo.AsScalar().Set(targetDrawable.Transformer.Position.Z);
                    break;

                case TargetObject.XYZ:
                    subscribeTo.AsVector().Set(targetDrawable.Transformer.Position);
                    break;

                case TargetObject.Rx:
                case TargetObject.Ry:
                case TargetObject.Rz:
                case TargetObject.Rxyz:
                    float xRotation, yRotation, zRotation; //X,Y,Z軸回転量に変換する。
                    int   type = 0;                        //分解パターン
                    if (
                        !CGHelper.FactoringQuaternionXYZ(targetDrawable.Transformer.Rotation, out xRotation,
                                                         out yRotation, out zRotation))
                    {
                        if (
                            !CGHelper.FactoringQuaternionYZX(targetDrawable.Transformer.Rotation, out yRotation,
                                                             out zRotation, out xRotation))
                        {
                            CGHelper.FactoringQuaternionZXY(targetDrawable.Transformer.Rotation, out zRotation,
                                                            out xRotation, out yRotation);
                            type = 2;
                        }
                        else
                        {
                            type = 1;
                        }
                    }
                    else
                    {
                        type = 0;
                    }
                    if (target == TargetObject.Rx)
                    {
                        subscribeTo.AsScalar().Set(xRotation);
                    }
                    else if (target == TargetObject.Ry)
                    {
                        subscribeTo.AsScalar().Set(yRotation);
                    }
                    else if (target == TargetObject.Rz)
                    {
                        subscribeTo.AsScalar().Set(zRotation);
                    }
                    else
                    {
                        subscribeTo.AsVector().Set(new Vector3(xRotation, yRotation, zRotation));
                    }
                    break;

                case TargetObject.Si:
                    subscribeTo.AsScalar().Set(targetDrawable.Transformer.Scale.Length());
                    break;

                case TargetObject.Tr:
                    //TODO Trへの対応
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemple #20
0
        public override void  数を更新する(EffectVariable 数, 数更新時引数 引数)
        {
            var currentModel = RenderContext.Instance.描画ターゲットコンテキスト.ワールド空間.Drawableを取得する(_name);

            if (currentModel == null)
            {
                return;
            }

            IDrawable targetDrawable = (_isSelf) ? 引数.モデル : currentModel;

            if (_target == TargetObject.UnUsed)
            {
                switch (_variableType)
                {
                case  数型.Float4x4:
                    数.AsMatrix().SetMatrix(RenderContext.Instance.行列管理.ワールド行列管理.モデルのワールド変換行列を作成して返す(targetDrawable));
                    break;

                case  数型.Float3:
                    数.AsVector().Set(targetDrawable.モデル状態.位置);
                    break;

                case  数型.Float4:
                    数.AsVector().Set(new Vector4(targetDrawable.モデル状態.位置, 1f));
                    break;

                case  数型.Float:
                    数.AsScalar().Set(targetDrawable.モデル状態.率.Length());
                    break;

                case  数型.Bool:
                    数.AsScalar().Set(targetDrawable.表示中);
                    break;

                default:
                    break;
                }
            }
            else if (_target == TargetObject.BoneName)
            {
                IEnumerable <PMXボーン> targetBone = (from bone in ((PMXModel)targetDrawable).スキニング.ボーン配列 where bone.ボーン名 == _itemName select bone);

                foreach (var bone in targetBone)
                {
                    Matrix mat = bone.モデルポーズ行列 * RenderContext.Instance.行列管理.ワールド行列管理.モデルのワールド変換行列を作成して返す(targetDrawable);

                    switch (_variableType)
                    {
                    case  数型.Float4x4:
                        数.AsMatrix().SetMatrix(mat);
                        break;

                    case  数型.Float3:
                        数.AsVector().Set(Vector3.TransformCoordinate(bone.ローカル位置, mat));
                        break;

                    case  数型.Float4:
                        数.AsVector().Set(new Vector4(Vector3.TransformCoordinate(bone.ローカル位置, mat), 1f));
                        break;

                    default:
                        break;
                    }
                    break;
                }
            }
            else if (_target == TargetObject.FaceName)
            {
                モーフ管理 morphManager = ((PMXModel)targetDrawable).モーフ管理;

                数.AsScalar().Set(morphManager.モーフの進捗率を返す(_name));
            }
            else
            {
                switch (_target)
                {
                case TargetObject.X:
                    数.AsScalar().Set(targetDrawable.モデル状態.位置.X);
                    break;

                case TargetObject.Y:
                    数.AsScalar().Set(targetDrawable.モデル状態.位置.Y);
                    break;

                case TargetObject.Z:
                    数.AsScalar().Set(targetDrawable.モデル状態.位置.Z);
                    break;

                case TargetObject.XYZ:
                    数.AsVector().Set(targetDrawable.モデル状態.位置);
                    break;

                case TargetObject.Rx:
                case TargetObject.Ry:
                case TargetObject.Rz:
                case TargetObject.Rxyz:
                    float xRotation, yRotation, zRotation;     //X,Y,Z軸回転量に変換する。
                                                               //int type = 0; //分解パターン
                    if (!CGHelper.クォータニオンをXYZ回転に分解する(targetDrawable.モデル状態.回転, out xRotation, out yRotation, out zRotation))
                    {
                        if (!CGHelper.クォータニオンをYZX回転に分解する(targetDrawable.モデル状態.回転, out yRotation, out zRotation, out xRotation))
                        {
                            CGHelper.クォータニオンをZXY回転に分解する(targetDrawable.モデル状態.回転, out zRotation, out xRotation, out yRotation);
                            //		type = 2;
                        }
                        else
                        {
                            //		type = 1;
                        }
                    }
                    else
                    {
                        //	type = 0;
                    }

                    if (_target == TargetObject.Rx)
                    {
                        数.AsScalar().Set(xRotation);
                    }
                    else if (_target == TargetObject.Ry)
                    {
                        数.AsScalar().Set(yRotation);
                    }
                    else if (_target == TargetObject.Rz)
                    {
                        数.AsScalar().Set(zRotation);
                    }
                    else
                    {
                        数.AsVector().Set(new Vector3(xRotation, yRotation, zRotation));
                    }
                    break;

                case TargetObject.Si:
                    数.AsScalar().Set(targetDrawable.モデル状態.率.Length());
                    break;

                case TargetObject.Tr:
                    // TODO: Trへの対応
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemple #21
0
 public static void Set(this EffectVariable var, Color4[] value)
 {
     var.AsVector().Set(value);
 }
 public override void Subscribe(EffectVariable subscribeTo, SubscribeArgument variable)
 {
     subscribeTo.AsVector().Set(variable.Context.CurrentPanelObserver.MiddleMouseDown);
 }
        public override void  数を更新する(EffectVariable 数, 数更新時引数 引数)
        {
            var viewport = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];

            数.AsVector().Set(new Vector2(viewport.Width, viewport.Height));
        }