ricaun / dotbim.three.js

Convert dotbim file to three.js object
https://htmlpreview.github.io/?https://github.com/ricaun/dotbim.three.js/blob/master/index.html
MIT License
7 stars 4 forks source link

The size of the library #1

Closed GitHubDragonFly closed 1 year ago

GitHubDragonFly commented 1 year ago

This is not an issue and is more of an FYI in regards to the size of the dotbim.three.js file, which is currently around 1.4MB.

I have managed to modify and reduce its size to around 4KB and it still shows as functional.

It is currently being used in my STEP Viewer and the code is available in my repository.

This topic can be closed at any time.

ricaun commented 1 year ago

Neat, I never noticed that the file is enormous. I believe has some json/bim files that I used to test when I was messing with the code.

You could create a Pull Request to change to the smaller version. 😊

GitHubDragonFly commented 1 year ago

The PR has been filed.

I have also updated README.md file with Usage section that has my example (this is all optional).

ricaun commented 1 year ago

Looks great!

GitHubDragonFly commented 1 year ago

Cool.

There is only 1 other thing to let you know about, which is the example face.bim model that you have in this repository.

There is something wrong with this model since my viewer could not show it and the Online 3D Viewer was throwing an error in the console (maybe try it yourself just so you can see the error).

I did test lots of examples from https://github.com/paireks/dotbim/tree/master/test/ExampleFiles and they worked fine.

ricaun commented 1 year ago

Ohh, Yes looks like the face.bim is using my proposal for schema 1.1.0, which was not approved...

Now to set the color of a face the file need to have a face_colors, I tried to move the color to the mesh instead of the element, which makes more sense in my mind.

paireks commented 1 year ago

Hey guys! I did a test using the @GitHubDragonFly viewer, and only had issues with this example: https://github.com/paireks/dotbim/blob/master/test/ExampleFiles/TestFilesFromC%23/CubesWithFaceColorsAndWithout.bim

image

Plus I'm really happy there is a discussion going on! :)

GitHubDragonFly commented 1 year ago

If the following picture represents correct colors then it is a combination of the Opacity and Vertex Colors in my viewer that is causing this. Simply turning these 2 features ON and OFF produced these colors (which might not be correct).

I did a test in the Online 3D Viewer as well and it shows the model slightly different so I am not sure what is correct.

For now, just assume that it is my viewer that's at fault.

BIM Test

GitHubDragonFly commented 1 year ago

It seems to be the Opacity feature that's not handling properly the Alpha values of each cube's color. Transparency is either turned ON or OFF with this feature which is a bit tricky.

Not really sure if that is fixable in my viewer but I might take a look at the code.

GitHubDragonFly commented 1 year ago

I did add transparency handling to the viewer and also added 1 line of code to the dotbim (with PR submitted).

It all seems to be working besides for the MulticolorHouse.bim file which does not show colors and I don't really know why that is. This file shows as schema 1.1.0 while other ones seem to be 1.0.0. Not really sure if that has to do anything with colors. Online 3D Viewer does show it properly.

paireks commented 1 year ago

Maybe the issue is due to dotbim.three.js library difference, which is what Luiz mentioned (putting face_colors inside elements instead of meshes).

Generally in 1.1.0 we've added only one thing: possibility to color each face (triangle) separately. It is mentioned here: https://github.com/paireks/dotbim#color-and-face_colors, because at 1.0.0 there was only 1 color per element.

Both Luiz and Viktor encouraged me to add this. Motivation was to make it much simpler for elements such as doors / windows - elements that have most of the time more than 1 color already. So with face_colors attached to element you can overwrite the color to specify color for every triangle :)

GitHubDragonFly commented 1 year ago

Thanks for the explanation.

I did find out that this particular MulticolorHouse.bim model is actually using vertex colors.

The detection of vertex colors in my viewer was not present so I added it.

Now it all seems to be working properly but feel free to do tests on your own and let me know if you find anything else.

GitHubDragonFly commented 1 year ago

Just found another file that does not show properly in my viewer: TrianglePlate.bim

Online 3D Viewer shows it fine.

Will try to figure out why this is happening.

paireks commented 1 year ago

