Skip to content

Commit

Permalink
Export Maya
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Dec 17, 2024
1 parent 648b095 commit 9d06a46
Showing 1 changed file with 139 additions and 11 deletions.
150 changes: 139 additions & 11 deletions meshroom/nodes/aliceVision/ExportMaya.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
from meshroom.core import desc
from meshroom.core.utils import VERBOSE_LEVEL


class ExportMaya(desc.AVCommandLineNode):
commandLine = 'aliceVision_exportMeshroomMaya {allParams}'
class ExportMaya(desc.Node):

category = 'Export'
documentation = '''
Export a scene for Autodesk Maya, with an Alembic file describing the SfM: cameras and 3D points.
It will export half-size undistorted images to use as image planes for cameras and also export thumbnails.
Use the MeshroomMaya plugin, to load the ABC file. It will recognize the file structure and will setup the scene.
MeshroomMaya contains a user interface to browse all cameras.
'''
Export a Maya script.
This script executed inside Maya, will gather the Meshroom computed elements.
'''

inputs = [
desc.File(
Expand All @@ -22,6 +18,24 @@ class ExportMaya(desc.AVCommandLineNode):
description="Input SfMData file.",
value="",
),
desc.File(
name="alembic",
label="Alembic file",
description="Input alembic file.",
value="",
),
desc.File(
name="mesh",
label="Input Mesh",
description="Input Mesh file.",
value="",
),
desc.File(
name="images",
label="Undistorted Images",
description="Undistorted images template.",
value="",
),
desc.ChoiceParam(
name="verboseLevel",
label="Verbose Level",
Expand All @@ -34,8 +48,122 @@ class ExportMaya(desc.AVCommandLineNode):
outputs = [
desc.File(
name="output",
label="Folder",
description="Folder for MeshroomMaya outputs: undistorted images and thumbnails.",
value=desc.Node.internalFolder,
label="Mel script",
description="Generated mel script",
value=desc.Node.internalFolder + "import.mel",
),
]

def processChunk(self, chunk):

import pyalicevision
import pathlib

Check warning on line 60 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L59-L60

Added lines #L59 - L60 were not covered by tests

chunk.logManager.start(chunk.node.verboseLevel.value)

Check warning on line 62 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L62

Added line #L62 was not covered by tests

chunk.logger.info("Open input file")
data = pyalicevision.sfmData.SfMData()
ret = pyalicevision.sfmDataIO.load(data, chunk.node.input.value, pyalicevision.sfmDataIO.ALL)
if not ret:
chunk.logger.error("Cannot open input")
chunk.logManager.end()
raise RuntimeError()

Check warning on line 70 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L64-L70

Added lines #L64 - L70 were not covered by tests

#Check that we have Only one intrinsic
intrinsics = data.getIntrinsics()
if len(intrinsics) > 1:
chunk.logger.error("Only project with a single intrinsic are supported")
chunk.logManager.end()
raise RuntimeError()

Check warning on line 77 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L73-L77

Added lines #L73 - L77 were not covered by tests

intrinsicId = next(iter(intrinsics))
intrinsic = intrinsics[intrinsicId]
w = intrinsic.w()
h = intrinsic.h()

Check warning on line 82 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L79-L82

Added lines #L79 - L82 were not covered by tests

cam = pyalicevision.camera.Pinhole.cast(intrinsic)
if cam == None:
chunk.logger.error("Intrinsic is not a required pinhole model")
chunk.logManager.end()
raise RuntimeError()

Check warning on line 88 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L84-L88

Added lines #L84 - L88 were not covered by tests

offset = cam.getOffset()
pix2inches = cam.sensorWidth() / (25.4 * max(w, h));

Check notice on line 91 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

codefactor.io / CodeFactor

meshroom/nodes/aliceVision/ExportMaya.py#L91

Statement ends with a semicolon. (E703)
ox = -pyalicevision.numeric.getX(offset) * pix2inches
oy = pyalicevision.numeric.getY(offset) * pix2inches

Check warning on line 93 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L90-L93

Added lines #L90 - L93 were not covered by tests

scale = cam.getScale()
fx = pyalicevision.numeric.getX(scale)
fy = pyalicevision.numeric.getY(scale)

Check warning on line 97 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L95-L97

Added lines #L95 - L97 were not covered by tests


#Retrieve the first frame

minIntrinsicId = 0
minFrameId = 0
minFrameName = ''
first = True
views = data.getViews()

Check warning on line 106 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L102-L106

Added lines #L102 - L106 were not covered by tests

for viewId in views:

Check warning on line 108 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L108

Added line #L108 was not covered by tests

view = views[viewId]
frameId = view.getFrameId()
intrinsicId = view.getIntrinsicId()
frameName = pathlib.Path(view.getImageInfo().getImagePath()).stem

Check warning on line 113 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L110-L113

Added lines #L110 - L113 were not covered by tests

if first or frameId < minFrameId:
minFrameId = frameId
minIntrinsicId = intrinsicId
minFrameName = frameName
first = False

Check warning on line 119 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L115-L119

Added lines #L115 - L119 were not covered by tests


#Generate the script itself

alembic = chunk.node.alembic.value
abcString = f'AbcImport -mode open -fitTimeRange "{alembic}";'

Check warning on line 125 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L124-L125

Added lines #L124 - L125 were not covered by tests

mesh = chunk.node.mesh.value
objString = f'file -import -type "OBJ" -ignoreVersion -ra true -mbl true -mergeNamespacesOnClash false -namespace "mesh" -options "mo=1" -pr -importTimeRange "combine" "{mesh}";'

Check warning on line 128 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L127-L128

Added lines #L127 - L128 were not covered by tests

framePath = chunk.node.images.value.replace('<INTRINSIC_ID>', str(minIntrinsicId)).replace('<FILESTEM>', minFrameName)

Check warning on line 130 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L130

Added line #L130 was not covered by tests

camString = f'''

