I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm wondering what a good framework / language is for the task.
The problem: I would like to use Typescript or Javascript, but neither support operator overloading.
A line like this in C#
a = Vector3.forward * 3 + direction * length * 0.5;
would look horrible without operator overloading:
a = Vector3.forward.times(3).add(direction.times(length * 0.5));
What is the most elegant solution to this?
-
1This question is in no way special to web development, so I took the freedom to remove that distracting noise from the title and and the tags.Doc Brown– Doc Brown2019年02月19日 12:13:44 +00:00Commented Feb 19, 2019 at 12:13
-
1Why do you feel you need to rewrite your application in a different language in order to present data in a browser?Peter M– Peter M2019年02月19日 13:05:33 +00:00Commented Feb 19, 2019 at 13:05
-
@PeterM I would like to generate and present the data inside a website, wihtout a server. I updated the question to be more specific. I know that you can transpile C# to Javascript, but that creates a lot of overhead.Toast– Toast2019年02月19日 19:17:03 +00:00Commented Feb 19, 2019 at 19:17
-
1@Toast Or if you really want to punish you can compile your c# to webassemblyPeter M– Peter M2019年02月19日 23:19:46 +00:00Commented Feb 19, 2019 at 23:19
-
2@Toast I don't think I understand what you are trying to do. Are you saying that you have built a 3D scene in Unity and now you need to replicate that scene in a stand alone file that can be loaded by a browser? Or do you want to cast your existing Unity program into a browser?Peter M– Peter M2019年02月19日 23:25:26 +00:00Commented Feb 19, 2019 at 23:25
1 Answer 1
You either pick a language that allows the syntax you want, or write it out longhand and accept that it "look[s] horrible".
For vector arithmetic, there are at least 3 different operations that are reasonably denoted by *
(or times
or product
), and you'd have to have a language that takes return types into account to disambiguate all of them. It's then not such a burden to have to name scale
, dot product
and cross product
.
As a note, it's likely there are existing linear algebra libraries in all the languages that you could use. Don't try to write one yourself unless you really can't find one.
-
Could you name an example of a language that offers operator overloading and works well on a webpage? For me it's sufficient if the
*
operator only works for scaling, not the dot product or cross product.Toast– Toast2019年02月19日 19:19:40 +00:00Commented Feb 19, 2019 at 19:19 -
@Toast C# is fine for generating html.Caleth– Caleth2019年02月19日 22:59:54 +00:00Commented Feb 19, 2019 at 22:59
-
-
1Soon you'll be able to compile C# to wasm, then the browser can run that.Turksarama– Turksarama2019年02月20日 00:57:26 +00:00Commented Feb 20, 2019 at 0:57