I want to display math symbols (equations, matrices, etc.) in order to teach math so that learners can see math derivations and live results. Babylon.js doesn’t seem to have a loader to load MathML. So, I try to use SVG symbols, which are produced with tools such as MathJax. But, SVG is used in Babylon.js only as a texture, isn’t it? If so, that won’t be flexible enough to make a math learning animation.
I went to our good neighbor three.js to try its SVG loader. Unfortunately, however, it does not fully support SVG, leaving out tags such as “defs”.
The Chinese characters were extracted from normal font files but the anchors were taken from SVG. They were both put in a font family, “Web-dings”. (Alas, turning SVG into letters is not automated.)
Also, I was unsure of what output you wanted. Your comment about textures not being flexible enough confused me a little. It might help to be able to visualize your target layout.
hi, if you want to rotate/scale/translate math symbols as a 3D object in BJS scene, you can draw svg on canvas( ctx.drawImage(image, 0, 0) ), then use it as a texutre( gl.readPixels() or canvas.toDataURL() ), and update it as you need.
There is a general-purpose way to put an image into a texture. SVG “images” work great for that. I have done it many times. So in your application, the SVG could be put on a rectangular mesh and placed anywhere in the scene. https://www.babylonjs-playground.com/#NT70VN#2
In that example, I turned your equation SVG into a dataurl and created a mesh with the same proportions as the SVG. That’s option 2.
Option 1 is harder. I have been interested in that for a long time but I suspect that is not what you want.
Meshes are first-class citizens in 3D. You can move them, size them, rotate them, light them and animate them. With the appropriate material, you will probably get what you want.
I got a tool that might help you for displaying latex math string as mesh.
you will most likely find bugs here and there. But simple usage should be ok?
example usage:
import {mathmesh} from "mathmesh";
var verts = mathmesh("\\int_{a}^{b}x^2 \\,dx");
let customMesh = new Mesh("mymathmesh", scene);
let vertexData = new VertexData();
vertexData.positions = verts.positions;
vertexData.indices = verts.indices;
vertexData.applyToMesh(customMesh);
let fontmaterial = new StandardMaterial("mathmeshMat", scene);
fontmaterial.backFaceCulling = false;
fontmaterial.emissiveColor = new Color3(0, 1, 0);
customMesh.material = fontmaterial;
Hi, thanks for the support :), but I think mathmesh is farrrrrr from being used in production. It still has a lotttttt of things to be improved/fixed. I shared it just so in case someone need some basic latex math display.