2

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?

Toast
  • 128
  • 4
  • 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
  • @Toast I think you are missing my point. Build the data set as a 3d model any way you like, but use something like Three.js to present a 3D model on the browser. Thus keep the 3D calc in the "Model" layer (see what I did there!) and pass that data onto a separate presentation layer in the browser. – Peter M Feb 19 '19 at 19:56
  • @PeterM I don't understand how that solves the problem. I still need to pick a programming language for the model layer / mesh generator. – Toast Feb 19 '19 at 22:06
  • There are C# libraries for creating html. It's plausible unity has that as a feature somewhere – Caleth Feb 19 '19 at 22:58
  • @Caleth Where would the C# code that creates the HTML run? – Toast Feb 19 '19 at 23:00
  • The same place where the C# that creates the meshes runs. – Caleth Feb 19 '19 at 23:01
  • And that is where? – Toast Feb 19 '19 at 23:02
  • @Toast The point is that you are free to choose the language that best supports what you want to do. A language that better supports overloading for your 3D math to build the meshes and a different language to display the meshes in the browser. Thus making your entire issue moot. – Peter M Feb 19 '19 at 23:18
  • But I'm limited by the programming languages that a browser can run. C# is not one of them. – Toast Feb 19 '19 at 23:19
  • 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
  • I want to make a website where you press a button and a 3D mesh appears. I prototyped the mesh generation part in Unity to see if the logic works. It doesn't use any Unity features beyond that. Now since it should run inside a website, I planned to reimplement it in Typescript or Javascript, together with a polished HTML user interface. I'm looking for a way around the lack of operator overloading in these langauges. – Toast Feb 19 '19 at 23:36
  • @Toast You are confusing us by saying that you want to "make a website" while at the same time saying "without a server". Most people here would assume that a website is run from a server. – Peter M Feb 20 '19 at 00:45
  • @PeterM Sorry for the confusion, I tried to clarify my question even further. I would like to make a web application where all computation happens on the client, the server only serves static files. It will be hosted on a service like github.io. – Toast Feb 20 '19 at 00:57

1 Answers1

7

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.

Caleth
  • 10,519
  • 2
  • 23
  • 35