Giter Site home page Giter Site logo

xeokit / sdk Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 10.0 123.25 MB

Next-generation alpha-status xeokit viewer in development

Home Page: https://xeokit.github.io/sdk/docs/api/index.html

License: GNU Affero General Public License v3.0

JavaScript 38.57% TypeScript 60.75% HTML 0.55% CSS 0.13%
aec bim ifc javascript webgl webgpu

sdk's Introduction

@xeokit

Welcome to the xeokit SDK - a flexible and powerful tool for creating stunning visualizations of AECO models in your browser.

Built with TypeScript, xeokit offers lightning-fast loading and rendering of even the most complex models, while using minimal system resources.

The scene graph works seamlessly on both browser and NodeJS platforms, allowing you to create, convert and provide content for the model viewer.

Benefit from built-in support for multiple canvases, utility libraries with complete documentation, and the ability to import/export models as industry-standard AECO file formats. Collaborate with other BIM software via BCF Viewpoints and bring your AECO models to life with xeokit.

Table of Contents

  1. Usage Examples
  2. Modules
  3. Examples
  4. Project development
  5. License
  6. Credits

Preparing the project:

Usage examples

Work in progress;

Modules

Scene Graph

The SDK represents models in a scene graph that include the model's objects, geometries, and materials. This scene graph works on both the browser and NodeJS platforms and can be used to create models, convert between model formats, and provide content for the SDK's model viewer.

Package Modules Description
@xeokit/scene @xeokit/scene Scene graph that contains model representations (geometries, materials etc.)

Data Graph

The SDK employs a generic entity-relationship data graph to manage model semantics, which includes entities, properties, and relationships. This data graph is compatible with both the browser and NodeJS and facilitates model generation, format conversion, and content navigation within the SDK's model viewer.

Package Modules Description
@xeokit/data @xeokit/data Entity-relationship graph that contains model semantic data.

Model Viewer

The SDK contains a high-performance Web viewer for displaying our model representations. Through a pluggable renderer strategy, the viewer can be extended to utilize various browser graphics APIs, including WebGL and WebGPU. Multiple models can be viewed simultaneously, and the viewer allows for the creation of separate canvases, featuring lights, section planes, annotations, and other elements, to display multiple views of our models.

Package Modules Description
@xeokit/viewer @xeokit/viewer Browser-based model viewer
@xeokit/cameracontrol @xeokit/cameracontrol Interactive camera control for a viewer
@xeokit/webglrenderer @xeokit/webglrenderer WebGL rendering strategy for a viewer
@xeokit/treeview @xeokit/treeview HTML tree view widget for a Viewer
@xeokit/locale @xeokit/locale Localization service for a viewer

Model Importers and Exporters

The SDK provides functions for importing and exporting its model representations and semantics as industry-standard AECO file formats. These functions can be used in NodeJS scripts for file format conversion or in the browser to load various file formats into the viewer.

Package Modules Description
@xeokit/dtx @xeokit/dtx Import and export XKT files
@xeokit/gltf @xeokit/gltf Import glTF files
@xeokit/las @xeokit/las Import LAS pointcloud scans
@xeokit/cityjson @xeokit/cityjson Import CityJSON files
@xeokit/webifc @xeokit/webifc Import IFC files

Interoperating with BIM Software

The SDK offers functions for sharing bookmarks of viewer state with other BIM software as industry-standard BCF Viewpoints. These functions can be used to develop applications that facilitate collaboration on construction projects.

Package Modules Description
@xeokit/bcf @xeokit/bcf Load and save BCF

Utility Libraries

The SDK's internal and lower-level functionalities are mostly available as utility libraries with complete documentation.

