public void Parse(ref string[] program) { string floatFunctionName = ParseUtils.GetToken(ref program); _Function = WooScript.GetFloatFunction(floatFunctionName); _Function.Parse(ref program); }
public void RenderPreview() { _Camera = new Camera(new Vector3(0, 0.4, -0.75), new Vector3(0, 0.5, 0), 40, 0, 0); _Camera._AAEnabled = true; _Camera._DOFEnabled = false; string log = "", error = ""; _BackgroundScript = new WooScript(); _BackgroundScript._Program = "rule main {pos.y -= 1 box}"; _BackgroundScript.Parse(ref log, ref error); _PreviewScript = new WooScript(); _PreviewScript._Program = "rule main {diff=vec("+_Material._DiffuseColour.ToString()+")\r\n" + "spec=vec(" + _Material._SpecularColour.ToString() + ")\r\n" + "refl=vec(" + _Material._Reflectivity.ToString() + ")\r\n" + "emi=vec(" + _Material._EmissiveColour.ToString() + ")\r\n" + "power=" + _Material._SpecularPower.ToString() + "\r\n" + "gloss=" + _Material._Shininess.ToString() + "\r\n" + "sphere}"; _PreviewScript.Parse(ref log, ref error); _LightingScript = new WooScript(); _LightingScript._Program = "rule main {directionalLight(vec(1.0, 1.0, 1.0), vec(-0.7, 1.0, -0.6), 0.02, 1) background(vec(0.0,0.0,0.0))}"; _LightingScript.Parse(ref log, ref error); _Scene = new Scene(_Camera); _Scene.AddRenderObject(_BackgroundScript); _Scene.AddRenderObject(_PreviewScript); _Scene.AddRenderObject(_LightingScript); BuildXML(); _ImageRenderer = new ImageRenderer(image1, _XML, (int)image1.Width, (int)image1.Height, false); _ImageRenderer.Render(); _ImageRenderer.SetPostProcess(new PostProcess()); _ImageRenderer.TransferLatest(false); }
public void Parse(ref string[] program) { string openbrace = ParseUtils.GetToken(ref program); string nexttoken = ParseUtils.PeekToken(program); while (nexttoken != "}") { TokenType type = WooScript.GetTokenType(nexttoken); if (nexttoken.Equals("if", StringComparison.Ordinal)) { IfStatement ifStatement = new IfStatement(); ifStatement.Parse(ref program); _Statements.Add(ifStatement); } else if (nexttoken.Equals("repeat", StringComparison.Ordinal)) { RepeatStatement repeatStatement = new RepeatStatement(); repeatStatement.Parse(ref program); _Statements.Add(repeatStatement); } else if (nexttoken.Equals("{", StringComparison.Ordinal)) { ScopeStatement scopeStatement = new ScopeStatement(); scopeStatement.Parse(ref program); _Statements.Add(scopeStatement); } else if (type == TokenType.rule) { CallStatement callStatement = new CallStatement(); callStatement.Parse(ref program); _Statements.Add(callStatement); } else if (type == TokenType.nullFunction) { NullStatement nullStatement = new NullStatement(); nullStatement.Parse(ref program); _Statements.Add(nullStatement); } else if ((type == TokenType.vecVar) || (type == TokenType.floatVar)) { VarStatement varStatement = new VarStatement(); varStatement.Parse(ref program); _Statements.Add(varStatement); } else { throw new ParseException("Unexpected token \"" + nexttoken + "\" at start of expression"); } nexttoken = ParseUtils.PeekToken(program); } string closebrace = ParseUtils.GetToken(ref program); }
public void Remove() { if (_Type == VarType.varFloat) { WooScript.RemoveFloatVariable(_Name); } else if (_Type == VarType.varVector) { WooScript.RemoveVecVariable(_Name); } }
public void Add() { if (_Type == VarType.varFloat) { WooScript.AddFloatVariable(_Name); } else if (_Type == VarType.varVector) { WooScript.AddVecVariable(_Name); } }
public void Parse(ref string[] program) { _DistanceFunction = ParseUtils.GetToken(ref program); if (WooScript.IsShader(_DistanceFunction)) { _ShaderMode = true; } else { _ShaderMode = false; } }
public void Parse(ref string[] program) { string token = ParseUtils.PeekToken(program); if (token.Equals("(", StringComparison.Ordinal)) { token = ParseUtils.GetToken(ref program); do { Argument arg = new Argument(); token = ParseUtils.GetToken(ref program); if (token.Equals("float", StringComparison.Ordinal)) { arg._Type = VarType.varFloat; } else if (token.Equals("vec", StringComparison.Ordinal)) { arg._Type = VarType.varVector; } else { throw new ParseException("Expected type of parameter (float OR vec), not" + token); } arg._Name = ParseUtils.GetToken(ref program); WooScript.ValidateName(arg._Name); _Arguments.Add(arg); token = ParseUtils.GetToken(ref program); }while (token.Equals(",", StringComparison.Ordinal)); if (!token.Equals(")", StringComparison.Ordinal)) { throw new ParseException("Expected \")\" but found \"" + token + "\" instead. :("); } } foreach (Argument a in _Arguments) { a.Add(); } block.Parse(ref program); foreach (Argument a in _Arguments) { a.Remove(); } }
public HelpWindow() { InitializeComponent(); string helpText; WooScript helpScript = new WooScript(); helpText = helpScript.GetHelpText(); string distanceHelpText; distanceHelpText = ShaderScript.GetHelpText(); helpText += System.Environment.NewLine + "Shader Functions : " + System.Environment.NewLine + distanceHelpText; textBox1.Text = helpText; }
public void Parse(ref string[] program) { string token = ParseUtils.GetToken(ref program); if (token.Length > 0) { _MaterialFunction = token; if (!WooScript.IsShader(_MaterialFunction)) { throw new ParseException("materialfunction call expected a shader, sadly " + _MaterialFunction + " isn't one..."); } } else { _MaterialFunction = ""; } }
public void Parse(ref string[] program) { _Variable = ParseUtils.GetToken(ref program); TokenType tokenType = WooScript.GetTokenType(_Variable); if (tokenType == TokenType.floatVar) { _Type = VarType.varFloat; } else if (tokenType == TokenType.vecVar) { _Type = VarType.varVector; } else { throw new ParseException("Unknown type for variable \"" + _Variable + "\""); } }
public void Parse(ref string[] program) { string token = ParseUtils.GetToken(ref program); WooScript._Log.AddMsg("Found function, target \"" + token + "\""); WooScript._Log.Indent(); if (WooScript.IsFloatVariable(token)) { _ReturnType = VarType.varFloat; _Var = token; } else if (WooScript.IsVecVariable(token)) { _ReturnType = VarType.varVector; _Var = token; } else { throw new ParseException("Expected \"" + token + "\" to be a float or vector variable"); } string assignOp = ParseUtils.GetToken(ref program); _AssignOp = WooScript.GetAssignOp(assignOp); _Expression = ExpressionBuilder.Parse(ref program); if (_ReturnType == VarType.varVector && (_Expression.GetExpressionType() != VarType.varVector)) { throw new ParseException("Target token is \"" + token + "\" which is a vector, expression isn't..."); } if (_ReturnType == VarType.varFloat && (_Expression.GetExpressionType() != VarType.varFloat)) { throw new ParseException("Target token is \"" + token + "\" which is a float, expression isn't..."); } }
public void Parse(ref string[] program) { string token = ParseUtils.GetToken(ref program); WooScript._Log.AddMsg("Found \"" + token + "\" function (null return)"); WooScript._Log.Indent(); _NullFunction = WooScript.GetNullFunction(token); string openCurl = ParseUtils.GetToken(ref program); if (!openCurl.Equals("(", StringComparison.Ordinal)) { new ParseException("Expected \"(\" not \"" + openCurl + "\""); } _NullFunction.Parse(ref program); string closeCurl = ParseUtils.GetToken(ref program); if (!closeCurl.Equals(")", StringComparison.Ordinal)) { new ParseException("Expected \")\" not \"" + closeCurl + "\""); } WooScript._Log.UnIndent(); }
public void Parse(ref string[] program) { string ruleName = ParseUtils.GetToken(ref program); _RulePrototype = WooScript.GetRulePrototype(ruleName); WooScript._Log.AddMsg("Call Rule : " + ruleName); string openbracket = ParseUtils.PeekToken(program); if (openbracket.Equals("(", StringComparison.Ordinal) || _RulePrototype._Args.Count() > 0) { openbracket = ParseUtils.GetToken(ref program); if (!openbracket.Equals("(", StringComparison.Ordinal)) { throw new ParseException("rule called without required arguments, or syntax error. Found " + openbracket + ", expeceted \"(\" instead."); } for (int i = 0; i < _RulePrototype._Args.Count(); i++) { _ArgValue.Add(ExpressionBuilder.Parse(ref program)); if (i + 1 < _RulePrototype._Args.Count()) { string comma = ParseUtils.GetToken(ref program); if (!comma.Equals(",", StringComparison.Ordinal)) { throw new ParseException("Found " + comma + " but expected another argument after a \",\""); } } } string closebracket = ParseUtils.GetToken(ref program); if (!closebracket.Equals(")", StringComparison.Ordinal)) { throw new ParseException("rules not currently supported with arguments, missing ), found " + closebracket + " instead."); } } }
public static ConditionalExpression Parse(ref string[] program) { ConditionalExpression ret = null; Expression expr = null; string token1 = ParseUtils.PeekToken(program); TokenType type1 = WooScript.GetTokenType(token1); if (token1.Equals("(", StringComparison.Ordinal)) { ret = new ConditionalBrackets(); (ret as ConditionalBrackets).Parse(ref program); } else if (type1 == TokenType.UnaryBooleanOp) { ret = WooScript.GetUnaryBooleanOp(token1); (ret as UnaryBooleanOp).Parse(ref program); } else if (type1 == TokenType.floatVar || type1 == TokenType.floatNum || type1 == TokenType.floatFunction) { expr = ExpressionBuilder.Parse(ref program); } else { throw new ParseException("Unrecognised expression \"" + token1 + "\""); } string token2 = ParseUtils.GetToken(ref program); TokenType type2 = WooScript.GetTokenType(token2); if (type2 == TokenType.ConditionalOp) { if (type1 != TokenType.floatNum && type1 != TokenType.floatVar && type1 != TokenType.floatFunction) { throw new ParseException("Conditional operation only takes floating point parameters"); } ConditionalOp condOp = WooScript.GetConditionalOp(token2); condOp._Arg1 = expr; Expression arg2 = ExpressionBuilder.Parse(ref program); if (arg2.GetExpressionType() != VarType.varFloat) { throw new ParseException("Conditional operation only takes floating point parameters"); } condOp._Arg2 = arg2; // no need for precedence check on conditional operator ret = condOp; string token3 = ParseUtils.PeekToken(program); TokenType type3 = WooScript.GetTokenType(token3); if (type3 == TokenType.BooleanOp) { BooleanOp boolOp = WooScript.GetBooleanOp(token3); boolOp._Arg1 = condOp; ConditionalExpression condArg2 = ConditionBuilder.Parse(ref program); boolOp._Arg2 = condArg2; // operator precedence check if (condArg2 is BooleanOp) { if ((condArg2 as BooleanOp).GetPrecedence() < boolOp.GetPrecedence()) { // shuffle args boolOp._Arg2 = (condArg2 as BooleanOp)._Arg1; (condArg2 as BooleanOp)._Arg1 = boolOp; boolOp = (condArg2 as BooleanOp); } } ret = boolOp; } } if (ret == null) { throw new ParseException("Malformed conditional expression, expected conditional operation"); } return(ret); }
private bool CompileSingle(ref WooScript script) { string log = ""; string error = ""; bool success = script.Parse(ref log, ref error); if (!success) { MessageBox.Show(error); return false; } return true; }
public void Parse(ref string[] program) { string op = ParseUtils.GetToken(ref program); _Op = WooScript.GetOp(op); }
public static Expression Parse(ref string[] program) { Expression ret; string token1 = ParseUtils.PeekToken(program); TokenType type1 = WooScript.GetTokenType(token1); if (token1.Equals("(", StringComparison.Ordinal)) { ret = new Brackets(); ret.Parse(ref program); } else if (type1 == TokenType.floatNum) { ret = new FloatNumber(); ret.Parse(ref program); } else if (type1 == TokenType.floatVar || type1 == TokenType.vecVar) { ret = new Variable(); ret.Parse(ref program); } else if (type1 == TokenType.vecFunction) { ret = new VecFunctionExpr(); ret.Parse(ref program); } else if (type1 == TokenType.floatFunction) { ret = new FloatFunctionExpr(); ret.Parse(ref program); } else if (type1 == TokenType.Op) { //deal with -8 type numbers ret = new FloatNumber(); ret.Parse(ref program); } else { throw new ParseException("Unrecognised expression \"" + token1 + "\""); } /* if (type1 == TokenType.floatFunction) * { * ret = new FloatFunction(); * ret.Parse(ref program); * } */ string token2 = ParseUtils.PeekToken(program); TokenType type2 = WooScript.GetTokenType(token2); if (type2 == TokenType.Op) { FloatOperation flop = new FloatOperation(); flop.Parse(ref program); flop._Argument1 = ret; Expression arg2 = ExpressionBuilder.Parse(ref program); flop._Argument2 = arg2; // operator precedence check if (arg2 is FloatOperation) { if ((arg2 as FloatOperation).GetPrecedence() < flop.GetPrecedence()) { // shuffle args flop._Argument2 = (arg2 as FloatOperation)._Argument1; (arg2 as FloatOperation)._Argument1 = flop; flop = (arg2 as FloatOperation); } } if (flop._Argument1.GetExpressionType() != flop._Argument2.GetExpressionType()) { throw new ParseException("Mismatch argument types on operation"); } ret = flop; } return(ret); }
public void InitialiseScript() { _BackgroundScript = new WooScript(); _SceneScript = new WooScript(); _LightingScript = new WooScript(); _BackgroundScript.Load("background", "scratch"); _SceneScript.Load("scene", "scratch"); _LightingScript.Load("lighting", "scratch"); _BackgroundScript._Program = "rule main {\r\npos.y -= 0\r\ndiff = vec(1.0, 1.0, 1.0)\r\nrefl = vec(0.4, 0.4, 0.4)\r\ngloss = 0.97\r\nscale = vec(460, 460, 460)\r\npos.y-=1\r\ncylinder\r\n}"; _SceneScript._Program = "rule main {box}"; _LightingScript._Program = "rule main {directionalLight(vec(1.0, 1.0, 1.0), vec(-0.7, 1.0, -0.6), 0.02, 1) \r\n background(vec(0.8,0.8,0.8))}"; LoadFractal("scratch"); // backgroundDesc.Text = _BackgroundScript._Program; // sceneDesc.Text = _SceneScript._Program; // lightingDesc.Text = _LightingScript._Program; }
public static string GetToken(ref string[] lines) { char[] whitespace = new char[] { ' ' }; char[] specialChars = new char[] { ',', '(', ')', '{', '}' }; char[] opChars = new char[] { '/', '*', '<', '>', '|', '&', '-', '+', '=' }; do { if (lines[0].Length == 0 || lines[0].IndexOf("//") == 0) { lines = lines.Where((val, idx) => idx != 0).ToArray(); if (lines.Length == 0) { return(""); } } lines[0] = lines[0].TrimStart(whitespace); }while (lines[0].Length == 0 || lines[0].IndexOf("//") == 0); string token; int tokenEnd = lines[0].IndexOfAny(whitespace); int tokenSpecial = lines[0].IndexOfAny(specialChars); int tokenOp = lines[0].IndexOfAny(opChars); if (tokenEnd == -1) { tokenEnd = lines[0].Length; } if (tokenSpecial == -1) { tokenSpecial = lines[0].Length; } if (tokenOp == -1) { tokenOp = lines[0].Length; } int tokenquote = lines[0].IndexOf("\""); if (tokenquote == 0) { tokenEnd = 1 + lines[0].IndexOf("\"", 1); } else { if (tokenSpecial == 0) { tokenEnd = 1; } else if (tokenOp == 0) { int length = 0; for (int i = 0; i < WooScript.GetNumOps(); i++) { string opName = WooScript.GetOp(i); if (lines[0].IndexOf(opName) == 0) { if (opName.Length > length) { length = opName.Length; } } } if (lines[0].IndexOf("<") == 0 || lines[0].IndexOf(">") == 0 || lines[0].IndexOf("&") == 0 || lines[0].IndexOf("|") == 0) { length = 1; } if (lines[0].IndexOf("!=") == 0) { length = 2; } // nah tokenEnd = length; } else { if (tokenSpecial < tokenEnd) { tokenEnd = tokenSpecial; } if (tokenOp < tokenEnd) { tokenEnd = tokenOp; } } } if (tokenEnd == lines[0].Length) { token = lines[0]; lines[0] = ""; } else { token = lines[0].Substring(0, tokenEnd); lines[0] = lines[0].Substring(tokenEnd); } if (tokenquote == 0) { token = token.Substring(1, token.Length - 2); } return(token); }