Object.ray_cast (and all RNA functions using "ob->runtime") broken in Blender 2.80 #57861

Closed
opened 2018-11-16 04:53:04 +01:00 by Kofi Garbrah · 21 comments

System Information
Operating system and graphics card
macOS X Mojave with GTX 980

Blender Version
Broken: 2.80. 59f0db430a
Worked: no solution

Short description of error

Object.ray_cast is broken in Blender 2.80.

I have attached a blend that contains a simple ray_cast that works in 2.79 and fails in 2.80. Run blender from a console to see the error messages.

Exact steps for others to reproduce the error
Click Run Script to see the result of ray_cast in Blender 2.80

ray_cast_test.blend

**System Information** Operating system and graphics card macOS X Mojave with GTX 980 **Blender Version** Broken: 2.80. 59f0db430a9 Worked: no solution **Short description of error** Object.ray_cast is broken in Blender 2.80. I have attached a blend that contains a simple ray_cast that works in 2.79 and fails in 2.80. Run blender from a console to see the error messages. **Exact steps for others to reproduce the error** Click Run Script to see the result of ray_cast in Blender 2.80 [ray_cast_test.blend](https://archive.blender.org/developer/F5579003/ray_cast_test.blend)
Author

Added subscriber: @KofiGarbrah

Added subscriber: @KofiGarbrah

blender/blender-addons#58317 was marked as duplicate of this issue

blender/blender-addons#58317 was marked as duplicate of this issue

#59791 was marked as duplicate of this issue

#59791 was marked as duplicate of this issue

blender/blender-addons#59790 was marked as duplicate of this issue

blender/blender-addons#59790 was marked as duplicate of this issue
Author

This comment was removed by @KofiGarbrah

*This comment was removed by @KofiGarbrah*
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Philipp Oeser self-assigned this 2018-11-16 10:42:29 +01:00
Member

Confirmed, will have a look...

Confirmed, will have a look...
Philipp Oeser removed their assignment 2018-11-16 12:20:34 +01:00
Bastien Montagne was assigned by Philipp Oeser 2018-11-16 12:20:34 +01:00
Member

Added subscribers: @mont29, @brecht

Added subscribers: @mont29, @brecht
Member

Hm, seems like since the removal of DerrivedMesh from RNA (79615c5adb) there are a couple of issues.
Checked rna_object_api() and all RNA functions using ob->runtime fail.

rna_Object_ray_cast():

  • fails (says "Object 'bla' has no mesh data to be used for ray casting")

rna_Object_closest_point_on_mesh():

  • fails (says "Object 'bla' has no mesh data to be used for finding nearest point")

rna_Object_me_eval_info():

  • bpy.context.selected_objects- .dm_info("SOURCE") is OK (uses ob->data directly)
  • bpy.context.selected_objects- .dm_info("DEFORM") fails (returns empty string)
  • bpy.context.selected_objects- .dm_info("FINAL") fails (returns empty string)

@mont29: any ideas here (assigning to you first)?
or maybe @brecht can comment?


@KofiGarbrah: As a (temporary) workaround for this report you can create a BVH manually and raycast that:

from mathutils import Vector
from mathutils import Matrix
from math import *
from mathutils.bvhtree import BVHTree

def bvhtree_from_object(ob):
    import bmesh
    bm = bmesh.new()

    mesh = ob.to_mesh(bpy.context.depsgraph, True)
    bm.from_mesh(mesh)
    bm.transform(ob.matrix_world)

    bvhtree = BVHTree.FromBMesh(bm)
    bpy.data.meshes.remove(mesh)
    return bvhtree

mesh = None
for obj in bpy.context.selected_objects:
    if obj.type == "MESH":
        mesh = obj

if mesh == None:
    bpy.ops.mesh.primitive_cube_add(location=(0,0,0))
    for obj in bpy.context.selected_objects:
        if obj.type == "MESH":
            mesh = obj

startRay = Vector((-2,-2,-2))
endRay = Vector((2,2,2))

p = endRay - startRay
distance = sqrt(p.dot(p))
direction = p / distance

print( "start", startRay, "end", endRay, "distance", distance, "direction", direction )

bvhtree = bvhtree_from_object(mesh)

ray = bvhtree.ray_cast( startRay, direction, distance )

print( "Hits:", ray )
Hm, seems like since the removal of DerrivedMesh from RNA (79615c5adb) there are a couple of issues. Checked `rna_object_api()` and all RNA functions using `ob->runtime` fail. **rna_Object_ray_cast()**: - fails (says "Object 'bla' has no mesh data to be used for ray casting") **rna_Object_closest_point_on_mesh()**: - fails (says "Object 'bla' has no mesh data to be used for finding nearest point") **rna_Object_me_eval_info()**: - bpy.context.selected_objects- [x].dm_info("SOURCE") is OK (uses `ob->data` directly) - bpy.context.selected_objects- [x].dm_info("DEFORM") fails (returns empty string) - bpy.context.selected_objects- [x].dm_info("FINAL") fails (returns empty string) ----- @mont29: any ideas here (assigning to you first)? or maybe @brecht can comment? ----- @KofiGarbrah: As a (temporary) workaround for this report you can create a BVH manually and raycast that: ``` from mathutils import Vector from mathutils import Matrix from math import * from mathutils.bvhtree import BVHTree def bvhtree_from_object(ob): import bmesh bm = bmesh.new() mesh = ob.to_mesh(bpy.context.depsgraph, True) bm.from_mesh(mesh) bm.transform(ob.matrix_world) bvhtree = BVHTree.FromBMesh(bm) bpy.data.meshes.remove(mesh) return bvhtree mesh = None for obj in bpy.context.selected_objects: if obj.type == "MESH": mesh = obj if mesh == None: bpy.ops.mesh.primitive_cube_add(location=(0,0,0)) for obj in bpy.context.selected_objects: if obj.type == "MESH": mesh = obj startRay = Vector((-2,-2,-2)) endRay = Vector((2,2,2)) p = endRay - startRay distance = sqrt(p.dot(p)) direction = p / distance print( "start", startRay, "end", endRay, "distance", distance, "direction", direction ) bvhtree = bvhtree_from_object(mesh) ray = bvhtree.ray_cast( startRay, direction, distance ) print( "Hits:", ray ) ```
Philipp Oeser changed title from Object.ray_cast broken in Blender 2.80 to Object.ray_cast (and all RNA functions using "ob->runtime") broken in Blender 2.80 2018-11-16 12:21:55 +01:00

Imho there is no bug here… that has more to see with how blender/depsgraph/CoW work now in 2.8. Original data (from Main, of bpy.data in python) is not supposed to have evaluated stuff, although we do 'backport' a few things for objects…

You should use context's despgraph object, something like:

start_ray = (-2, -2, -2)
dir_ray = (1, 0, 0)

depsgraph = bpy.context.depsgraph
for obj in bpy.context.selected_objects:

if obj.type == "MESH":
obj_eval = depsgraph.objects.get(obj.name, None)
if obj_eval is not None:
print(obj_eval.ray_cast(start_ray, dir_ray))

Imho there is no bug here… that has more to see with how blender/depsgraph/CoW work now in 2.8. Original data (from Main, of `bpy.data` in python) is not supposed to have evaluated stuff, although we do 'backport' a few things for objects… You should use context's despgraph object, something like: ```lang=python start_ray = (-2, -2, -2) dir_ray = (1, 0, 0) depsgraph = bpy.context.depsgraph for obj in bpy.context.selected_objects: ``` if obj.type == "MESH": obj_eval = depsgraph.objects.get(obj.name, None) if obj_eval is not None: print(obj_eval.ray_cast(start_ray, dir_ray)) ```

I would expect this ray cast function to get a depsgraph parameter, which it will then look up the object in. That will at least make it more clear to users what is missing.

I would expect this ray cast function to get a depsgraph parameter, which it will then look up the object in. That will at least make it more clear to users what is missing.
Author

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author

Thanks for the workarounds! I've marked this as resolved.

Thanks for the workarounds! I've marked this as resolved.

Added subscribers: @Darcvizer, @MichelAnders

Added subscribers: @Darcvizer, @MichelAnders

Changed status from 'Resolved' to: 'Open'

Changed status from 'Resolved' to: 'Open'

Somehow missed @brecht's comment, indeed think that would be a nice addition, will do that now.

Somehow missed @brecht's comment, indeed think that would be a nice addition, will do that now.

This issue was referenced by 61cb1a81a8

This issue was referenced by 61cb1a81a84c8a10c5abfb86011de9ea4bb2aa3d

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

We can even use depsgraph from context, in fact, should work perfect for 99% of usecases ;)

We can even use depsgraph from context, in fact, should work perfect for 99% of usecases ;)
Member

Just tested it with the daily build (blender-2.80-e4dbfe0a98c1-linux-glibc224-x86_64) and repeatedly ray casting on the bvh now works but if I invoke the operator again (and create a new bvh from the same object) I get a segmentation fault. I'll create a separate bug report that references this one just in case this is not related.

Just tested it with the daily build (blender-2.80-e4dbfe0a98c1-linux-glibc224-x86_64) and repeatedly ray casting on the bvh now works but if I invoke the operator again (and create a new bvh from the same object) I get a segmentation fault. I'll create a separate bug report that references this one just in case this is not related.
Added subscribers: @Vax456, @Sherm, @capnm, @Joefelix, @Dragon.Studio, @JacquesLucke
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#57861
No description provided.