Coder Social home page Coder Social logo

joaomartins-callmejohn / aps-viewer-rooms-screenshots Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8.83 MB

APS Rooms Screenshots sample: Sample to generate screenshots from rooms from a Revit design in Viewer context

Home Page: https://joaomartins-callmejohn.github.io/aps-viewer-rooms-screenshots/

License: MIT License

JavaScript 69.76% HTML 30.24%

aps-viewer-rooms-screenshots's Introduction

aps-viewer-rooms-screenshots

APS Rooms Screenshots sample: Sample to generate screenshots from rooms from a Revit design in Viewer context

THIS IS A WORK IN PROGRESS

DEMO:

Introduction

Lets say you need to generate images of your scene at specific orientations. The commom way would be prompting the user to walk through the model, properly orienting the camera ang generating some images. In specific contexts, we can automate this workflow to generate these images using Viewer methods such as setView and getScreenShot. This is what we'll cover in this sample, in this case focusing on generating automatic images of rooms.

generated images

The approach

We are basically take advantage of the methods used by Eason's moving camera to rooms blog in the in order to list and obtain bounding boxes and names from the rooms available in the scene, just like in the snippet below:

async getRoomData() {
  const getRoomDbIds = () => {
    return new Promise((resolve, reject) => {
      this.viewer.search(
        'Revit Rooms',
        (dbIds) => resolve(dbIds),
        (error) => reject(error),
        ['Category'],
        { searchHidden: true }
      );
    });
  };

  const getPropertiesAsync = (dbId) => {
    return new Promise((resolve, reject) => {
      this.viewer.getProperties(
        dbId,
        (result) => resolve(result),
        (error) => reject(error),
      );
    });
  }

  const data = [];

  try {
    const roomDbIds = await getRoomDbIds();
    if (!roomDbIds || roomDbIds.length <= 0) {
      throw new Error('No Rooms found in current model');
    }

    for (let i = 0; i < roomDbIds.length; i++) {
      const dbId = roomDbIds[i];
      const propData = await getPropertiesAsync(dbId);

      data.push({
        id: propData.externalId,
        dbId: dbId,
        name: propData.name
      });
    }

  } catch (ex) {
    console.warn(`[RoomListPanel]: ${ex}`);
    throw new Error('Failed to extract room data');
  }

  return data;
}

async getBoundingBox(dbId) {
  const model = this.viewer.model;
  const it = model.getInstanceTree();
  const fragList = model.getFragmentList();
  let bounds = new THREE.Box3();

  it.enumNodeFragments(dbId, (fragId) => {
    let box = new THREE.Box3();
    fragList.getWorldBounds(fragId, box);
    bounds.union(box);
  }, true);

  return bounds;
}

With that, we can loop through the rooms (waiting for the transition to finish) to generate each image.

generated images

generated images

Limitations

For this workflow to work, your Revit file needs to be converted generating the master views (that contains the rooms information). You can find that explained in this lightning talk. Also, for it to load the master view first, we're using a trick, just like in the snippet below:

function findMasterViews(viewable) {
  var masterViews = [];
  // master views are under the "folder" with this UUID
  if (viewable.data.type === 'folder' && viewable.data.name === '08f99ae5-b8be-4f8d-881b-128675723c10') {
    return viewable.children;
  }
  if (viewable.children === undefined) return;
  viewable.children.forEach((children) => {
    var mv = findMasterViews(children);
    if (mv === undefined || mv.length == 0) return;
    masterViews = masterViews.concat(mv);
  })
  return masterViews;
}

Since the execution generates one image for each room, you'll need to allow this app to download all these files.

aps-viewer-rooms-screenshots's People

Contributors

joaomartins-callmejohn avatar

Watchers

 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.