Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions plugin/adsk/scripts/mayaUsd_exportHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,38 @@ def removeHiddenInOutliner(allItems):
def updateDefaultPrimCandidates(excludeMesh, excludeLight, excludeCamera, excludeStage):
allItems = cmds.ls(assemblies=True)
excludeList = []

def add_excluded(items):
for m in items:
rel = cmds.listRelatives(m, parent=True, fullPath=True)[0]
excludeList.append(m)
excludeList.append(rel)
if rel.startswith("|"):
excludeList.append((rel.removeprefix("|")))

if excludeMesh == "1":
meshes = cmds.ls(type=('mesh'), l=True)
for m in meshes:
excludeList.append(cmds.listRelatives(m, parent=True)[0])
add_excluded(cmds.ls(type=('mesh'), l=True))

if excludeLight == "1":
lights = cmds.ls(type=('light'), l=True)
for l in lights:
excludeList.append(cmds.listRelatives(l, parent=True)[0])
add_excluded(cmds.ls(type=('light'), l=True))

if excludeCamera == "1":
cameras = cmds.ls(type=('camera'), l=True)
for c in cameras:
excludeList.append(cmds.listRelatives(c, parent=True)[0])
add_excluded(cmds.ls(type=('camera'), l=True))
else:
# Note: we still want to exclude the startup cameras even if
# excludeCamera is not set, to avoid exporting them by mistake.
cameras = cmds.ls(type=('camera'), l=True)
startup_cameras = []
for c in cameras:
if cmds.camera(cmds.listRelatives(c, parent=True)[0], startupCamera=True, q=True):
startup_cameras.append(cmds.listRelatives(c, parent=True)[0])
camRelatives = cmds.listRelatives(c, parent=True, fullPath=True)
if cmds.camera(camRelatives[0], startupCamera=True, q=True):
startup_cameras.append(camRelatives[0])

startup_cameras.extend([c.removeprefix("|") for c in startup_cameras])
allItems = list(set(allItems) - set(startup_cameras))

if excludeStage == "1":
stages = cmds.ls(type=('mayaUsdProxyShape'), l=True)
for st in stages:
excludeList.append(st)
excludeList.append(cmds.listRelatives(st, parent=True)[0])
add_excluded(cmds.ls(type=('mayaUsdProxyShape'), l=True))

allItems = removeHiddenInOutliner(list(set(allItems) - set(excludeList)))
allItems.sort(key=natural_key)
Expand Down Expand Up @@ -74,7 +78,7 @@ def _addExclusions(nodeType, excludeParent=False):
nodes = cmds.ls(type=(nodeType), l=True)
for n in nodes:
if excludeParent:
excludeSet.add(cmds.listRelatives(n, parent=True)[0])
excludeSet.add(cmds.listRelatives(n, parent=True, fullPath=True)[0])
path = _getRelatives(n)
if not path:
continue
Expand Down
1 change: 1 addition & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(TEST_SCRIPT_FILES
testUsdExportBlendshapes.py
testUsdExportCamera.py
testUsdExportCameraAttrSpline.py
testUsdExportCameraSameName.py
testUsdExportColorSets.py
testUsdExportConnected.py
testUsdExportDefaultPrim.py
Expand Down
71 changes: 71 additions & 0 deletions test/lib/usd/translators/testUsdExportCameraSameName.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env mayapy
#
# Copyright 2016 Pixar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
import unittest

from pxr import Usd
from pxr import UsdGeom

from maya import cmds
from maya import standalone

import fixturesUtils

class testUsdExportCameraWithSameName(unittest.TestCase):

@classmethod
def setUpClass(cls):
fixturesUtils.setUpClass(__file__)

@classmethod
def tearDownClass(cls):
standalone.uninitialize()

def testExportMultiCameras(self):
"""
Test that having multiple cameras with the same name and exporting
by specifying a camera node name works. It used to fail because we
would confuse both cameras.
"""
cmds.file(force=True, new=True)

# create a camera and group it
cmds.camera()
cmds.rename('cam')
cmds.group(name='backup')

# create a second camera with the same name
cmds.camera()
cmds.rename('cam')

# export it to USD
usdFilePath = os.path.abspath('UsdExportCameraTest.usda')
if os.path.exists(usdFilePath):
os.remove(usdFilePath)
cmds.usdExport("|cam", file=usdFilePath)
stage = Usd.Stage.Open(usdFilePath)
self.assertTrue(stage)

# Verify the camera in USD
cam = UsdGeom.Camera.Get(stage, '/cam')
self.assertTrue(cam)
print(stage.GetRootLayer().ExportToString())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this print?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging:) I will remove



if __name__ == '__main__':
unittest.main(verbosity=2)