BGE KX_GameObject new 'worldDimensions' and 'localDimensions' properties accessible from Python API #42017

Closed
opened 2014-09-29 22:47:33 +02:00 by Razvan Cosmin Radulescu · 23 comments

The Python API misses a "dimensions" property on KX_GameObject. This patch addresses this issue. I don't know if it's the best implementation, but it works.

There are two new functions now:
KX_GameObject:NodeGetWorldDimensions and
KX_GameObject:NodeGetLocalDimensions used to create the new Python accessible variables:

  • worldDimensions (the dimensions of the object on x, y, z relative to the world axis)
  • localDimensions (the dimensions of the object on x, y, z relative to the local axis)

Both new attributes are of type MT_Vector3.

I could not find a simple way to add this to SG_Spatial so instead I'm just calculating the dimensions on the fly in KX_GameObject.KX_GameObject.patch

The Python API misses a "dimensions" property on KX_GameObject. This patch addresses this issue. I don't know if it's the best implementation, but it works. There are two new functions now: KX_GameObject:NodeGetWorldDimensions and KX_GameObject:NodeGetLocalDimensions used to create the new Python accessible variables: * worldDimensions (the dimensions of the object on x, y, z relative to the world axis) * localDimensions (the dimensions of the object on x, y, z relative to the local axis) Both new attributes are of type MT_Vector3. I could not find a simple way to add this to SG_Spatial so instead I'm just calculating the dimensions on the fly in KX_GameObject.[KX_GameObject.patch](https://archive.blender.org/developer/F113655/KX_GameObject.patch)

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @razvanc87

Added subscriber: @razvanc87

Added subscribers: @Moguri, @brita, @Sergey

Added subscribers: @Moguri, @brita, @Sergey

KX_GameObject.patch

Just a quick update: dummy_dimensions are changed to positive values now.

[KX_GameObject.patch](https://archive.blender.org/developer/F113756/KX_GameObject.patch) Just a quick update: `dummy_dimensions` are changed to positive values now.

Added subscriber: @solarlune

Added subscriber: @solarlune
Jorge Bernal was assigned by Sergey Sharybin 2015-02-26 10:54:20 +01:00

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

If I read the code correctly, KX_GameObject::NodeGetWorldDimensions() results in a transformation of the world bounding box to local coordinates, only to convert it back to world coordinates. Seems like a waste.

If I read the code correctly, `KX_GameObject::NodeGetWorldDimensions()` results in a transformation of the world bounding box to local coordinates, only to convert it back to world coordinates. Seems like a waste.

I don't disagree. It's my first try at changing / looking at the Blender code so if anyone has a better idea, please do implement it. Also I need to point out that this won't work for font objects which is a shame. So again, if anyone else knows how to do it or if it's possible then you're more than welcome.

I don't disagree. It's my first try at changing / looking at the Blender code so if anyone has a better idea, please do implement it. Also I need to point out that this won't work for font objects which is a shame. So again, if anyone else knows how to do it or if it's possible then you're more than welcome.
Member

What is the motivation for this? Why would this be useful?
You are returning the dimensions of the bounding box, which is axis aligned and may not correspond to the actual dimensions.
It could be better to store the object's dimensions from Blender during the DataConversion step and try to make sure it doesn't change.

What is the motivation for this? Why would this be useful? You are returning the dimensions of the bounding box, which is axis aligned and may not correspond to the actual dimensions. It could be better to store the object's dimensions from Blender during the DataConversion step and try to make sure it doesn't change.

@brita storing the bounding box during conversion only works when the object doesn't deform. I'm also curious for the motivation.

@brita storing the bounding box during conversion only works when the object doesn't deform. I'm also curious for the motivation.
Member

@dr.sybren I meant storing the dimensions during conversion, because blender does take into account the object space, instead of a bb.
Then for what could change that in runtime... scaling an object? or if it is a softbody or cases that don't even come up to mind easily. So I foresee an easily broken property, without further motivation I'd say not to add.

@dr.sybren I meant storing the dimensions during conversion, because blender does take into account the object space, instead of a bb. Then for what could change that in runtime... scaling an object? or if it is a softbody or cases that don't even come up to mind easily. So I foresee an easily broken property, without further motivation I'd say not to add.

So, for the motivation, I decided to make a dimension property available in BGE because I was programatically creating a tiled map with hexagons and to place the hexagons well obviously I needed to get have the dimensions. It seemed rather weird not to be able to get such a basic property from BGE. The workaround at the time for me was to create the hexagon at the proper dimensions and then apply the scaling and use the scale in BGE instead.

And for the rest... the way I did it I was pretty sure wasn't the correct way to do it, but I had to try anyway.

So, for the motivation, I decided to make a dimension property available in BGE because I was programatically creating a tiled map with hexagons and to place the hexagons well obviously I needed to get have the dimensions. It seemed rather weird not to be able to get such a basic property from BGE. The workaround at the time for me was to create the hexagon at the proper dimensions and then apply the scaling and use the scale in BGE instead. And for the rest... the way I did it I was pretty sure wasn't the correct way to do it, but I had to try anyway.

@brita I was thinking about human characters. When you walk, your bounding box keeps changing in size all the time.

@razvanc87 your "workaround" would actually be my first approach ;-)

@brita I was thinking about human characters. When you walk, your bounding box keeps changing in size all the time. @razvanc87 your "workaround" would actually be my first approach ;-)

@dr.sybren but that only mean that the programmer needs to be careful and aware of this and update the dimensions every frame he makes calculations based on it, no?

@dr.sybren but that only mean that the programmer needs to be careful and aware of this and update the dimensions every frame he makes calculations based on it, no?
Member

@razvanc87 I would also programatically do a grid and place scaled objects there. So all good..
as to have to update the dimensions every frame, are your hexagons changing? It is totally scenario dependent.

@dr.sybren anything rotating about would be changing the dimensions of the GE AABB all the time, and I can not foretell if that is what you want or not, or in what coordinate set.

I'd say that to handle this on top of bge instead of inside is best.

@razvanc87 I would also programatically do a grid and place scaled objects there. So all good.. as to have to update the dimensions every frame, are your hexagons changing? It is totally scenario dependent. @dr.sybren anything rotating about would be changing the dimensions of the GE AABB all the time, and I can not foretell if that is what you want or not, or in what coordinate set. I'd say that to handle this on top of bge instead of inside is best.

@brita I was just making a point to @dr.sybren's statement about the bounding box changes shapes. I didn't need this for my specific scenario

@brita I was just making a point to @dr.sybren's statement about the bounding box changes shapes. I didn't need this for my specific scenario
Jorge Bernal removed their assignment 2015-03-09 07:43:58 +01:00
Member

Added subscriber: @JorgeBernalMartinez

Added subscriber: @JorgeBernalMartinez
Member

Added subscriber: @Blendify

Added subscriber: @Blendify
Member

@razvanc87 can you add this to the differential tool?

@razvanc87 can you add this to the differential tool?

Hi, it's been so long I thought this was dropped. OK... I just did, I hope I did it right: https://developer.blender.org/D1513

Hi, it's been so long I thought this was dropped. OK... I just did, I hope I did it right: https://developer.blender.org/D1513
Member

Yes thank you this should get in the master sooner now

Yes thank you this should get in the master sooner now
Aaron Carlisle self-assigned this 2015-10-06 19:37:19 +02:00
Aaron Carlisle removed their assignment 2015-10-06 19:37:31 +02:00
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Aaron Carlisle self-assigned this 2017-04-14 21:19:04 +02:00
Member

See reply in the patch.

See reply in the patch.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
7 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#42017
No description provided.