Ejemplo n.º 1
0
        /// <summary>
        /// Updates the field with a new value just in the SceneGraph.
        /// (Changes in the field are picked up by a currrently running X3DProgrammableShaderObject)
        /// </summary>
        public void setFieldValue(string name, object value)
        {
            field field = (field)this.Children
                          .FirstOrDefault(n => n.GetType() == typeof(field) &&
                                          n.getAttribute("name").ToString() == name);

            Type   type;
            object convValue;
            Type   conv;

            try
            {
                type      = X3DTypeConverters.X3DSimpleTypeToManagedType(field.type);
                convValue = Convert.ChangeType(value, type);
                conv      = convValue.GetType();

                if (conv == typeof(int))
                {
                    UpdateField(name, X3DTypeConverters.ToString((int)convValue));
                }
                if (conv == typeof(float))
                {
                    UpdateField(name, X3DTypeConverters.ToString((float)convValue));
                }
                if (conv == typeof(Vector3))
                {
                    UpdateField(name, X3DTypeConverters.ToString((Vector3)convValue));
                }
                if (conv == typeof(Vector4))
                {
                    UpdateField(name, X3DTypeConverters.ToString((Vector4)convValue));
                }
                if (conv == typeof(Matrix3))
                {
                    UpdateField(name, X3DTypeConverters.ToString((Matrix3)convValue));
                }
                if (conv == typeof(Matrix4))
                {
                    UpdateField(name, X3DTypeConverters.ToString((Matrix4)convValue));
                }
            }
            catch
            {
                Console.WriteLine("error");
            }
        }