/// <summary> /// Evaluates the function. /// </summary> /// <param name="Arguments">Function arguments.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Function result.</returns> public override IElement Evaluate(IElement[] Arguments, Variables Variables) { Graphs3D.PhongIntensity Diffuse = Graphs3D.Canvas3D.ToPhongIntensity(Arguments[0].AssociatedObjectValue); Graphs3D.PhongIntensity Specular = Graphs3D.Canvas3D.ToPhongIntensity(Arguments[1].AssociatedObjectValue); Vector3 Position = Graphs3D.Canvas3D.ToVector3(Arguments[2].AssociatedObjectValue); return(new ObjectValue(new Graphs3D.PhongLightSource(Diffuse, Specular, Position))); }
/// <summary> /// Evaluates the function. /// </summary> /// <param name="Arguments">Function arguments.</param> /// <param name="Variables">Variables collection.</param> /// <returns>Function result.</returns> public override IElement Evaluate(IElement[] Arguments, Variables Variables) { Graphs3D.PhongIntensity Ambient = Graphs3D.Canvas3D.ToPhongIntensity(Arguments[1].AssociatedObjectValue); Graphs3D.PhongLightSource[] LightSources; object Obj; if (!(Arguments[0].AssociatedObjectValue is Graphs3D.PhongMaterial Material)) { throw new ScriptRuntimeException("Phong material expected in first argument.", this); } Obj = Arguments[2].AssociatedObjectValue; if (Obj is Graphs3D.PhongLightSource Source) { LightSources = new Graphs3D.PhongLightSource[] { Source } } ; else if (Obj is IVector V) { List <Graphs3D.PhongLightSource> Sources = new List <Graphs3D.PhongLightSource>(); foreach (IElement E in V.VectorElements) { if (E.AssociatedObjectValue is Graphs3D.PhongLightSource Source2) { Sources.Add(Source2); } else { throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this); } } LightSources = Sources.ToArray(); } else { throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this); } return(new ObjectValue(new Graphs3D.PhongShader(Material, Ambient, LightSources))); }