Transparency looks good! But something with face_colors is missing, as I'm comparing middle cube of theCubesWithFaceColorsAndWithout.bim file. It still takes a green color from an element, but should take face_colors applied :)

image

ricaun commented 1 year ago

I updated and looks like this:

image

ricaun commented 1 year ago

I update the index.html in this repo with drag-and-drop, just move some bim file and should work I guess.

paireks commented 1 year ago

It works like a charm now :) It is also really fast with loading :)

GitHubDragonFly commented 1 year ago

@ricaun just so you are aware, the GitHub & BitBucket HTML Preview actually allows your index.html to show a page where BIM models can be dropped and seen.

This would be the link: https://htmlpreview.github.io/?https://github.com/ricaun/dotbim.three.js/blob/master/index.html

It does not show your built-in model and you could try adding an alert to your <body> tag to let visitors know that they can drop BIM files onto the page, similar to this: <body onload="alert( 'Drop your BIM files here...' );">

ricaun commented 1 year ago

@ricaun just so you are aware, the GitHub & BitBucket HTML Preview actually allows your index.html to show a page where BIM models can be dropped and seen.

Interesting, never use that, that's odd that the default model is not loaded...

GitHubDragonFly commented 1 year ago

GitHub & BitBucket HTML Preview is limited to what it can do.

You could also activate the website page in your repository for free, just like my main webpage is, but first do a research on the internet. I would personally stick with the GitHub & BitBucket HTML Preview since your repository is somewhat simple.

Do whatever you want with that PR that you moved to the develop branch. One more update you could consider would be related to the keyboard keys since in the Firefox browser they might require CTRL button, so it would be CTRL + 1 or CTRL + c.

ricaun commented 1 year ago

Yes activate the website page was my next step just to have some online preview.

GitHub & BitBucket HTML Preview works great! I onload was not triggering and I added a simple text in de view.

https://htmlpreview.github.io/?https://github.com/ricaun/dotbim.three.js/blob/master/index.html

ricaun commented 1 year ago

Do whatever you want with that PR that you moved to the develop branch. One more update you could consider would be related to the keyboard keys since in the Firefox browser they might require CTRL button, so it would be CTRL + 1 or CTRL + c.

The keyboard is just for testing, in my Firefox works fine. 😀

GitHubDragonFly commented 1 year ago

Your page looks neat now.

Firefox browser has a setting 'Search for text when you start typing' which when enabled will intercept the keyboard presses before the page can do it. That's the reason why I mentioned that CTRL might need to be used.

GitHubDragonFly commented 1 year ago

There is a few more things you can do in an attempt to gain more traffic to your repository:

These are only suggestions.

ricaun commented 1 year ago

Thanks, I really appreciate your suggestion and help in this project.

GitHubDragonFly commented 1 year ago

You are welcome.

This is probably going to be my last suggestion - maybe add a screenshot to your repository, similar to the attached picture below, and update your README.md file to look like the following:

Here is an [Online Preview](https://htmlpreview.github.io/?https://github.com/ricaun/dotbim.three.js/blob/master/index.html) page where you can drop your BIM file. See the `Example` section below for additional info.

Screenshot
![Online Preview](./dotbim.png?raw=true)

dotbim

GitHubDragonFly commented 1 year ago

@ricaun color is off for this particular example: https://github.com/Gorgious56/dotbim_io_dxf/tree/master/test

Maybe update the last function to this:

function convertTHREEColorRGB(r,g,b)
{
    return new THREE.Color(r/255.0, g/255.0, b/255.0);
}
ricaun commented 1 year ago

The file color is wrong. The color should be an integer between 0-255.

And your approach is better, gonna update 😁

image

https://htmlpreview.github.io/?https://github.com/ricaun/dotbim.three.js/blob/develop/index.html

paireks commented 1 year ago

Hey guys, I'd love to post about it on three.js forum as @GitHubDragonFly suggested if you don't mind ;) Maybe someone will find it interesting there :)

GitHubDragonFly commented 1 year ago

It would probably help increase the traffic by posting it wherever you can including three.js forum.

The ultimate decision is with @ricaun since this is his repository.

ricaun commented 1 year ago