Package Modules Description
@xeokit/core @xeokit/core Basic component types used throughout the xeokit SDK
@xeokit/core/constants Constants used throughout the xeokit SDK
@xeokit/core/utils Core utilities used throughout the xeokit SDK
@xeokit/basictypes @xeokit/basictypes/basicTypes Basic semantic data type constants
@xeokit/ifctypes IFC data type constants
@xeokit/math @xeokit/math/math General math definitions and constants
@xeokit/math/boundaries Boundaries math library
@xeokit/math/compression SceneGeometry de/compression utilities library
@xeokit/math/curves Spline curves math library
@xeokit/math/geometry SceneMesh generation functions
@xeokit/math/matrix Matrix and vector math utilities library
@xeokit/math/rtc Relative-to-center (RTC) coordinates math library
@xeokit/webgl @xeokit/webglutils WebGL utilities library
@xeokit/procgen @xeokit/procgen/geometry SceneGeometry generation functions
@xeokit/ktx2 @xeokit/ktx2 Compressed texture support

Examples

Spinning Textured Box

Let's make a simple application using xeokit - a spinning, textured box.

First import the npm modules we need from the SDK:

npm install @xeokit/scene
npm install @xeokit/viewer
npm install @xeokit/webglrenderer
npm install @xeokit/core/constants

Then create a simple HTML page with a canvas element:

<!DOCTYPE html>
<html>
  <head>
    <title>xeokit Spinning Textured Box</title>
  </head>
  <body>
    <canvas id="myCanvas"></canvas>
  </body>
</html>

Now let's write some JavaScript to create the spinning, textured box.

import {Scene} from "@xeokit/scene";
import {TrianglesPrimitive, LinearEncoding, LinearFilter} from "@xeokit/core/constants";
import {Viewer} from "@xeokit/viewer";
import {WebGLRenderer} from "@xeokit/webglrenderer";

const scene = new Scene(); // Scene graph

const renderer = new WebGLRenderer({}); // WebGL renderers kernel

const viewer = new Viewer({ // Browser-base viewer
    scene,
    renderer
});

const view = myViewer.createView({ // Independent view 
    id: "myView",
    canvasId: "myView1"
});

view.camera.eye = [0, 0, 10]; // Looking down the -Z axis
view.camera.look = [0, 0, 0];
view.camera.up = [0, 1, 0];

const sceneModel = scene.createModel(); // Start building the scene graph

sceneModel.createGeometry({ // Define a box-shaped geometry
    id: "boxGeometry",
    primitive: TrianglesPrimitive,
    positions: [-1, -1, -1, 1, -1, -1, ],
    uvs: [1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, ],
    indices: [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, ]
});

sceneModel.createTexture({ // 
    id: "boxColorTexture",
    src: "myTexture.png",
    encoding: LinearEncoding,
    magFilter: LinearFilter,
    minFilter: LinearFilter
});

sceneModel.createTextureSet({
    id: "boxTextureSet",
    colorTextureId: "boxColorTexture"
});

sceneModel.createLayerMesh({
    id: "boxMesh",
    geometryId: "boxGeometry",
    color: [1, 1, 1],
    metallic: 0.8, // PBR material attributes
    roughness: 0.3,
    textureSetId: "boxTextureSet"
});

sceneModel.createObject({
    id: "boxObject",
    meshIds: ["boxMesh"]
});

sceneModel.build().then(() => { // Compresses textures, geometries etc.

    // A textured box object now appears on our View's canvas.

    // We can now show/hide/select/highlight our box through the View:

    view.objects["boxObject"].visible = true;
    view.objects["boxObject"].highlighted = false;  // etc.

    // Start orbiting the camera:

    viewer.onTick.subscribe(() => {
        view.camera.orbitYaw(1.0);
    });
});

glTF Model Viewer

Let's make a simple application that views a glTF file in the browser.

First import the npm modules we need from the SDK:

npm install @xeokit/scene
npm install @xeokit/viewer
npm install @xeokit/webglrenderer
npm install @xeokit/core/constants
npm install @xeokit/gltf

Here's the JavaScript for our glTF viewer app:

