GollyGang / ready

A cross-platform implementation of various reaction-diffusion systems and PDEs.
GNU General Public License v3.0
755 stars 60 forks source link

import_obj_sequence.py doesn't work with Blender 2.82 #136

Closed timhutton closed 3 years ago

schroef commented 3 years ago

One issue i see with this method, is when a user saves his scene and then reopens it. The handler is gone and it thus will not playback. At first this method seems very simple and handy. But it is kinda limiting. I made a note of the stop-motion addon, this one works quite nice, has more feats then my approach.

https://docs.blender.org/api/current/bpy.app.handlers.html

schroef commented 3 years ago

I tried my code which i was working on to delete objects in the scene faster. I could use it to make the handler run again when reopening a saved file. The user would need to comment out the import part. adding a boolean for that would make it simpler.

But again, stop-motion addon has everything working really nice.

scn = bpy.context.scene.objects
readySeq = "TipSplitting-3d"
for ob in scn:
    for i in range(0,len(obj_files)):
        if(ob.name == readySeq + "_000"+(f'{i:03}')):
            objs.append(ob)

Note that those leading zero are probably different per file or are they always 6 digits?

schroef commented 3 years ago

I made a some adjustments to your updated importer. In the top of the code i added an importFiles boolean. Now a user can set this to True when they want to import. Then when files is saved and closed, the user can set it to False and it skips the import and does apply the handler again.

Hope you dont mind the adjustments

#  A Blender script to import a sequence of OBJ meshes into an animation.
#
# ------------------------------------------------------------------------
#  Copyright 2011-2021 The Ready Bunch
#
#  This file is part of Ready.
#
#  Ready is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Ready is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Ready. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------

# Usage:
# In Blender, change one of the panels into a Text Editor (using the icon on the left with the up/down arrow)
# Hit 'New' and paste in the script.
# Edit the 'path' string to be the folder where your OBJ files live.
# Hit 'Run Script'
# It should load all the OBJ files it found and add keyframes for them.
# (If the script gives errors, use Window > Toggle System Console to see them.)
# Hit the 'Play animation' button in the Timeline panel and your mesh should start animating.
# Set up the camera and lighting and use Render > Render animation.

import bpy
import glob

readySeq = "TipSplitting-3d"
importFiles = False
#path = 'c:/Ready_frames/*.obj'      # <------- Change this to the folder with your OBJ files

obj_files = glob.glob( path )

if len(obj_files)==0:
    print('ERROR: No files in path: ' + path)

if bpy.data.materials.get("Material") is not None:
    mat = bpy.data.materials["Material"]
else:
    mat = bpy.data.materials.new(name="Material")

# load the objects
objs = []
for iObj,fn in enumerate(obj_files):
    if importFiles:
        bpy.ops.import_scene.obj( filepath=fn )
        ob = bpy.context.selected_editable_objects[0]
        objs.append(ob)
    else:
        objName = readySeq + "_000"+(f'{iObj:03}')
        bpy.context.view_layer.objects.active = bpy.data.objects[objName]
        ob=bpy.context.active_object
        ob.hide_render = ob.hide_viewport = True
        if(ob.name == readySeq + "_000"+(f'{iObj:03}')):
            objs.append(ob)

    # assign the same material to all frames
    ob.data.materials.clear()
    ob.data.materials.append(mat)

bpy.context.scene.frame_start = 0
bpy.context.scene.frame_end = len(objs)-1

def frame_change(self):
    i_frame = int(self.frame_current)
    for i_ob, ob in enumerate(objs):
        if i_ob == i_frame:
            ob.hide_render = ob.hide_viewport = False
        else:
            ob.hide_render = ob.hide_viewport = True

bpy.app.handlers.frame_change_pre.append(frame_change)
timhutton commented 3 years ago

No, that's great. Please make a PR.

Or we could delete the script and tell people to use the Add-On you suggested? I haven't tried it yet.

schroef commented 3 years ago

Yeah that otherone is really nice, it has so manhy great options. Do you know that new addon they released for sculptors, with which you can make different sculpts on each frame. Well the backend works kinda of the same. What they do is they switch the mesh data on each frame. So all the obj are imported as mesh data. They then are set to fake users so they wont be deleted once imported. Than a handler switches the data on the flyer when you play.

There is a downside, realtime playback is not very smooth for my older machine when you use a subsurf on the model. But for rendering it would be fine. The addon has many options. I did make some feature request already. hahah i have just played with a bit but already found 1/2 things which could perhaps be improved.

I think perhaps you and others, im not sure with how many people you have this project. Should take a look at that addon. Then decide to keep your own code or simply link to that addon. You could always just keep your script or my addon as default but make it clear that addon has a much easier and richer experience.

These are just suggestions, this is your project and you guys should decide what to do.

schroef commented 3 years ago

I noticed the script has now been removed. Isnt it a good idea to make a remark about that in the readme.md, now its only visible in the commit description, sort of hidden

timhutton commented 3 years ago

I added suggestions and the link here: https://gollygang.github.io/ready/Help/file.html and https://gollygang.github.io/ready/Help/tips.html

schroef commented 3 years ago

Sorry to bother again. it took me some while to find these docs. Why arent they in the Wiki section? I mean if you use md files, the styling could also be better. Currently these docs deel like something of the 90s...

I also think styling these docs is easier, atleast i feel markdown is easier and faster then doing html markup

timhutton commented 3 years ago

I've added a Wiki page too for the Blender topic.

The .html pages are the ones that Ready shows to the users in the Help pane. They are viewable in a browser too but that's not their main purpose. I agree they look a bit 90s.

If there is a viewer for github markdown in wxWidgets then I'd be happy to use .md instead of .html for our help files.

schroef commented 3 years ago

I dont know any about wxWidgets. But markdown is simply said a certain method of "markdown". Its quite easy, if you make up the file and save as .md it shows like proper HTML.

The way i would do it is fork the wiki section and then simply start making those md files. Its much faster then HTML coding, but i guess you would like to have an autocomplete or so

Here's a nice cheatsheet