If you would like to share in the three.js forum I don't mind. 😛

paireks commented 1 year ago

https://discourse.threejs.org/t/dotbim-three-js/55323 :)

paireks commented 1 year ago

Pavel has responded there with some tips as well :) - https://discourse.threejs.org/t/dotbim-three-js/55323/2

GitHubDragonFly commented 1 year ago

@ricaun check the attached BIM Loaders for three.js, which I currently have in my repository.

Three.js project only uses modules these days so maybe try to submit the module version as it is or modify it to your liking. Don't get surprised if they reject it or maybe ask you to change something before they accept it officially.

I did move edges to the userData and made slight changes to the code.

BIM Loader.zip

You can use this repository for testing just follow the instructions as they are listed for python.

GitHubDragonFly commented 1 year ago

@ricaun and @paireks , if you might be interested in an interesting experiment then try loading the attached modified file in my mobile STEP Viewer.

It takes approximately 5 seconds to load it and it also has some color. Changed info section on the bottom of the file is what makes it work with newly modified code in my repository.

Teapots1000.zip

paireks commented 1 year ago

@GitHubDragonFly Wow! On my computer it opened in maybe 2 seconds while the current version takes +10 seconds!

GitHubDragonFly commented 1 year ago

That mobile viewer is stripped down to almost basic functionality so it doesn't have a burden of loading too many scripts and HTML controls. It also has a console timer which shows the loading time.

I would say that your computer is better than my laptop which takes slightly less than 4 seconds to load this model.

As I mentioned previously, currently the info section of the model has to have that "Instanced" entry in order for this to work.

ricaun commented 1 year ago

Hmmm... By default, every mesh_id should be a THREE.InstancedMesh. I guess the THREE.Mesh is slow...

GitHubDragonFly commented 1 year ago

THREE.InstancedMesh does not seem to be as flexible as THREE.Mesh.

I did try using general approach but colors got messed up in some models.

It might be something to consider for the future developments but the code might be tricky to figure out.

ricaun commented 1 year ago

THREE.InstancedMesh does not seem to be as flexible as THREE.Mesh.

I did try using general approach but colors got messed up in some models.

It might be something to consider for the future developments but the code might be tricky to figure out.

Yes, the color/material is a trick to change. I don't know if gonna improve much in a file that does not have many repeated meshes. And If you add face_colors in each mesh gonna needs to be unique as well.

ricaun commented 1 year ago

Probably if you filter the elements in two groups, one that needs to be THREE.Mesh and another one that fit in the THREE.InstancedMesh gonna make some improvements.

GitHubDragonFly commented 1 year ago

I did manage to figure this out but had to sacrifice the edges creation in order to maintain the speed of loading.

Now, only THREE.InstancedMesh is used for all.

The updated files are in my repository but will eventually update the BIMLoaders, Only my mobile STEP Viewer is currently using these new files.

GitHubDragonFly commented 1 year ago

@ricaun the PR has been updated with all the latest changes.

If you don't really want to deal with it then close it or let me know and I will close it.

GitHubDragonFly commented 1 year ago

@ricaun the PR has been updated again to set color of the instanced mesh.

Current design of three.js exporters is not set to properly deal with instanced meshes. I guess this is something they will have to eventually update.

My STEP Viewer has been modified to deal with instanced meshes simply by merging them all and then passing them to exporters.

paireks commented 1 year ago

@GitHubDragonFly hello, shall I add this project: https://githubdragonfly.github.io/viewers/templates/STEP%20Viewer.html into the list here in Viewers category? https://github.com/paireks/dotbim#viewers

I reorganized this list and was wondering if I could add it there. Or maybe I should add another of your repos, cause there is quite many :) Also I'm not sure if they are WIP or ready, because of "read-only" repositories ;)

GitHubDragonFly commented 1 year ago

@paireks you should do whatever you think is the best for your list.

Those "read-only" repositories are as good as they are but still get updated from time to time (some more frequent than the others).

paireks commented 1 year ago

@GitHubDragonFly ok, I've just updated it, let me know if I should anything change or add there.

Thank you for your contribution, I really apprieciate it.

GitHubDragonFly commented 1 year ago

@paireks that's cool and looks good to me.