import {Scene} from "@xeokit/scene";
import {TrianglesPrimitive, LinearEncoding, LinearFilter} from "@xeokit/core/constants";
import {Viewer} from "@xeokit/viewer";
import {WebGLRenderer} from "@xeokit/webglrenderer";
import {loadGLTF} from "@xeokit/gltf";

const scene = new Scene(); // Scene graph

const renderer = new WebGLRenderer({}); // WebGL renderers kernel

const viewer = new Viewer({ // Browser-base viewer
    scene,
    renderer
});

const view = myViewer.createView({ // Independent view 
    id: "myView",
    canvasId: "myView1"
});

view.camera.eye = [0, 0, 10]; // Looking down the -Z axis
view.camera.look = [0, 0, 0];
view.camera.up = [0, 1, 0];

const sceneModel = scene.createModel(); // Start building the scene graph

fetch("myModel.glb").then(response => {

    response.arrayBuffer().then(data => {

        loadGLTF({data, scene}).then(() => {

            sceneModel.build().then(() => { // Compresses textures, geometries etc.

                // A model now appears on our View's canvas.

                // We can now show/hide/select/highlight the model's objects through the View:

                view.objects["2hExBg8jj4NRG6zzE$aSi6"].visible = true;
                view.objects["2hExBg8jj4NRG6zzE$aSi6"].highlighted = false;  // etc.

                // Start orbiting the camera:

                viewer.onTick.subscribe(() => {
                    view.camera.orbitYaw(1.0);
                });
            });
        });
    });
});

Convert a glTF file to XKT

Let's make a simple NodeJS script that converts a glTF file into xeokit's native XKT format.

First import the npm modules we need from the SDK. Note that we don't need the viewer for this example.

npm install @xeokit/scene
npm install @xeokit/core/constants
npm install @xeokit/gltf
npm install @xeokit/dtx

Here's the JavaScript for our converter script.

import {Scene} from "@xeokit/scene";
import {Data} from "@xeokit/data";
import {TrianglesPrimitive, LinearEncoding, LinearFilter} from "@xeokit/core/constants";
import {loadGLTF} from "@xeokit/gltf";
import {saveXKT} from "packages/dtx";

const fs = require('fs');

const scene = new Scene(); // Scene graph
const sceneModel = scene.createModel({ id: "myModel" }); // Start building the scene graph

const data = new Data();
const dataModel = data.createModel({ id: "myModel" }); // Will model the glTF scene hierarchy

fs.readFile("./tests/assets/HousePlan.glb", (err, buffer) => {
    const arraybuffer = toArrayBuffer(buffer);
    loadGLTF({
        data: arrayBuffer,
        sceneModel,
        dataModel
    }).then(() => {
        sceneModel.build().then(() => { // Compresses textures, geometries etc.
            const arrayBuffer = saveXKT({ sceneModel, dataModel });
            fs.writeFile('myModel.dtx', arrayBuffer, err => {});
        });
    })
});

function toArrayBuffer(buf) {
    const ab = new ArrayBuffer(buf.length);
    const view = new Uint8Array(ab);
    for (let i = 0; i < buf.length; ++i) {
        view[i] = buf[i];
    }
    return ab;
}

Project development

Preparing:

To start developing this project, you should first install it, preferably globally:

npm i pnpm -g
pnpm install turbo --global

Then clone the repository:

git clone https://github.com/xeokit/sdk

Install the project using:

pnpm i

Building:

To build all packages and their dependencies use:

pnpm dist

This will automatically start all project building processes, a dist directory will be created in each package, this is a representation of the package's built source and its dependencies.

Testing:

To run all tests:

pnpm test

To run tests for specific package:

turbo run test --filter=nameOfSelectedPackage  

License

Copyright 2020, AGPL3 License.

Credits

See Credits.

sdk's People

Contributors

db-ec-hamburg-bim avatar dhivinx avatar paireks avatar xeolabs avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

sdk's Issues

Goals

  • Written in TypeScript
  • Uses WebGPU for rendering
  • Multiple views of same content, each with independent per-object state, section planes, and camera

