Giter Site home page Giter Site logo

cityjson-threejs-loader's Introduction

CityJSON three.js loader

A loader for CityJSON files in three.js.

Installation

Use in your project

yarn install git+https://github.com/cityjson/cityjson-threejs-loader.git

Development

  • Clone this repository
  • Run yarn install
  • Go nuts!

Run examples

Use

You need to select one of the availables parsers (recommended is CityJSONWorkerParser) and use it with CityJSONLoader.

import { CityJSONLoader, CityJSONWorkerParser } from 'cityjson-threejs-loader'

// Initialise your scene here

const parser = CityJSONWorkerParser();

const loader = CityJSONLoader( parser );

loader.load( cityjsonData );

scene.add( loader.scene );

Raycasting the scene

The added scene objects contain functions to retrieve information related to the original city model when raycasting:

// Initialise raycaster

const intersections = raycaster.intersectObject( loader.scene );

if ( intersection ) {

    // Gain the 3D object that was hit by the closest ray
    const object = intersection[ 0 ].object;

    // Check if this is a city object
    if ( object.isCityObject ) {

        const data = object.resolveIntersectionInfo( intersection[ 0 ], cityjsonData )

        const objectId = data.objectId; // This is the objectId of the city object hit by the ray

    }

}

Visualization options

The scene objects have specialised materials to handle aspects of how the respective geometries are handled. For example:

// Traverse the scene for objects
scene.traverse( obj = > {

    // Check if this has a material and if this is a city object material
    if ( obj.material && obj.material.isCityObjectsMaterial ) {

        obj.material.showSemantics = false; // This will disable coloring per semantic surface

    }

} );

Highlighting objects

City object materials can be used to highlight a specific object:

// Assuming cityjsonData contains the citymodel and we want to highlight the selectObjectId
const objectIndex = Object.keys( cityjsonData.CityObjects ).indexOf( selectedObjectId )

// Traverse the scene for objects
scene.traverse( obj = > {

    // Check if this has a material and if this is a city object material
    if ( obj.material && obj.material.isCityObjectsMaterial ) {

        // Set the highlighted object index to what was found before
        obj.highlightedObject = {

            objectIndex: objectIndex

        };

    }

} );

cityjson-threejs-loader's People

Contributors

liberostelios avatar ylannl avatar

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.