Check warning on line 132 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L132

Added line #L132 was not covered by tests
select -r mvgCameras ;
string $camName[] = `listRelatives`;
currentTime {minFrameId};
imagePlane -c $camName[0] -fileName "{framePath}";
setAttr "imagePlaneShape1.useFrameExtension" 1;
setAttr "imagePlaneShape1.offsetX" {ox};
setAttr "imagePlaneShape1.offsetY" {oy};
'''

ipa = fx / fy
advCamString = ''

Check warning on line 146 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L145-L146

Added lines #L145 - L146 were not covered by tests

if abs(ipa - 1.0) < 1e-6:

Check notice on line 148 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

codefactor.io / CodeFactor

meshroom/nodes/aliceVision/ExportMaya.py#L148

Multiple spaces before operator. (E221)
advCamString = f'''

Check warning on line 149 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L148-L149

Added lines #L148 - L149 were not covered by tests
setAttr "imagePlaneShape1.fit" 1;
'''
else:
advCamString = f'''

Check warning on line 153 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L153

Added line #L153 was not covered by tests
setAttr "imagePlaneShape1.fit" 4;
setAttr "imagePlaneShape1.squeezeCorrection" {ipa};
select -r $camName[0];
float $vaperture = `getAttr ".verticalFilmAperture"`;
float $scaledvaperture = $vaperture * {ipa};
setAttr "imagePlaneShape1.sizeY" $scaledvaperture;
'''

with open(chunk.node.output.value, "w") as f:
f.write(abcString + '\n')
f.write(objString + '\n')
f.write(camString + '\n')
f.write(advCamString + '\n')

Check warning on line 167 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L163-L167

Added lines #L163 - L167 were not covered by tests

chunk.logManager.end()

Check warning on line 169 in meshroom/nodes/aliceVision/ExportMaya.py

View check run for this annotation

Codecov / codecov/patch

meshroom/nodes/aliceVision/ExportMaya.py#L169

Added line #L169 was not covered by tests

0 comments on commit 9d06a46

Please sign in to comment.