1

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?

16
  • 1
    This 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
    Feb 19 '19 at 12:13
  • 1
    Why do you feel you need to rewrite your application in a different language in order to present data in a browser?
    – Peter M
    Feb 19 '19 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
    Feb 19 '19 at 19:17
  • 1
    @Toast Or if you really want to punish you can compile your c# to webassembly
    – Peter M
    Feb 19 '19 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
    Feb 19 '19 at 23:25
8

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.

4
  • 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
    Feb 19 '19 at 19:19
  • @Toast C# is fine for generating html.
    – Caleth
    Feb 19 '19 at 22:59
  • Webbrowsers can't run C#.
    – Toast
    Feb 19 '19 at 23:06
  • 1
    Soon you'll be able to compile C# to wasm, then the browser can run that.
    – Turksarama
    Feb 20 '19 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.