|
Post by linuxdeveloper on Feb 1, 2021 8:54:31 GMT
Hello,
Correct me if I'm wrong, but I don't see anything in the text which explains or specifies how to write the YAML parser. Am I missing this in the text, or is this left as an exercise for the reader?
As having the YAML parser seems extremely useful, I would like to write one. Does anyone have any tips/tricks or suggestions for getting started? I am using Python.
Thanks!
|
|
|
Post by jdunlap on Feb 3, 2021 1:53:06 GMT
This has been an ongoing process for me. Jamis has not provided any specification for the format. It also seems that maybe he has disappeared from this site as he last posted here several months ago... What I have done is to base my parser on the examples that I have found on this site and the one in the book. Implement the parts that you have done in your raytracer and add to the parser as you add to the raytracer. You are correct, though, that it is much easier since you do not have to hand-create code to make a scene for each part. Just grab or write a YAML and render from that to see the results of your work!
Sorry that I can't give any specifics for Python as it's not a language that I know well. One universal recommendation, though, would be to look for a YAML parsing library for your implementation language. The parse is the ugliest part of my code as it is full of special cases, likely because no specification exists and I am just making it work.
|
|
|
Post by jdunlap on Feb 3, 2021 2:39:06 GMT
Oh, and I might add that the YAML format is sometimes very frustrating. For example, when creating patterns, colors are listed as a list of vectors UNLESS you are creating the align check pattern in the texture bonus chapter, and then it is a dictionary of vectors. For strongly-typed languages like C# this is a pain and requires several "special" pieces of code to handle that one case.
|
|
|
Post by inventordave on Feb 10, 2021 23:15:33 GMT
This should tell you to manually write a YAML parser. I have no YAML parser, but I hope to be bothered at some point to write one. I am studying the dragon book, so at some point I'll hopefully write a beast of a parser. Feel free to check out my web-based raytracer at www.inventordave.com/rt-dt/raytracer.html it's pretty great, but wait for the pre-loaded resources to load... There is a nightmare of a bug that you wouldn't notice unless you're observant, but the Pattern class's .algorithm() fires repeatedly for many iterations long after the render has finished (open the web console to see the diagnostic msg that loops *for ages* after the render has finished - oh, very weird, wow, wow, wow, wow!!) (try "Earth", or "Earth & Moon", or "Cube" from the drop-down menu of pre-configured scenes, and watch the output in the browser's console - sometimes, and I don't understand why, the bug does not reproduce, sometimes it does...) EDIT: The bug does not reproduce in Firefox, but it does in Chrome... EDIT2: Yep, the bug reproduces in Chrome, but not in Firefox, must be a v8 bug...
|
|
|
Post by jaredp on Feb 11, 2021 18:46:37 GMT
This is one of the things left to the reader. From what I understand, Jamis didn't want to lock the implementation into a particular format. I think I mostly agree with his decision: file parsing can vary widely depending on your language and libraries, and it's really outside the scope of a book that's designed to teach you about computer graphics. That said, a lot of the book hints at a particular way of structuring a configuration file (especially with Groups and CSG) and using a recursive parsing method. The sample YAML in the appendix also hints at how you might provide templates for materials and shapes. I think there was a post on here in which Jamis mentioned his plans to release a YAML spec, and if he ever releases a 2nd edition of the book, I hope this is one of the things he adds. Even some pseudocode for a parser would be helpful.
I've managed to write a parser using yaml-cpp that's compatible with the sample YAML files in the book and bonus chapters, but it's kind of a mess at this point. If you're just starting the book, make sure to read ahead to the chapter on Groups and Triangles and design your parser with an emphasis on recursion and reusable functions.
|
|
|
Post by Jamis on Mar 3, 2021 2:13:05 GMT
Hey all, sorry I've been awol forever...been a bit crazy!
As for the YAML format, yeah... I never intended for it to be a formal part of the book. I selected it because it was fairly self-documenting, and someone could (hopefully!) look at a YAML scene description and understand how to translate that into whatever implementation they preferred.
Many languages have YAML parsers available. Ruby, for instance, has an excellent YAML parser. Python has at least one as well. Before implementing a full YAML parser (which could be a tall order), look and see if there's one already available for your language. That's another reason I selected YAML: it's fairly well-supported in a lot of languages.
Ultimately, though, I never really intended for the YAML files to become formal specifications. That was short-sighted of me, and I apologize. If there's ever another edition of my book, I'll consider adding an appendix that better describes how I'm using the format.
|
|