AR-js-org / AR.js

Image tracking, Location Based AR, Marker tracking. All on the Web.
MIT License
5.41k stars 924 forks source link

TypeScript version of the library and modularity #509

Open kalwalt opened 1 year ago

kalwalt commented 1 year ago

Typescript conversion or simply type definitions?

Adding modularity to AR.js

We converted AR.js to ES6 and we have a npm package that can be imported in many projects and frameworks, but if you need to import into a Typescript project it became hard and you enter into a lot of troubles. I thought to add type definitions, it's possible witing the documentation in JSDoc to the actual code and transpiling to Typescript. I'm doing this in #506 but i realized that we need also to convert the entire code to real ES6 standard. But why not convert directly to Typescript? If we do so, we can add also more modularity to the project, I already started this task - you can see in this repository ~AR.js-threex~ (see my comment in POST EDIT). I named it AR.js-threex but maybe we can find a more appropriate name, Initially i thought that we should develop two separate package (as the "namespaces": ARjs and THREEx) But maybe this can add a complexity that we don't need. Probably a better name will be AR.js-threejs (as the name of the folder in AR.js) but if you have a better idea let me know. I plan to move AR.js-threex (or with the new name) in few days to the AR.js org and when it will be possible also release a first npm pacakge for testing. POST EDIT: Now i renamed it as AR.js-threejs

Project design

Convert all the existent three.js classes ( i mean code in the AR.js three.js folder) to a Typesctipt version. For a list of created classes:

THREEx:

ARjs:

new-api:

markers-area:

Final conclusion

The idea is when it will be ready also to import it as a npm module into AR.js itself and remove the threejs folder as it will be unecessary. I can not say when this will became a reality but i hope that we can do in a short time. If you have experience with Typescript any help and collaboration is appreciated! I don't know what think @nickw1 and @nicolocarpignoli about this but i hope that they can help in some way. I will update this issue with the progresses in this task and, time permitting, i will aslo try to describe the plan for converting the code. I know also that not all developers know or love Typescript, but the final distribution library is javascript code and you will be able to use as before. I hope that you will understand this.

RobvandenBerg commented 1 year ago

I would say it's fine as long as there's always easy access to the final distribution in plain JS.

kalwalt commented 1 year ago

I would say it's fine as long as there's always easy access to the final distribution in plain JS.

Yes absolutely there will be always a plain JS distribution at the end. Thanks @RobvandenBerg for the feedback!

nickw1 commented 1 year ago

I agree with @RobvandenBerg.

kalwalt commented 1 year ago

I agree with @RobvandenBerg.

What your experience and knowledge with Typescript @nickw1 ?

kalwalt commented 1 year ago

I think AR.js-threex should be renamed as AR.js-threejs because it collect all the code inside the threejs folder. I'm going to rename it, i think the actual name can be confusing, it suppose to contain only the THREEx namespace but it's not; with my recent changes in the code i added both namesapces ARjs and THREEx to the project. I have not created all the classes, this will be done in a future. I will also move the repository to the AR-js-org, so everybody can partecipate and collaborate.

nickw1 commented 1 year ago

@kalwalt not extensive I will admit, but I was agreeing that a plain JS distribution sounds like a good idea because it is (perhaps) less likely to produce unexpected problems and maintain compatibility with existing code.

kalwalt commented 1 year ago

@kalwalt not extensive I will admit, but I was agreeing that a plain JS distribution sounds like a good idea because it is (perhaps) less likely to produce unexpected problems and maintain compatibility with existing code.

@nickw1 for location-base code we can also leave plain js code, it should be possible to bundle Typescript and Javascript code toghether with the allowJs option; i will not force you to code in Typescript or other language 🙂. I will create also another repository, for testing purposes, let say AR.js-core and make the same code instead with ES6 with pure vanilla JS.

commentatorboy commented 4 months ago

Hey guys.

I have currently been very busy with my work, so I did not have the time to help out here. But I will take a look at the AR.js-threejs repo you made.

kalwalt commented 4 months ago

Hey guys.

I have currently been very busy with my work, so I did not have the time to help out here. But I will take a look at the AR.js-threejs repo you made.

No problem @commentatorboy you are welcome!