Giter Site home page Giter Site logo

Brainstorm libf3d API about f3d HOT 23 CLOSED

f3d-app avatar f3d-app commented on May 13, 2024
Brainstorm libf3d API

from f3d.

Comments (23)

Meakk avatar Meakk commented on May 13, 2024 1

Here are my inputs.
libf3d usage should allow the user to call something like that:

f3d::window w = f3d::createWindow(f3d::context ctx); // create window (external, native, android ...)
w.addFile("/path/file.vtp"); // add a file
w.addFolder("/path"); // add all the files in folder
w.setActiveFile(int index); // set the active file
w.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)
w.clear(); // remove all files
w.render(); // render the scene
w.saveTofile("/path/image.png"); // save the rendered image
w.setKeyCallBack([](int keyCode, int modifier) {
  // do something
  });
w.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
w.setMotionCallBack([](float whatever) {
  // do something on Android
  });

It also means that the interactor should be moved to the executable, but it makes sense to me.
The API is clear, simple, and it's easy to remove/add options without breaking the compilation on the user side. Maybe providing an equivalent API in C would be useful too.
The list I provided is most likely incomplete.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024 1

I think it would be better to separate loading data and rendering data. here is a proposition:

f3d::options opt;
opt.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)

f3d::loader load;
load.setOptions(opt);
load.addFile("/path/file.vtp"); // add a file
load.addFolder("/path"); // add all the files in folder
load.setActiveFile(int index); // set the active file

f3d::interactor interact
interact.setKeyCallBack([](int keyCode, int modifier) {
  // do something
  });
interact.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
interact.setMotionCallBack([](float whatever) {
  // do something on Android
  });

f3d::window win (f3d::context ctx); // create window (external, native, android ...)
win.setOptions(opt)
win.setLoader(load);
win.setInteractor(interact);
win.render(); // render the scene
win.saveTofile("/path/image.png"); // save the rendered image

I dont really care about C bindings, python bindings would be much more important imo.

from f3d.

Meakk avatar Meakk commented on May 13, 2024 1

I still think providing C functions can be useful, for C programmers of course, but it will make other bindings easier, like Rust for instance: https://stackoverflow.com/questions/52923460/how-to-call-a-c-dynamic-library-from-rust

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024 1

Haha, nice screenshot 👍

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024 1

Yes, any options will be changeable dynamically when all is implemented.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024 1

@Meakk updated with your suggestions

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Ignoring completelly how libf3d and f3d are currently implemented, let's consider the fonctionnality we want to provide as a lib.

Features:

  • Set a list of options
  • Read a file
  • Display resuting scene using file and options in a OpenGL context, potentially provided by user

Restrictions:

  • User must not need to find_package VTK to use libf3d or use any vtk* class
  • User does not need to know much about rendering to use libf3d

inputs @Meakk ?

from f3d.

Meakk avatar Meakk commented on May 13, 2024

I agree, VTK should be a private dependency of libf3d.
Ideally, f3d executable should only provide the command-line parsing, and config file management.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

So trying to link it with current implementation, we could have the following rough public API

F3DOptions
  SetFoo
  SetBar

F3DFileLoader(F3DOptions)
  AddFile

F3DViewer(F3DOptions, F3DFileLoader)
  Show

from f3d.

Meakk avatar Meakk commented on May 13, 2024

@mwestphal I like it! Regarding bindings, we will need Java bindings too for Android. I will take care of it, don't worry 😛

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Great ! Lets focus on this one when we find the time. We may want to merge into a dedicated branch until it stabilize.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Interesting.

from f3d.

SamuelTallet avatar SamuelTallet commented on May 13, 2024

Hi, I'm also interested by C functions 😃 Given I write my SketchUp plugins in Ruby, I could use Fiddle to call libf3d from Ruby.
Ruby Fiddle Test
To ease language interoperability and type mapping, I suggest to use JSON as string when value passed or returned is structured.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Discussed API moving forward

f3d::options opt;
opt.setOption("key", "value"); // configure all options using this function (parse the value string inside the function)

f3d::window win (f3d::context ctx); // create window (external, native, android ...)

f3d::loader load;
load.setOptions(opt);
load.setWindow(win);
load.addFile("/path/file.vtp"); // add a file
load.addFolder("/path"); // add all the files in folder
load.setActiveFile(int index); // set the active file

f3d::interactor interact
interact.setMouseCallBack([](float dx, float dy, int button) {
  // do something
  });
interact.setMotionCallBack([](float whatever) {
  // do something on Android
  });

win.setInteractor(interact);
win.render(); // render the scene
win.saveTofile("/path/image.png"); // save the rendered image

interact.loop();

from f3d.

SamuelTallet avatar SamuelTallet commented on May 13, 2024

@mwestphal Once model is loaded and rendered, could we access renderer then change things in real time? For instance:

win.render(); // render the scene
ren = win.getRenderer();
cam = ren.getActiveCamera();
cam.setPosition(float x, float y, float z);

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

So a very early version of the API is now in master, I'll try to update the issue to identify the remaining work.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Here is how it looks now:

  f3d::engine eng(f3d::engine::WindowTypeEnum::WINDOW_STANDARD);
  f3d::loader& load = eng.getLoader();
  load.addFile(filepath);
  load.loadFile(f3d::loader::LoadFileEnum::LOAD_CURRENT);
  f3d::window& win = eng.getWindow();
  f3d::interactor& inter = eng.getInteractor();
  inter.start();

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

For anyone following this. We are close to completion of the first version of the API. stay tuned.

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

store init value in f3d::options for easier reset ?

not needed

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

(Optional) introduce f3d::config in libf3d ?

not needed

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

(optional) expand f3d_interactor to support user set behavior for many more context

Not needed, for now

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

Doc item in their own issue: #48

from f3d.

mwestphal avatar mwestphal commented on May 13, 2024

All items have been adressed, closing.

from f3d.

Related Issues (20)

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.