Giter Site home page Giter Site logo

Comments (3)

derickson avatar derickson commented on May 24, 2024

workaround: when the model is server side, use https://github.com/lukeapage/pngjs to load the PNG as data and copy the data to the terrain in the terrain init

var fs = require('fs'),
PNG = require('pngjs').PNG;

then the main. call back is necessary as the png io needs to finish before initializing the model

// Loads map resource from object in serial event async nodejs style
fs.createReadStream(model_params.map)
  .pipe(new PNG({filterType: 4}))
  .on("parsed", function () {
      //save the terrain image data into globalThis scope
      globalThis.terrainImage = this;
      
      // now start the simulation
      model.setup();
      run();
  });

then in the setup

  // load the terrain image to the Terrain object
  // works differently for browser vs nodejs
  if(globalThis.isBrowser) {
    modelStuff.terrain.load(model_params.map);
  } else {
    modelStuff.terrain.init((x,y) => {
      var idx = ((width * y) + x) << 2;
      var rv = globalThis.terrainImage.data[idx];
      var gv = globalThis.terrainImage.data[idx + 1];
      var bv = globalThis.terrainImage.data[idx + 2];
      modelStuff.terrain.set(x,y,{r:rv,g:gv,b:bv,a:255});
    });
  }

from flocc.

scottpdo avatar scottpdo commented on May 24, 2024

Hi @derickson pardon my slow reply. While Flocc does attempt to be equally useful in both server and browser contexts, the visualization components really are more browser-focused. It seems like your workaround using pngjs works nicely! One goal of Flocc is to be dependency-free, so I'd want to do a little more work on the Node side to remove that as a dependency, but it seems like that approach would work well.

from flocc.

derickson avatar derickson commented on May 24, 2024

no worries on slow reply, just trying to be a good open source community member. we are in the middle our our hackathon powered by flocc right now. really appreciate you making this project available.

from flocc.

Related Issues (17)

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.