Coder Social home page Coder Social logo

oxcabe / ifcjs-fragment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thatopen/engine_fragment

0.0 0.0 0.0 12.92 MB

Home Page: https://ifcjs.github.io/fragment/example

License: MIT License

JavaScript 89.47% TypeScript 10.51% CSS 0.02%

ifcjs-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 'bim-fragment';

const canvas = document.getElementById('container');

// Simple three.js scene: check the resources folder of this repo
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);

  for(const frag of chairs) {
    threeScene.scene.add(frag.mesh);
  }
}

function deleteChairs() {
  if (!chairs) return;
  for(const frag of chairs) {
    frag.dispose(true);
  }
  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();
}

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.