connectome-neuprint / neuVid

Generates neuroscience videos from high-level descriptions using Blender or VVDViewer.
Other
26 stars 7 forks source link

Support Blender 4 #161

Closed hubbardp closed 1 month ago

hubbardp commented 11 months ago

The new version 4 of Blender has some breaking changes to the Python API that prevent neuVid from working. For example, importMeshes.py fails because bpy.ops.import_scene.obj no longer exists, probably having been replaced with bpy.ops.wm.obj_import.

hubbardp commented 11 months ago

The latest changes seem to be working pretty well in Blender 4, thanks to @floesche!

JackieZhai commented 6 months ago

Hi, Philip @hubbardp!

I tried the latest importMeshes.py in MacOS, but still received errors about "Principled BSDF":

Blender 4.0.1 (hash d0dd92834a08 built 2023-11-17 00:31:48)
neuVid 1.44.3

ERROR: cannot import neuron file '.../1654068522.obj' for ID 1654068522:

'bpy_prop_collection[key]: key "Principled BSDF" not found'

Currently, my solution is using Blender 3 from https://download.blender.org/release/Blender3.6/.

hubbardp commented 6 months ago

Thanks for reporting the issue. Would you be able to share the input JSON file that triggered the problem? I have tried my own JSON input but I cannot reproduce the error so far. I found that body ID, 1654068522, in the hemibrain data set on neuPrint. So I switched to its Neuroglancer view, copied the URL and ran neuVid's importNg.py to get this JSON:

{
  "neurons": {
    "source": "https://hemibrain-dvid.janelia.org/api/node/31597/segmentation_meshes",
    "n1": [1654068522]
  },
  "animation": [
    ["frameCamera", {"bound": "neurons"}],
    ["orbitCamera", {"duration": 10}]
  ]
}

Running importMeshes.py with this JSON input seems to work fine, though. I'm using the same version of Blender on macOS as you, I believe:

Blender 4.0.1 (hash d0dd92834a08 built 2023-11-17 00:31:48)
JackieZhai commented 6 months ago

Thank you for your quick reply!

Interestingly, when I tried to reproduce the issue by the JSON you provided above, I found the cause: Blender's language settings.

When set to Chinese:

Blender 4.0.1 (hash d0dd92834a08 built 2023-11-17 00:31:48)
Read prefs: "/Users/haozhai/Library/Application Support/Blender/4.0/config/userpref.blend"
neuVid 1.44.3
Using output Blender file: './hemibrain_test.blend'
Using SWC cross-sectional vertex count: 12
Using SWC axon radius factor: 10
Using SWC dendrite radius factor: 15
Parsing neuron IDs...
Done
Using separate .blend files for neurons: False
Assigning colors...
Done
Importing 1 neuron meshes
Downloading mesh from https://hemibrain-dvid.janelia.org/api/node/31597/segmentation_meshes/key/1654068522.ngmesh
0: 0 / 1 (11.94 secs)
OBJ import of '1654068522.obj' took 215.7 ms
Added object 'Neuron.1654068522'

ERROR: cannot import neuron file '/Volumes/dc2TB0/OurCode/blender/neuVidNeuronMeshes/1654068522.obj' for ID 1654068522:

'bpy_prop_collection[key]: key "Principled BSDF" not found'
Done
Computing bounding boxes for neuron meshes...
Done
Assigning ROI materials...
Importing synapse meshes...
Done
Assigning synapse materials...
Done
Adding bounds...
Done
Writing /Volumes/dc2TB0/OurCode/blender/./hemibrain_test.blend
信息: 文件总数 0 | 更改 0 项 | 失败 0 项
信息: 已保存 "hemibrain_test.blend"

Importing started at 2024-04-29 21:49:15.246485
Importing ended at 2024-04-29 21:49:27.557228
Elapsed time: 0:00:12.310743

ERROR: could not download/find mesh .obj files for the following neurons:
[1654068522]

Blender quit

When set to English (default):

Blender 4.0.1 (hash d0dd92834a08 built 2023-11-17 00:31:48)
Read prefs: "/Users/haozhai/Library/Application Support/Blender/4.0/config/userpref.blend"
neuVid 1.44.3
Using output Blender file: './hemibrain_test.blend'
Using SWC cross-sectional vertex count: 12
Using SWC axon radius factor: 10
Using SWC dendrite radius factor: 15
Parsing neuron IDs...
Done
Using separate .blend files for neurons: False
Assigning colors...
Done
Importing 1 neuron meshes
Downloading mesh from https://hemibrain-dvid.janelia.org/api/node/31597/segmentation_meshes/key/1654068522.ngmesh
0: 0 / 1 (18.17 secs)
OBJ import of '1654068522.obj' took 175.8 ms
Added object 'Neuron.1654068522'
Added material 'Material.Neuron.1654068522'
Done
Computing bounding boxes for neuron meshes...
Done
Assigning ROI materials...
Importing synapse meshes...
Done
Assigning synapse materials...
Done
Adding bounds...
Done
Writing /Volumes/dc2TB0/OurCode/blender/./hemibrain_test.blend
Info: Total files 0 | Changed 0 | Failed 0
Info: Saved "hemibrain_test.blend"

Importing started at 2024-04-29 21:54:34.065609
Importing ended at 2024-04-29 21:54:52.562779
Elapsed time: 0:00:18.497170

Blender quit
hubbardp commented 1 month ago

Blender 4.1 and 4.2 seem to be working pretty well (especially with the fix for assembleFrames.py) so I am closing this issue.