~wahn

Berlin, Germany

https://www.janwalter.org/

I worked for Autodesk, Paramex, The Mill, NVIDIA, mental images, Digital Domain, Mill Film, MPC, NaN, and Fraunhofer.

Trackers

~wahn/rs-blender

Last active 2 years ago

~wahn/rs-pbrt

Last active 2 years ago

#6 [blend_info] C bindings 2 years ago

Comment by ~wahn on ~wahn/rs-blender

I'm going to close this ticket. I did write a blog post describing the problem and a start how to attack it here:

https://www.janwalter.org/jekyll/rust/libblendinfo/2022/05/10/libblendinfo.html

I linked to that blog post in the Rust user community:

https://users.rust-lang.org/t/libblendinfo-return-information-from-rust-crate-to-c-library/76082

And finally I talked about the problem and how to solve it on Reddit:

https://www.reddit.com/r/rust/comments/uxdcrg/libblendinfo_return_information_from_rust_crate/

https://www.reddit.com/r/rust/comments/uxm6e8/how_to_return_bytes_from_a_rust_crate_to_cc/

So, the C bindings will be in this git repository:

https://git.sr.ht/~wahn/libblendinfo

The current state is:

From C (see example folder) you can ask e.g. for the bytes of a Camera struct, Rust will deal with reading the .blend file and returns a bunch of bytes (in a way that you can query the length of the returned vector of u8 values). The standalone blend_info program can be used to create a C struct in a header file:

https://git.sr.ht/~wahn/blend_info

Another header file (for the C bindings) can be created via the Rust crate safer-ffi:

https://crates.io/crates/safer-ffi

Have a look at the example code (camera.c):

#include <stdio.h>
#include "blendinfo.h"
#include "camera_v279.h"

int main(void) {
  char* filename = "blend/factory_v279.blend";
  char* camera = "Camera";
  // call Rust function                                                                                                                                       
  Vec_uint8_t bytes_read = extract_struct(filename, camera);
  // print returned bytes information                                                                                                                         
  printf("########################################\n");
  printf("%d bytes received from Rust\n", bytes_read.len);
  int i;
  for (i = 0; i < bytes_read.len; i++) {
    uint8_t byte_read = bytes_read.ptr[i];
    if (byte_read) {
      printf("bytes_read[%d] = %d\n", i, byte_read);
    }
  }
  // blend_info -n Camera blend/factory_v279.blend > examples/camera_v279.h                                                                                   
  // 1. replace unknown types/structs by char some_name[byte_count];                                                                                          
  // 2. replace pointers by void* pointers                                                                                                                    
  // 3. cast pointer to struct defined in header                                                                                                              
  struct Camera_v279* cam_v279 = (struct Camera_v279*) bytes_read.ptr;
  // print some float values from Camera struct (for Blender v2.79)                                                                                           
  printf("########################################\n");
  printf("Camera.clipsta = %f\n", cam_v279->clipsta);
  printf("Camera.clipend = %f\n", cam_v279->clipend);
  printf("Camera.lens = %f\n", cam_v279->lens);
}

The C bindings are not done (yet), but the git repository exists and there is a clear path for further development, therefore:

Ticket closed

REPORTED RESOLVED FIXED

#6 [blend_info] C bindings 2 years ago

Comment by ~wahn on ~wahn/rs-blender

Jan Walter referenced this ticket in commit eed43cb.

#6 [blend_info] C bindings 2 years ago

Comment by ~wahn on ~wahn/rs-blender

An example would be this Rust library (crate):

https://github.com/greyblake/whatlang-rs

And the C bindings for it:

https://github.com/greyblake/whatlang-ffi

More information about how this was done can be found here:

https://www.greyblake.com/blog/exposing-rust-library-to-c/

#6 [blend_info] C bindings 2 years ago

task added by ~wahn on ~wahn/rs-blender

#6 [blend_info] C bindings 2 years ago

~wahn assigned ~wahn to #6 on ~wahn/rs-blender

#6 [blend_info] C bindings 2 years ago

Ticket created by ~wahn on ~wahn/rs-blender

Can the Rust crate blend_info be wrapped in a way that it can be used from within C?

#5 Material.emit and Blender version 3.0.0 2 years ago

on ~wahn/rs-blender

CONFIRMED RESOLVED FIXED

#4 Matrix values 2 years ago

on ~wahn/rs-blender

CONFIRMED RESOLVED FIXED

#3 [bug] calc_mem_tlen reports wrong size 2 years ago

on ~wahn/rs-blender

CONFIRMED RESOLVED FIXED

#1 Camera information using DNA 2 years ago

on ~wahn/rs-blender

CONFIRMED RESOLVED FIXED