USD Import - camera field of view wrong #100028

Closed
opened 2022-07-27 16:59:26 +02:00 by Russ Andersson · 11 comments

The USD camera import does not produce a usable camera. It sets the focal length, but not the camera sensor size (horizontal and vertical aperture), so the camera field of view is wrong all of the time. The sensor size information is in the USD file, but is ignored for perspective cameras. Setting these two values is essential to a camera import, not optional, ie this is a bug, not a new feature.

If you accept the focal length as having arbitrary unknown units, you can and must do the same thing for sensor size/aperture. Since the values are generally not in mm, the user's recourse is to enter the values into blender manually after locating the correct aperture values using usdview or by converting to USDA and opening the file in a text editor and hunting them down.

There's an additional hazard: blender limits sensor size to 1 to 100 mm. Due to USD's definition of FL/HA/VA units, the sensor size (and/or FL) may (often) fall outside that range. If the value is outside the valid range, the USD camera importer should simply rescale FL, HA, and VA by the same value, chosen to bring them in range.

https://developer.blender.org/diffusion/B/browse/master/source/blender/io/usd/intern/usd_reader_camera.cc
https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/BKE_camera.h

The USD camera import does not produce a usable camera. It sets the focal length, but not the camera sensor size (horizontal and vertical aperture), so the **camera field of view is wrong all of the time**. The sensor size information is in the USD file, but is ignored for perspective cameras. Setting these two values is essential to a camera import, not optional, ie this is a bug, not a new feature. If you accept the focal length as having arbitrary unknown units, you can and must do the same thing for sensor size/aperture. Since the values are generally not in mm, the user's recourse is to enter the values into blender manually after locating the correct aperture values using usdview or by converting to USDA and opening the file in a text editor and hunting them down. There's an additional hazard: blender limits sensor size to 1 to 100 mm. Due to USD's definition of FL/HA/VA units, the sensor size (and/or FL) may (often) fall outside that range. If the value is outside the valid range, the USD camera importer should simply rescale FL, HA, and VA by the same value, chosen to bring them in range. https://developer.blender.org/diffusion/B/browse/master/source/blender/io/usd/intern/usd_reader_camera.cc https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/BKE_camera.h
Author

Added subscriber: @ssontech

Added subscriber: @ssontech
Author

Untested example/proposed code change to fix this:

58,59c58,62
<   bcam->sensor_x = horAp.Get<float>();
<   bcam->sensor_y = verAp.Get<float>();
---
>   /* TODO(@makowalski): support sensor size. */
> #if 0
>    bcam->sensor_x = 0.0f;
>    bcam->sensor_y = 0.0f;
> #endif

62,79d64
<   if (bcam->sensor_x != 0.0f && bcam->sensor_y != 0.0f)
<       while (bcam->sensor_x < 1.0f || bcam->sensor_y < 1.0f)
<       {
<         bcam->lens *= 10.0f;
<         bcam->sensor_x *= 10.0f;
<         bcam->sensor_y *= 10.0f;
<         bcam->shiftx *= 10.0f;
<         bcam->shifty *= 10.0f;
<       };
<   while (bcam->sensor_x > 100.0f || bcam->sensor_y > 100.0f)
<   {
<       bcam->lens *= 0.1f;
<       bcam->sensor_x *= 0.1f;
<       bcam->sensor_y *= 0.1f;
<       bcam->shiftx *= 0.1f;
<       bcam->shifty *= 0.1f;
<   };
<
Untested example/proposed code change to fix this: ``` 58,59c58,62 < bcam->sensor_x = horAp.Get<float>(); < bcam->sensor_y = verAp.Get<float>(); --- > /* TODO(@makowalski): support sensor size. */ > #if 0 > bcam->sensor_x = 0.0f; > bcam->sensor_y = 0.0f; > #endif 62,79d64 < if (bcam->sensor_x != 0.0f && bcam->sensor_y != 0.0f) < while (bcam->sensor_x < 1.0f || bcam->sensor_y < 1.0f) < { < bcam->lens *= 10.0f; < bcam->sensor_x *= 10.0f; < bcam->sensor_y *= 10.0f; < bcam->shiftx *= 10.0f; < bcam->shifty *= 10.0f; < }; < while (bcam->sensor_x > 100.0f || bcam->sensor_y > 100.0f) < { < bcam->lens *= 0.1f; < bcam->sensor_x *= 0.1f; < bcam->sensor_y *= 0.1f; < bcam->shiftx *= 0.1f; < bcam->shifty *= 0.1f; < }; < ```
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

I guess the module can mark this as a TODO or a known issue.
Since you seem knowledgeable about this, have you considered submitting a patch yourself? https://wiki.blender.org/wiki/Process/Contributing_Code

I guess the module can mark this as a TODO or a known issue. Since you seem knowledgeable about this, have you considered submitting a patch yourself? https://wiki.blender.org/wiki/Process/Contributing_Code
Author

My proposed change is based on a quick look at this local code only; I have no "big picture" understanding of blender internals at all and may be completely missing some other concern. So my thought is that it's better for an actual USD developer to consider it.

My proposed change is based on a quick look at this local code only; I have no "big picture" understanding of blender internals at all and may be completely missing some other concern. So my thought is that it's better for an actual USD developer to consider it.
Member

Added subscriber: @SonnyCampbell_Unity

Added subscriber: @SonnyCampbell_Unity
Member

@ssontech Have you got a sample USD/blend file to test against? I can happily take a look at this for you

@ssontech Have you got a sample USD/blend file to test against? I can happily take a look at this for you
Author

Sorry for the delay, here's an example file. Images at https://www.ssontech.com/pub/GoingThruPhase.php

phaseExample.zip

Sorry for the delay, here's an example file. Images at https://www.ssontech.com/pub/GoingThruPhase.php [phaseExample.zip](https://archive.blender.org/developer/F13442129/phaseExample.zip)
Sonny Campbell self-assigned this 2022-09-19 15:23:31 +02:00

This issue was referenced by f359a39d11

This issue was referenced by f359a39d11511721c5a201be6f6dcaa6d8780792

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Bastien Montagne added this to the Pipeline, Assets & IO project 2023-02-09 15:40:02 +01:00
Bastien Montagne removed this from the Pipeline, Assets & IO project 2023-02-10 12:49:18 +01:00
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
5 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#100028
No description provided.