A first pass at translating .STP files to manim
You know what, today we are going to look at how to represent CAD models in Manim.
You know what, today we are going to look at how to represent CAD models in Manim. The thought is that we take something off of GrabCAD at a specified format, convert it to a point cloud, then make it a mesh by using a hull process(?).
Scratch that, what I'll try to do is create a parser using a python library called Lark for .stp files and transform it into manim objects. This should be an interesting project. Lark only takes in a particular description of code called EBNF. The .STP format is specified in a somewhat different form called WSN. From the look of things I should be able to use Kate's Grammar Tool on github [1], to convert between the two without any problems. This is what I've got so far after applying Kate's Grammar Tool and cleaning the BNF up to be EBNF manually:
SPACE : " "
DIGIT : "0"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
LOWER : "a"
| "b"
| "c"
| "d"
| "e"
| "f"
| "d"
| "e"
| "f"
| "g"
| "h"
| "i"
| "j"
| "k"
| "l"
| "m"
| "n"
| "o"
| "p"
| "q"
| "r"
| "s"
| "t"
| "u"
| "v"
| "w"
| "x"
| "y"
| "z"
UPPER : "A"
| "B"
| "C"
| "D"
| "E"
| "F"
| "D"
| "E"
| "F"
| "G"
| "H"
| "I"
| "J"
| "K"
| "L"
| "M"
| "N"
| "O"
| "P"
| "Q"
| "R"
| "S"
| "T"
| "U"
| "V"
| "W"
| "X"
| "Y"
| "Z"
SPECIAL : "!"
| "\" \""
| "*"
| "$"
| "%"
| "&"
| "."
| "#"
| "+"
| ","
| "-"
| "("
| ")"
| "?"
| "/"
| ":"
| ";"
| "<"
| "="
| ">"
| "@"
| "["
| "]"
| "{"
| "|"
| "}"
| "^"
| "`"
REVERSE_SOLIDUS : "\\"
APOSTROPHE : "'"
CHARACTER : SPACE
| DIGIT
| LOWER
| UPPER
| SPECIAL
| REVERSE_SOLIDUS
| APOSTROPHE
KEYWORD : USER_DEFINED_KEYWORD
| STANDARD_KEYWORD
USER_DEFINED_KEYWORD : "!" UPPER
STANDARD_KEYWORD : UPPER
SIGN : "+"
| "-"
INTEGER : DIGIT
REAL : DIGIT "."
NON_Q_CHAR : SPECIAL
| DIGIT
| SPACE
| LOWER
| UPPER
STRING : "'" "'"
ENTITY_INSTANCE_NAME : "#" DIGIT
ENUMERATION : "." UPPER "."
HEX : "0"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "A"
| "B"
| "C"
| "D"
| "E"
| "F"
BINARY : "" "" "" ""
From there I should be able to pass it through to Lark, pass the text I want to parse, and potentially translate it to manim. I thought I could get away with it being a day long project, but I was wrong. I'm going to have to leave it and come back to it with a renewed set of eyes. Also, for the python file this is what I have:
from lark import Lark
def load_grammar(file_path: str) -> Lark:
with open(file_path, 'r', encoding='utf-8') as file:
grammar = file.read()
return Lark(grammar, parser='lalr')
print(load_grammar("./step.ebnf"))
See ya'll next time, and let's see if I continue this one.
[1] https://github.com/katef/kgt