NVlabs / latentfusion

LatentFusion: End-to-End Differentiable Reconstruction and Rendering for Unseen Object Pose Estimation
https://arxiv.org/pdf/1912.00416.pdf
Other
213 stars 34 forks source link

Questions about Blender software version #12

Closed vtasStu closed 3 years ago

vtasStu commented 3 years ago

Tanks for your great work. When I was running blender -P tools/dataset/preprocess_shapenet.py -- "$SHAPENET_PATH" "$OUT_PATH" --strip-materials --out-name ShapeNetCore-nomat I get error about: AttributeError: 'Context' object has no attribute 'view_layer'. I have searched this error on Google, and found that the problem may be in the version of Blender. I use the version of 2.79. What's your version of Blender?

keunhong commented 3 years ago

I think we used Blender 2.8x, which IIRC was when they made some massive changes.

vtasStu commented 3 years ago

I think we used Blender 2.8x, which IIRC was when they made some massive changes.

Hi, I have tried to run the script on three versions of Blender: 2.79, 2.83, 2.91. When I was running in 2.83 and 2.91, I got the same erorr about

Traceback (most recent call last):
  File "/media/vtas/WIN/mycode/python_code/latentfusion-master/tools/dataset/preprocess_shapenet.py", line 110, in <module>
    main()
  File "/media/vtas/WIN/mycode/python_code/latentfusion-master/tools/dataset/preprocess_shapenet.py", line 72, in main
    bpy.ops.object.mode_set(mode='EDIT')
  File "/usr/local/blender-2.83.12-linux64/2.83/scripts/modules/bpy/ops.py", line 201, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect

I ran in the ShapeNetCore.v2 download from https://www.shapenet.org/download/shapenetcore. Maybe the problem is in the dataset. What about your Shapenet dataset.

vtasStu commented 3 years ago

I solved this problem by modifying the script.

mimichu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

vtasStu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

mimichu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

Thanks a lot for the reference! Did you solve it by commenting out that line?

vtasStu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

Thanks a lot for the reference! Did you solve it by commenting out that line?

I solve the problem by replacing the code, not just commenting out the line, because you need to clear some of the data.

mimichu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

Thanks a lot for the reference! Did you solve it by commenting out that line?

I solve the problem by replacing the code, not just commenting out the line, because you need to clear some of the data.

Thanks a lot! I tried the change but I am still getting the same error. This is what I did: I replaced bpy.ops.wm.read_factory_settings(use_empty=True) with reset_blend() function as referenced by your pointer. To make it work for Blender 2.83, I modified the reset_blend() a bit, it looks like this now:

def reset_blend():
    bpy.ops.wm.read_factory_settings()

    # modified based on https://blender.stackexchange.com/questions/162256/bpy-prop-collection-object-has-no-attribute-link/162417
    for collection in bpy.data.collections:
        for obj in collection.objects:
            collection.objects.unlink(obj)

    # only worry about data in the startup scene
    for bpy_data_iter in (
            bpy.data.objects,
            bpy.data.meshes,
            bpy.data.lights, # modified from bpy.data.lamps
            bpy.data.cameras,
    ):
        for id_data in bpy_data_iter:
            bpy_data_iter.remove(id_data)

And with this change, I am still getting the RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect error. Is this the same as the fix you used?

vtasStu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

Thanks a lot for the reference! Did you solve it by commenting out that line?

I solve the problem by replacing the code, not just commenting out the line, because you need to clear some of the data.

Thanks a lot! I tried the change but I am still getting the same error. This is what I did: I replaced bpy.ops.wm.read_factory_settings(use_empty=True) with reset_blend() function as referenced by your pointer. To make it work for Blender 2.83, I modified the reset_blend() a bit, it looks like this now:

def reset_blend():
    bpy.ops.wm.read_factory_settings()

    # modified based on https://blender.stackexchange.com/questions/162256/bpy-prop-collection-object-has-no-attribute-link/162417
    for collection in bpy.data.collections:
        for obj in collection.objects:
            collection.objects.unlink(obj)

    # only worry about data in the startup scene
    for bpy_data_iter in (
            bpy.data.objects,
            bpy.data.meshes,
            bpy.data.lights, # modified from bpy.data.lamps
            bpy.data.cameras,
    ):
        for id_data in bpy_data_iter:
            bpy_data_iter.remove(id_data)

And with this change, I am still getting the RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect error. Is this the same as the fix you used?

Since a lot of time has passed, I don't have the backup code, so I don't remember exactly how I changed it. Read all the answers below this link thoroughly and I believe in you can find the Q&A.

mimichu commented 3 years ago

@vtasStu I ran into the same error, would you mind sharing how you fixed it in the script? Thanks!

The error is caused by bpy.ops.wm.read_factory_settings(use_empty=True) . The solution can be referenced in this

Thanks a lot for the reference! Did you solve it by commenting out that line?

I solve the problem by replacing the code, not just commenting out the line, because you need to clear some of the data.

Thanks a lot! I tried the change but I am still getting the same error. This is what I did: I replaced bpy.ops.wm.read_factory_settings(use_empty=True) with reset_blend() function as referenced by your pointer. To make it work for Blender 2.83, I modified the reset_blend() a bit, it looks like this now:

def reset_blend():
    bpy.ops.wm.read_factory_settings()

    # modified based on https://blender.stackexchange.com/questions/162256/bpy-prop-collection-object-has-no-attribute-link/162417
    for collection in bpy.data.collections:
        for obj in collection.objects:
            collection.objects.unlink(obj)

    # only worry about data in the startup scene
    for bpy_data_iter in (
            bpy.data.objects,
            bpy.data.meshes,
            bpy.data.lights, # modified from bpy.data.lamps
            bpy.data.cameras,
    ):
        for id_data in bpy_data_iter:
            bpy_data_iter.remove(id_data)

And with this change, I am still getting the RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect error. Is this the same as the fix you used?

Since a lot of time has passed, I don't have the backup code, so I don't remember exactly how I changed it. Read all the answers below this link thoroughly and I believe in you can find the Q&A.

I see! Thanks a lot for the help!!

shanice-l commented 3 years ago

I think we used Blender 2.8x, which IIRC was when they made some massive changes.

I found that the blender version does really matters, I tried v2.7x and v2.9x, raised all kinds of weird errors. but v2.83 works finally.