AECgeeks / BIMsurfer2

MIT License
106 stars 25 forks source link

Correct gltf conversion #4

Closed DaJansenGit closed 4 years ago

DaJansenGit commented 4 years ago

We are running into an issue when converting our .ifc files into gltf. We used the following python script

IFCCONVERT = Path('./IfcConvert')
COLLADA = Path('./collada2gltf/COLLADA2GLTF-v2.1.5-windows-Release-x64/COLLADA2GLTF-bin')
GLTFPIPELINE = Path('./gltf-pipeline/bin/gltf-pipeline.js')
os.chdir(r'C:\Entwicklung\test\ifc2gltf')

def convert(ifc_file):
    name = Path(ifc_file).stem
    # for some reason gltf file needs double .gltf ending to be read by bimSurfer
    cmd_convert0 = '{} --use-element-guids {path} {name}.xml'.format(IFCCONVERT, path=ifc_file, name=name)
    cmd_convert1 = '{} --use-element-guids {path} {name}.dae'.format(IFCCONVERT, path=ifc_file, name=name)
    cmd_convert2 = "{} -i {name}.dae -o {name}.gltf.gltf -v '1.0'".format(COLLADA, name=name)  #  -v '1.0'
    for cmd in (cmd_convert0, cmd_convert1, cmd_convert2):
        print(cmd)
        p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        for line in p.stdout.readlines():
            if line:
                print(line.replace(b'\x00', b''))  # DIRTY!
        retval = p.wait()
        print(retval)

which works fine but when trying to load the .gltf with bimsurfer the browser returns:

image

IfcConvert: 0.6.0 (Windows 64 bit) Collada2Gltf: v.2.1.5

Are there any flags we have to set when converting to gltf? We tried gltf v1.0 and gltf v2.0

aothms commented 4 years ago

I don't know. There error you get is a 404 Not Found. Are you sure it's related to this repository?

Have you seen https://github.com/AECgeeks/ifc-pipeline it'll give you a python back-end for this viewer. Also IfcConvert can convert to .glb directly if you use a recent version.

DaJansenGit commented 4 years ago

Thanks for the fast reply! The 404 error is not due to this repository, sorry this wasn't clear. I meant the entry[0] overwritten problems and the xeogl.input error. With the provided demo .gtlf files everything runs fine. So it has to be something regarding our gltf files I think. We tried now with the .glb conversion and run into the following error: image

Haven't seen the ifc-pipeline repo. Good to know there is a python backend!!

aothms commented 4 years ago

Ah, ok, for the time being I recommend using the ThreeJS rendered in this repository. The xeogl renderer is a bit behind. So when instantiate your BimSurfer, add a engine: 'threejs' to the arguments, like so https://github.com/AECgeeks/BIMsurfer2/blob/master/bimsurfer/src/MultiModal.js#L30

aothms commented 4 years ago

Actually I just changed the default to threejs https://github.com/AECgeeks/BIMsurfer2/blob/master/bimsurfer/src/BimSurfer.js

DaJansenGit commented 4 years ago

Thanks again for the very fast reply! I updated our BimSurfer to the current state of the repo. Unfortunately also threeJs viewer makes problems in our setup, while it works fine in your demo. All the resources of liband srcfolder are the same. Do you have any idea where this errors could come from?

image

Edit: To make the gltf demo of your repo work again the resource lib files for threeJs are missing currently I think. I fixed this by adding them in gltf.html:

    <script type="text/javascript" src="../bimsurfer/lib/three.js"></script>
    <script type="text/javascript" src="../bimsurfer/lib/OrbitControls.js"></script>
    <script type="text/javascript" src="../bimsurfer/lib/GLTFLoader.js"></script>
    <script type="text/javascript" src="../bimsurfer/lib/DRACOLoader.js"></script>    
aothms commented 4 years ago

This is an error while loading the glTF. Token < at position 0 probably means you're feeding it an html or xml document instead of the glTF, possibly an error page of some kind if your webserver cannot locate the referenced glTF.

Sent from a mobile device. Excuse my brevity. Kind regards, Thomas

Op ma 17 aug. 2020 17:30 schreef David Jansen notifications@github.com:

Thanks again for the very fast reply! In updated our BimSurfer to the current state of the repo. Unfortunately also threeJs viewer makes problems in our setup, while it works fine in your demo. All the resources of lib and src folder are the same. Do you have any idea where this errors could come from?

[image: image] https://user-images.githubusercontent.com/27726960/90411758-847cf580-e0ac-11ea-9082-d8dcd62baf4b.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AECgeeks/BIMsurfer2/issues/4#issuecomment-674949823, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAILWV4X3GIGYF5DGIQZPBTSBFEH7ANCNFSM4P6PWWXQ .

DaJansenGit commented 4 years ago

You were right. It was a problem with doubled data format extension in our code (.gltf.glb) -.- . We can load our files now. Anyway we do still have some problems with the viewer.

I recorded two gifs for demonstration. As you can see with the Duplex_A_20110907_optimized we don't encounter the problems we have with our own glb. _Editstart:
To make sure that it's not an ifc problem I searched for the duplex ifc and found it here: http://smartlab1.elis.ugent.be:8889/IFC-repo/ I converted the duplex IFC with our conversion script and we have same errors. I attached a .gif of this as well _Editend:

glb_example_gifs.zip

The ViewFit() error shown in both .gif is described at the end of this post but has nothing to do with the gltf but with ThreeJs implementation into BimSurfer

Is there anything to be aware of when convertig from ifc -> glb regarding BimSurfer? I tried

but with all files we have the problems shown above.

I attached one of your .glb files. AC20-FZK-Haus-v2.zip

Also I saw that some of the build in functions of BimSurfer like viewFit() aren't implemented for threeJs and throw errors but used in highlight()function for example. I can have a look for an equivalent function in threeJS.

Thanks in advance for your help!

aothms commented 4 years ago

The selection problem sounds to me that there is an issue with somehow getting the correct mouse coordinates or translating them relatively to the canvas, or perhaps some DPI issue. How do you position your canvas, what kind of CSS is applied?

I have upload AC20 FZK here and didn't find any issues https://view.ifcopenshell.org/v/vdflizoOFUDhuLHOZJuVibhblUnIKxSp (although there was an uninitialized variable somewhere, but I doubt that was related).

Yeah, could be that some parts are not implemented yet in ThreeJS. Any help appreciated. Likely not complicated.

DaJansenGit commented 4 years ago

Thanks again! The problems were coming from the conversion. We used gltf-pipeline before to convert from .dae-> .glb. By converting directly with IfcConvert our models are fine and everything works :) Your source code from ifc-pipeline was very helpfull. For the viewFitfunction for threeJs I will create a pullrequest when I'm done. From my site we can close this issue!

sadsasuke commented 8 months ago

@DaJansenGit how to make viewFit work?