Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PhongShader.cs
1using System;
2using System.Collections.Generic;
3using System.Numerics;
8
10{
15 {
25 public PhongShader(ScriptNode Diffuse, ScriptNode Specular, ScriptNode Position,
27 : base(new ScriptNode[] { Diffuse, Specular, Position },
28 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Normal }, Start, Length, Expression)
29 {
30 }
31
35 public override string FunctionName => nameof(PhongShader);
36
40 public override string[] DefaultArgumentNames => new string[]
41 {
42 "Material",
43 "Ambient",
44 "LightSources"
45 };
46
54 {
55 Graphs3D.PhongIntensity Ambient = Graphs3D.Canvas3D.ToPhongIntensity(Arguments[1].AssociatedObjectValue);
56 Graphs3D.PhongLightSource[] LightSources;
57 object Obj;
58
59 if (!(Arguments[0].AssociatedObjectValue is Graphs3D.PhongMaterial Material))
60 throw new ScriptRuntimeException("Phong material expected in first argument.", this);
61
62 Obj = Arguments[2].AssociatedObjectValue;
63 if (Obj is Graphs3D.PhongLightSource Source)
64 LightSources = new Graphs3D.PhongLightSource[] { Source };
65 else if (Obj is IVector V)
66 {
67 List<Graphs3D.PhongLightSource> Sources = new List<Graphs3D.PhongLightSource>();
68
69 foreach (IElement E in V.VectorElements)
70 {
71 if (E.AssociatedObjectValue is Graphs3D.PhongLightSource Source2)
72 Sources.Add(Source2);
73 else
74 throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this);
75 }
76
77 LightSources = Sources.ToArray();
78 }
79 else
80 throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this);
81
82 return new ObjectValue(new Graphs3D.PhongShader(Material, Ambient, LightSources));
83 }
84 }
85}
Class managing a script expression.
Definition: Expression.cs:39
Generates a Graphs3D.PhongShader object.
Definition: PhongShader.cs:15
override string[] DefaultArgumentNames
Default Argument names
Definition: PhongShader.cs:40
PhongShader(ScriptNode Diffuse, ScriptNode Specular, ScriptNode Position, int Start, int Length, Expression Expression)
Generates a Graphs3D.PhongIntensity object.
Definition: PhongShader.cs:25
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: PhongShader.cs:53
override string FunctionName
Name of the function
Definition: PhongShader.cs:35
Contains information about the intensity of a light component, as used in the Phong reflection model....
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for vectors.
Definition: IVector.cs:9
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9