Giter Site home page Giter Site logo

fragment's Introduction

TOC | documentation | demo | community | npm package

cover

BIM Fragment

NPM Package NPM Package Tests

This library is a geometric system to efficiently display 3D BIM data built on top of Three.js. Specifically, it uses InstancedMeshes to draw each set of repeated geometries (which are abundant in BIM models) using a single draw call.

  • It uses flatbuffers to persist data as a binary format efficiently.
  • It prevents memory leaks exposing a dispose() method.

You generally won't need to interact with this library direclty. Instead, you can use components, which provides an abstraction layer of tools that use this format and make the creation of BIM tools very easy.

Usage

You need to be familiar with Three.js API to be able to use this library effectively. In the following example, we will create a cube in a 3D scene that can be navigated with the mouse or touch events. You can see the full example here and the deployed app here.

import * as FRAGS from '../resources/fragment.js';

const canvas = document.getElementById('container');
const threeScene = new SimpleThreeScene(canvas);

let chairs;

const serializer = new FRAGS.Serializer();

async function importChairsBinary() {
    if (chairs !== undefined) return;
    const fetched = await fetch("../resources/chairs.frag");
    const rawData = await fetched.arrayBuffer();
    const buffer = new Uint8Array(rawData);
    chairs = serializer.import(buffer);
    threeScene.scene.add(chairs);
}

function deleteChairs() {
    if (!chairs) return;
    chairs.dispose();
    chairs = undefined;
}

async function exportChairsBinary() {
    if (!chairs) return;

    const buffer = serializer.export(chairs);
    const file = new File([new Blob([buffer])], "chairs.frag");
    const link = document.createElement('a');
    document.body.appendChild(link);

    link.download = 'chairs.frag';
    link.href = URL.createObjectURL(file);
    link.click();

    link.remove();
}

fragment's People

Contributors

agviegas avatar github-actions[bot] avatar harrycollin avatar hoyosjuan avatar oxcabe avatar quimmoya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fragment's Issues

Conflicting peer dependency (three.js)

Describe the bug ๐Ÿ“

I'm having trouble upgrading openbim-components, because there's a conflict.
Perhaps the issue is that package-lock.json of fragment still has "three": "0.152.2".

Reproduction โ–ถ๏ธ

No response

Steps to reproduce ๐Ÿ”ข

Download this package.json.

{
  "name": "demo-web",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "dependencies": {
    "openbim-components": "^1.3.2",
    "three": "^0.160.1",
    "web-ifc": "^0.0.50"
  }
}

Run npm i in the same directory

Get a conflict error

System Info ๐Ÿ’ป

System:
    OS: Linux 6.6 Pop!_OS 22.04 LTS
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 20.21 GB / 31.19 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.11.0 - /usr/bin/node
    npm: 10.2.4 - /usr/bin/npm
  Browsers:
    Chromium: 121.0.6167.85

Used Package Manager ๐Ÿ“ฆ

npm

Error Trace/Logs ๐Ÿ“ƒ

Error log
 npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/three
npm ERR!   three@"^0.160.1" from the root project
npm ERR!   peer three@">=0.126.1" from [email protected]
npm ERR!   node_modules/camera-controls
npm ERR!     camera-controls@"^1.36.0" from [email protected]
npm ERR!     node_modules/openbim-components
npm ERR!       openbim-components@"^1.3.1" from the root project
npm ERR!   3 more (n8ao, postprocessing, three-mesh-bvh)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer three@"0.152.2" from [email protected]
npm ERR! node_modules/bim-fragment
npm ERR!   peer bim-fragment@"1.3.1" from [email protected]
npm ERR!   node_modules/openbim-components
npm ERR!     openbim-components@"^1.3.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/three
npm ERR!   peer three@"0.152.2" from [email protected]
npm ERR!   node_modules/bim-fragment
npm ERR!     peer bim-fragment@"1.3.1" from [email protected]
npm ERR!     node_modules/openbim-components
npm ERR!       openbim-components@"^1.3.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.

Test fragments issue

Describe the bug ๐Ÿ“

asdfa

Reproduction โ–ถ๏ธ

No response

Steps to reproduce ๐Ÿ”ข

afsdfa

System Info ๐Ÿ’ป

asdfa

Used Package Manager ๐Ÿ“ฆ

npm

Error Trace/Logs ๐Ÿ“ƒ

afasdfa

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a IFC.js fragment issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Discord Chat Server.
  • The provided reproduction is a minimal reproducible example of the bug.

export * from "./base-types"; SyntaxError: Unexpected token 'export'

Describe the bug ๐Ÿ“

I'm using bim-fragment in Nodejs, it throw error

Reproduction โ–ถ๏ธ

https://github.com/RyugaRyuzaki/bim-fragment-server.git

Steps to reproduce ๐Ÿ”ข

  1. Run "npm install"
  2. Run "npm run dev"

System Info ๐Ÿ’ป

Nodejs 20.0.5

Used Package Manager ๐Ÿ“ฆ

npm

Error Trace/Logs ๐Ÿ“ƒ

No response

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a IFC.js fragment issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Discord Chat Server.
  • The provided reproduction is a minimal reproducible example of the bug.

FragmentMap and FragmentIdMap

Describe the bug ๐Ÿ“

