Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PhongShader.cs
6
8{
13 {
23 public PhongShader(ScriptNode Diffuse, ScriptNode Specular, ScriptNode Position,
25 : base(new ScriptNode[] { Diffuse, Specular, Position },
26 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Scalar, ArgumentType.Normal }, Start, Length, Expression)
27 {
28 }
29
33 public override string FunctionName => nameof(PhongShader);
34
38 public override string[] DefaultArgumentNames => new string[]
39 {
40 "Material",
41 "Ambient",
42 "LightSources"
43 };
44
52 {
53 Graphs3D.PhongIntensity Ambient = Graphs3D.Canvas3D.ToPhongIntensity(Arguments[1].AssociatedObjectValue);
54 Graphs3D.PhongLightSource[] LightSources;
55 object Obj;
56
57 if (!(Arguments[0].AssociatedObjectValue is Graphs3D.PhongMaterial Material))
58 throw new ScriptRuntimeException("Phong material expected in first argument.", this);
59
60 Obj = Arguments[2].AssociatedObjectValue;
61 if (Obj is Graphs3D.PhongLightSource Source)
62 LightSources = new Graphs3D.PhongLightSource[] { Source };
63 else if (Obj is IVector V)
64 {
65 ChunkedList<Graphs3D.PhongLightSource> Sources = new ChunkedList<Graphs3D.PhongLightSource>();
66
67 foreach (IElement E in V.VectorElements)
68 {
69 if (E.AssociatedObjectValue is Graphs3D.PhongLightSource Source2)
70 Sources.Add(Source2);
71 else
72 throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this);
73 }
74
75 LightSources = Sources.ToArray();
76 }
77 else
78 throw new ScriptRuntimeException("Expected one or more light sources for the third argument.", this);
79
80 return new ObjectValue(new Graphs3D.PhongShader(Material, Ambient, LightSources));
81 }
82 }
83}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
Class managing a script expression.
Definition: Expression.cs:41
Generates a Graphs3D.PhongShader object.
Definition: PhongShader.cs:13
override string[] DefaultArgumentNames
Default Argument names
Definition: PhongShader.cs:38
PhongShader(ScriptNode Diffuse, ScriptNode Specular, ScriptNode Position, int Start, int Length, Expression Expression)
Generates a Graphs3D.PhongIntensity object.
Definition: PhongShader.cs:23
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: PhongShader.cs:51
override string FunctionName
Name of the function
Definition: PhongShader.cs:33
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:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
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