Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is that possible to create a mesh sequence from Python script, i.e. without loading from a file? #104

Open
archibate opened this issue Aug 20, 2020 · 7 comments

Comments

@archibate
Copy link

archibate commented Aug 20, 2020

Is your feature request related to a problem? Please describe.
Hi, I'm freshman to both Blender and Stop-motion-OBJ.
Recently I'm working on integrating Taichi into Blender. So that people could make use their own physics engines based on Taichi in Blender.
And it's usually the case that Taichi + Blender users don't want to import a mesh sequence from disk, but generate a mesh sequence via Taichi instead.
So I'd like to add a possibility to create a mesh sequence from Python scripting module.

Describe the solution you'd like
Add an API like this:

import bpy
object = bpy.context.object
for frame in range(250):
  x = ... (creating a new mesh)
  object.mesh_sequence_settings.append_mesh(x)

Describe alternatives you've considered
We may do them in pure end-user Python script manipulating mesh_sequence_settings members.

Additional context
For now I use an external script to generate a series of PLY file for creating empty meshes:

import taichi as ti
import numpy as np

n_frames = 250
output = '/tmp/particles.ply'

for frame in range(n_frames):
    print('generating frame', frame)
    writer = ti.PLYWriter(num_vertices=1)
    writer.add_vertex_pos(np.zeros(1), np.zeros(1), np.zeros(1))
    writer.export_frame(frame, output)

and import them into Blender for creating a mesh sequence of length 250.

@neverhood311
Copy link
Owner

That's an interesting idea. I think it's entirely possible.

How would your mesh data be formatted? According to this stack exchange post, Blender can create a mesh from an array of vertex positions (formatted like this: [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)]) and an array of faces (formatted as arrays of vertex indices like this: [[0, 1, 2]]). If the mesh data is formatted like this, I think it would be fairly straightforward to add the desired API.

@archibate
Copy link
Author

(formatted like this: [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)]) and an array of faces (formatted as arrays of vertex indices like this: [[0, 1, 2]])

Exactly! I will create the meshes first according to that post, and fed the meshes to the API here.

@neverhood311
Copy link
Owner

Ok, I'll see what I can do. I can't promise a timeline, though.

@archibate
Copy link
Author

archibate commented Aug 21, 2020

And what's more, can we use the streaming mechanism, to only generate a frame when requested? Something like:

def on_request_frame(frame):
  mesh = ...  # generate a mesh via Taichi
  return mesh

object.mesh_sequence_settings.set_frame_callback(on_request_frame, mode='streaming')

@neverhood311
Copy link
Owner

neverhood311 commented Aug 21, 2020 via email

@neverhood311
Copy link
Owner

@archibate Are you still working on TaiChi-Blender integration? I'm finally getting around to some Stop Motion OBJ development. I'm working on a feature that lets you create an empty mesh sequence then add new frames to the sequence on-the-fly. Did you still want to integrate with this addon or have you taken a different route?

@archibate
Copy link
Author

@archibate Are you still working on TaiChi-Blender integration? I'm finally getting around to some Stop Motion OBJ development. I'm working on a feature that lets you create an empty mesh sequence then add new frames to the sequence on-the-fly. Did you still want to integrate with this addon or have you taken a different route?

Yes, thank for the great project! I studied your addon source code carefully and succeed to support mesh sequence on my own by hooking frame_change_pre. But I have some trouble when saving the mesh sequence (only the mesh at current frame is saved), though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants