Skip to content

Commit

Permalink
Merge pull request #2 from beersandrew/fix-bounds
Browse files Browse the repository at this point in the history
feat: fixing bounds calc
  • Loading branch information
beersandrew authored Oct 4, 2023
2 parents e62e715 + 1ba85dc commit 74616e0
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 9 deletions.
Binary file added examples/AntiqueCamera/AntiqueCamera.usdz
Binary file not shown.
28 changes: 28 additions & 0 deletions examples/AntiqueCamera/AntiqueCamera_Cards.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#usda 1.0
(
defaultPrim = "camera"
doc = "Blender v3.6.0"
metersPerUnit = 1
subLayers = [
@AntiqueCamera.usdz@
]
upAxis = "Z"
)

over "camera" (
prepend apiSchemas = ["GeomModelAPI"]
kind = "component"
)
{
uniform bool model:applyDrawMode = 1
uniform token model:cardGeometry = "box"
asset model:cardTextureXNeg = @renders/XNeg.png@
asset model:cardTextureXPos = @renders/XPos.png@
asset model:cardTextureYNeg = @renders/YNeg.png@
asset model:cardTextureYPos = @renders/YPos.png@
asset model:cardTextureZNeg = @renders/ZNeg.png@
asset model:cardTextureZPos = @renders/ZPos.png@
uniform token model:drawMode = "cards"
uniform float3 model:drawModeColor = (1, 0, 0)
}

Binary file added examples/AntiqueCamera/renders/XNeg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/AntiqueCamera/renders/XPos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/AntiqueCamera/renders/YNeg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/AntiqueCamera/renders/YPos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/AntiqueCamera/renders/ZNeg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/AntiqueCamera/renders/ZPos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions src/camera/cameraGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from camera.utils.distanceCalculator import get_distance_to_frame_subject
from camera.globals import APERTURE, FOCAL_LENGTH, FOCUS_DISTANCE

def create_camera_for_card(card, camera_stage, subject_center, bounding_box):
def create_camera_for_card(card, camera_stage, center_of_card_face, bounding_box):
camera_prim = create_camera_with_defaults(camera_stage, card.name)

distance = get_distance_to_frame_subject(bounding_box, APERTURE, FOCAL_LENGTH)

position_camera(camera_prim, card, subject_center, distance)
position_camera(camera_prim, card, center_of_card_face, distance)

calculate_apertures(camera_prim, bounding_box, distance, card)

Expand All @@ -26,12 +26,12 @@ def create_camera_with_defaults(camera_stage, name):

return camera_prim

def position_camera(camera_prim, card, subject_center, distance):
camera_translation = create_camera_translation(card, subject_center, distance)
def position_camera(camera_prim, card, center_of_card_face, distance):
camera_translation = create_camera_translation(card, center_of_card_face, distance)
apply_camera_translation(camera_prim, camera_translation)

def create_camera_translation(card, subject_center, distance):
return subject_center + create_translate_vector(distance * card.sign, card.translationIndex)
def create_camera_translation(card, center_of_card_face, distance):
return center_of_card_face + create_translate_vector(distance * card.sign, card.translationIndex)

def calculate_apertures(camera_prim, bounding_box, distance, card):
flip_aperatures = False
Expand Down
8 changes: 6 additions & 2 deletions src/camera/cameraManager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from pxr import Usd, UsdGeom, UsdLux
from pxr import Usd, UsdGeom, UsdLux, Gf
from collections import namedtuple
from camera.cameraGenerator import create_camera_for_card

Expand Down Expand Up @@ -32,8 +32,12 @@ def create_cameras(camera_stage, subject_stage, cards):
card_width = (max_bound[card.horizontalIndex] - min_bound[card.horizontalIndex]) * 10
card_height = (max_bound[card.verticalIndex] - min_bound[card.verticalIndex]) * 10
card_bounding_box = BoundingBox(card_width, card_height)

faceTranslationValue = max_bound[card.translationIndex] if card.sign > 0 else min_bound[card.translationIndex]
center_of_card_face = Gf.Vec3d(subject_center[0], subject_center[1], subject_center[2])
center_of_card_face[card.translationIndex] = faceTranslationValue

create_camera_for_card(card, camera_stage, subject_center, card_bounding_box)
create_camera_for_card(card, camera_stage, center_of_card_face, card_bounding_box)

def get_bounding_box(subject_stage):
bboxCache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), [UsdGeom.Tokens.default_])
Expand Down
2 changes: 1 addition & 1 deletion src/utils/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse_args():

is_usdz = ".usdz" in args.usd_file
usdz_wrapper_name = args.usd_file.split('.')[0] + '_Cards.usda'
file_to_sublayer = args.usdz_wrapper_name if is_usdz else args.usd_file
file_to_sublayer = usdz_wrapper_name if is_usdz else args.usd_file

return Args(args.usd_file,
args.create_usdz_result,
Expand Down

0 comments on commit 74616e0

Please sign in to comment.