Adding LICENSE file

Just adding note to remember, that there is only tiny mention about license, without a LICENSE file.

Architectural Review

API is now pretty stable and documentation almost complete (for the core of the SDK).

What would be great now would be:

  • opinions on names of things - anything that should be renamed for a better "user mental model"?
  • any code smells that must be factored out?
  • architectural changes?
  • new features that look doable on the new architecture?
  • any new tech we should use to manege the project?

Don't worry about any erros in the API docs - they're still work in progress. Although, any comments on how those might be improved are always great.

Also note that no npm modules have been published yet.

npm run dist always fails with TS2307: Cannot find module '@xeokit/data'

Attempting to build by running npm run dist, the process always fails with the following message:

@xeokit/gltf2dtx:dist: src/gltf2dtx.ts(3,20): error TS2307: Cannot find module '@xeokit/data' or its corresponding type declarations.

I'm stuck on this error - If anyone can see where I've configured things wrongly that would be cool.

  • using turborepo
  • building on Ubuntu, using NodeJS v16.17.1
lindsay@mousebear:~/xeolabs/sdk-feb4-2$ npm run dist

> [email protected] dist
> turbo run dist   --concurrency 100

╭───────────────────────────────────────────────────────────────────────╮
│                                                                       │
│                  Update available v1.11.2 ≫ v1.12.3                   │
│    Changelog: https://github.com/vercel/turbo/releases/tag/v1.12.3    │
│           Run "npx @turbo/codemod@latest update" to update            │
│                                                                       │
│        Follow @turborepo for updates: https://x.com/turborepo         │
╰───────────────────────────────────────────────────────────────────────╯
• Packages in scope: @xeokit/basictypes, @xeokit/bcf, @xeokit/boundaries, @xeokit/cameracontrol, @xeokit/cityjson, @xeokit/cityjson2dtx, @xeokit/cityjsontypes_1_1_3, @xeokit/compression, @xeokit/constants, @xeokit/core, @xeokit/curves, @xeokit/data, @xeokit/demos, @xeokit/dotbim, @xeokit/dtx, @xeokit/gltf, @xeokit/gltf2dtx, @xeokit/ifc2dtx, @xeokit/ifctypes, @xeokit/kdtree2, @xeokit/kdtree3, @xeokit/ktx2, @xeokit/las, @xeokit/las2dtx, @xeokit/locale, @xeokit/math, @xeokit/matrix, @xeokit/pick, @xeokit/procgen, @xeokit/rtc, @xeokit/scene, @xeokit/testutils, @xeokit/threedxml, @xeokit/treeview, @xeokit/utils, @xeokit/viewer, @xeokit/webglrenderer, @xeokit/webglutils, @xeokit/webifc
• Running dist in 39 packages
• Remote caching disabled
@xeokit/compression:dist: cache bypass, force executing f5077ea08e20f7ea
@xeokit/pick:dist: cache bypass, force executing c98ac46dfde320e1
@xeokit/math:dist: cache bypass, force executing 49848de5797259ec
@xeokit/cityjsontypes_1_1_3:dist: cache bypass, force executing a8987917917a138f
@xeokit/webifc:dist: cache bypass, force executing 7e0bb63e57ddaacc
@xeokit/gltf:dist: cache bypass, force executing b3cab1843e766eac
@xeokit/rtc:dist: cache bypass, force executing 2f453c93c8d69192
@xeokit/dtx:dist: cache bypass, force executing 964f6be7122489f9
@xeokit/webglrenderer:dist: cache bypass, force executing 4528da8e3054f657
@xeokit/las2dtx:dist: cache bypass, force executing 2427a0dc1a72db17
@xeokit/las:dist: cache bypass, force executing 3b006a415ce2e97b
@xeokit/bcf:dist: cache bypass, force executing 407f06f9fa354bee
@xeokit/viewer:dist: cache bypass, force executing b79f539051e4abd7
@xeokit/dotbim:dist: cache bypass, force executing fb692263329469d8
@xeokit/utils:dist: cache bypass, force executing 6e329a870559b5ab
@xeokit/ifctypes:dist: cache bypass, force executing 0583eea0c6f14b8c
@xeokit/ifc2dtx:dist: cache bypass, force executing dea2acebbda7d363
@xeokit/ktx2:dist: cache bypass, force executing 58ed3487f61ddbfd
@xeokit/matrix:dist: cache bypass, force executing 0a4a76a90b60e7b6
@xeokit/procgen:dist: cache bypass, force executing 15970707e1be1dc3
@xeokit/scene:dist: cache bypass, force executing 2a7028e1d3cad41c
@xeokit/data:dist: cache bypass, force executing bb8e896a58d48296
@xeokit/kdtree3:dist: cache bypass, force executing abbf858cef3659bf
@xeokit/basictypes:dist: cache bypass, force executing 1a8085121bc68d20
@xeokit/curves:dist: cache bypass, force executing e2a3b2b58944c654
@xeokit/gltf2dtx:dist: cache bypass, force executing d3605a8202d81d8a
@xeokit/constants:dist: cache bypass, force executing 9ebb68d1be47b9ad
@xeokit/treeview:dist: cache bypass, force executing 8e5f20e11164591c
@xeokit/core:dist: cache bypass, force executing e76478bee5c9fe55
@xeokit/cityjson2dtx:dist: cache bypass, force executing 82659b4c0235f2f4
@xeokit/kdtree2:dist: cache bypass, force executing 8fe02feafe180fca
@xeokit/locale:dist: cache bypass, force executing 0cc0b18c521cc7c3
@xeokit/webglutils:dist: cache bypass, force executing 9274ee03b4bd3da4
@xeokit/cityjson:dist: cache bypass, force executing 0a1acaff8d2d25e2
@xeokit/cameracontrol:dist: cache bypass, force executing deecc4b7cb81f9e5
@xeokit/boundaries:dist: cache bypass, force executing 1e3526e05816060f
@xeokit/threedxml:dist: cache bypass, force executing ede1850de8ce6ef6
@xeokit/compression:dist: yarn run v1.22.19
@xeokit/math:dist: yarn run v1.22.19
@xeokit/gltf:dist: yarn run v1.22.19
@xeokit/pick:dist: yarn run v1.22.19
@xeokit/webifc:dist: yarn run v1.22.19
@xeokit/cityjsontypes_1_1_3:dist: yarn run v1.22.19
@xeokit/webglrenderer:dist: yarn run v1.22.19
@xeokit/las2dtx:dist: yarn run v1.22.19
@xeokit/dtx:dist: yarn run v1.22.19
@xeokit/dotbim:dist: yarn run v1.22.19
@xeokit/las:dist: yarn run v1.22.19
@xeokit/utils:dist: yarn run v1.22.19
@xeokit/rtc:dist: yarn run v1.22.19
@xeokit/viewer:dist: yarn run v1.22.19
@xeokit/ifctypes:dist: yarn run v1.22.19
@xeokit/boundaries:dist: yarn run v1.22.19
@xeokit/ktx2:dist: yarn run v1.22.19
@xeokit/matrix:dist: yarn run v1.22.19
@xeokit/scene:dist: yarn run v1.22.19
@xeokit/procgen:dist: yarn run v1.22.19
@xeokit/data:dist: yarn run v1.22.19
@xeokit/gltf:dist: $ tsc
@xeokit/constants:dist: yarn run v1.22.19
@xeokit/math:dist: $ tsc
@xeokit/las2dtx:dist: $ tsc
@xeokit/kdtree3:dist: yarn run v1.22.19
@xeokit/compression:dist: $ tsc
@xeokit/cityjsontypes_1_1_3:dist: $ tsc
@xeokit/curves:dist: yarn run v1.22.19
@xeokit/gltf2dtx:dist: yarn run v1.22.19
@xeokit/ifc2dtx:dist: yarn run v1.22.19
@xeokit/webglutils:dist: yarn run v1.22.19
@xeokit/cityjson2dtx:dist: yarn run v1.22.19
@xeokit/treeview:dist: yarn run v1.22.19
@xeokit/core:dist: yarn run v1.22.19
@xeokit/dtx:dist: $ tsc
@xeokit/basictypes:dist: yarn run v1.22.19
@xeokit/utils:dist: $ tsc
@xeokit/viewer:dist: $ tsc
@xeokit/rtc:dist: $ tsc
@xeokit/ifctypes:dist: $ tsc
@xeokit/procgen:dist: $ tsc
@xeokit/locale:dist: yarn run v1.22.19
@xeokit/boundaries:dist: $ tsc
@xeokit/kdtree2:dist: yarn run v1.22.19
@xeokit/ktx2:dist: $ tsc
@xeokit/las:dist: $ tsc
@xeokit/constants:dist: $ tsc
@xeokit/dotbim:dist: $ tsc
@xeokit/webifc:dist: $ tsc
@xeokit/data:dist: $ tsc
@xeokit/bcf:dist: yarn run v1.22.19
@xeokit/webglrenderer:dist: $ tsc
@xeokit/pick:dist: $ tsc
@xeokit/threedxml:dist: yarn run v1.22.19
@xeokit/kdtree3:dist: $ tsc
@xeokit/matrix:dist: $ tsc
@xeokit/scene:dist: $ tsc
@xeokit/core:dist: $ tsc
@xeokit/basictypes:dist: $ tsc
@xeokit/cityjson2dtx:dist: $ tsc
@xeokit/ifc2dtx:dist: $ tsc
@xeokit/cameracontrol:dist: yarn run v1.22.19
@xeokit/curves:dist: $ tsc
@xeokit/treeview:dist: $ tsc
@xeokit/gltf2dtx:dist: $ tsc
@xeokit/cityjson:dist: yarn run v1.22.19
@xeokit/webglutils:dist: $ tsc
@xeokit/locale:dist: $ tsc
@xeokit/bcf:dist: $ tsc
@xeokit/kdtree2:dist: $ tsc
@xeokit/threedxml:dist: $ tsc
@xeokit/cityjson:dist: $ tsc
@xeokit/cameracontrol:dist: $ tsc
@xeokit/math:dist: Done in 4.40s.
@xeokit/cityjson2dtx:dist: Done in 4.33s.
@xeokit/utils:dist: Done in 4.53s.
@xeokit/cityjsontypes_1_1_3:dist: Done in 4.57s.
@xeokit/constants:dist: Done in 4.55s.
@xeokit/procgen:dist: Done in 4.64s.
@xeokit/ifctypes:dist: Done in 4.75s.
@xeokit/gltf2dtx:dist: src/gltf2dtx.ts(3,20): error TS2307: Cannot find module '@xeokit/data' or its corresponding type declarations.
@xeokit/ktx2:dist: Done in 4.82s.
@xeokit/data:dist: Done in 4.84s.
@xeokit/kdtree3:dist: Done in 4.83s.
@xeokit/gltf2dtx:dist: error Command failed with exit code 2.
@xeokit/gltf2dtx:dist: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@xeokit/gltf2dtx:dist: ERROR: command finished with error: command (/home/lindsay/xeolabs/sdk-feb4-2/packages/gltf2dtx) /usr/local/bin/yarn run dist exited (2)
@xeokit/gltf2dtx#dist: command (/home/lindsay/xeolabs/sdk-feb4-2/packages/gltf2dtx) /usr/local/bin/yarn run dist exited (2)

 Tasks:    10 successful, 37 total
Cached:    0 cached, 37 total
  Time:    5.635s 
Failed:    @xeokit/gltf2dtx#dist

 ERROR  run failed: command  exited (2)
lindsay@mousebear:~/xeolabs/sdk-feb4-2$ 

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.