FragmentGroup.getFragmentMap returns "FragmentMap", but APIs such as OBC.Highlighter.highlightByID requests "FragmentIdMap". Therefore, I need to write the following conversion code myself. I think this is a bug because "FragmentMap" and "FragmentIdMap" are the same concept.

const item: any = OBC.IfcPropertiesUtils.findItemByGuid(this.groups[0].properties!, guid);
const expressID = item.expressID as number;
const found = this.groups[0].getFragmentMap([expressID]);
const result: OBC.FragmentIdMap = {};
for (const fragmentId in found) {
    const expressIds = new Set<string>();
    const expressIdsInNumber = found[fragmentId];
    for (const expressIdInNumber of expressIdsInNumber) {
        expressIds.add(expressIdInNumber.toString());
    }
    result[fragmentId] = expressIds;
}

this.highlighter.highlightByID('default', result);

Reproduction โ–ถ๏ธ

No response

Steps to reproduce ๐Ÿ”ข

No response

System Info ๐Ÿ’ป

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 5.58 GB / 15.75 GB
  Binaries:
    Node: 16.20.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.7.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (117.0.2045.43)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    openbim-components: ^1.1.0 => 1.1.0

Used Package Manager ๐Ÿ“ฆ

npm

Error Trace/Logs ๐Ÿ“ƒ

No response

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a IFC.js components issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.

FragmentMesh.clone fails with `Cannot read properties of undefined`

Describe the bug ๐Ÿ“

I'm trying to clone a FragmentsGroup. I assumed this would be possible, because FragmentsGroup extends Group. However, it fails with Cannot read properties of undefined.

The root of the problem seems to be that FragmentMesh (or maybe FragmentsGroup) doesn't defined a clone-method which results in the default clone being called. The default implementation is the following:

  clone(recursive) {
    return new this.constructor().copy(this, recursive);
  }

This calls the constructor of FragmentMesh. Unfortunately, FragmentMesh doesn't define default arguments which leads to problems, such as geometry being undefined.

To fix the issue, either a clone that calls the constructor with proper arguments should be implemented, or a constructor with defaults arguments should be implemented. I feel that the latter would be the Three.js way, but I haven't read enough fragment code to make a judgement.

Reproduction โ–ถ๏ธ

No response

Steps to reproduce ๐Ÿ”ข

  1. Create a FragmentsGroup anyway you want. In my case:
    const file = await selectFile();
    if (!file) {
        console.warn('File not loaded');
        return;
    }
    const data = await file.arrayBuffer();
    const buffer = new Uint8Array(data);
    const model = await fragmentIfcLoader.load(buffer, "example");
   components.scene.get().add(model);
    ```
2.Try cloning a `FragmentsGroup`. For example, after loading the model call:

// fragments is a FragmentsManager
const group = fragments.groups[0];
group.clone(true);
``

Result:

Cannot read properties of undefined

System Info ๐Ÿ’ป

System:
    OS: Linux 6.6 Pop!_OS 22.04 LTS
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 13.53 GB / 31.19 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/bin/node
    npm: 10.2.3 - /usr/bin/npm
  Browsers:
    Chromium: 120.0.6099.71
  npmPackages:
    openbim-components: ^1.2.0 => 1.2.0

Used Package Manager ๐Ÿ“ฆ

npm

Error Trace/Logs ๐Ÿ“ƒ

Console logs!
openbim-components.js?v=4bd4a061:45990 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'index')
    at _FragmentMesh.newFragmentGeometry (openbim-components.js?v=4bd4a061:45990:19)
    at new _FragmentMesh (openbim-components.js?v=4bd4a061:45942:26)
    at _FragmentMesh.clone (chunk-ADNH2OTW.js?v=4bd4a061:5238:12)
    at FragmentsGroup2.copy (chunk-ADNH2OTW.js?v=4bd4a061:5263:24)
    at FragmentsGroup2.clone (chunk-ADNH2OTW.js?v=4bd4a061:5238:35)
    at cloneAndUnravel (ifcmain.ts:107:23)
    at produceGlb (ifcmain.ts:102:17)
    at exportGlb (ifcmain.ts:137:21)
    at Object.exportGlb (ifcmain.ts:163:20)
    at HTMLButtonElement.<anonymous> (three_examples_jsm_libs_lil-gui__module__min.js?v=4bd4a061:145:44)

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.

Test issue

Description ๐Ÿ“

Test issue description!

Suggested solution ๐Ÿ’ก

asdfa dffadfa

Alternative โ›•

fadsfaasdfa

Additional context โ˜๏ธ

afadfaaafdsa aada

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

moving three js to peerDependencies

Description ๐Ÿ“

I suggest moving three js dependency out of dependencies, to peerDependencies and devDependencies, this way i believe we can reduce total size of a library.

Suggested solution ๐Ÿ’ก

"dependencies": {
"flatbuffers": "^23.3.3",
"three": "0.152.2",
"three-mesh-bvh": "0.6.0"
}
->
"dependencies": {
"flatbuffers": "^23.3.3",
"three-mesh-bvh": "0.6.0"
}
"devDependencies": {
...
"three": "0.152.2",
}
"peerDependencies": {
"three": "0.152.2",
}

Alternative โ›•

No response

Additional context โ˜๏ธ

I beleive this direct dependency to be primary suspect of really heavy size of the bundle.

Validations โœ…

  • Read the docs.
  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.