|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +"""Shared Physical OCIO cube scene for Cinema 4D integration tests.""" |
| 3 | + |
| 4 | +import os |
| 5 | + |
| 6 | +import c4d |
| 7 | + |
| 8 | +ACES_DEFAULT_VIEW_TRANSFORM = 0 |
| 9 | +ACES_UNTONE_MAPPED_VIEW_TRANSFORM = 3 |
| 10 | +PHYSICAL_RENDERER_ID = 1023342 |
| 11 | + |
| 12 | + |
| 13 | +def _add_sample_cube(doc) -> None: |
| 14 | + cube = c4d.BaseObject(c4d.Ocube) |
| 15 | + cube.SetName("OCIO sample cube") |
| 16 | + cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(300, 300, 300) |
| 17 | + cube.SetAbsPos(c4d.Vector(0, 170, 170)) |
| 18 | + doc.InsertObject(cube) |
| 19 | + |
| 20 | + |
| 21 | +def build_ocio_scene( |
| 22 | + output_dir: str, |
| 23 | + scene_name: str, |
| 24 | + view_transform: int, |
| 25 | +) -> None: |
| 26 | + """Build and save the sample cube with the requested ACES view transform.""" |
| 27 | + output_dir = os.path.abspath(output_dir) |
| 28 | + os.makedirs(output_dir, exist_ok=True) |
| 29 | + |
| 30 | + doc = c4d.documents.GetActiveDocument() |
| 31 | + doc.Flush() |
| 32 | + doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = c4d.DOCUMENT_COLOR_MANAGEMENT_OCIO |
| 33 | + doc[c4d.DOCUMENT_OCIO_PRESET] = c4d.DOCUMENT_OCIO_PRESET_ACES |
| 34 | + doc[c4d.DOCUMENT_OCIO_VIEW_TRANSFORM] = view_transform |
| 35 | + |
| 36 | + _add_sample_cube(doc) |
| 37 | + |
| 38 | + render_data = doc.GetActiveRenderData() |
| 39 | + render_data[c4d.RDATA_RENDERENGINE] = PHYSICAL_RENDERER_ID |
| 40 | + render_data[c4d.RDATA_FRAMEFROM] = c4d.BaseTime(1, doc.GetFps()) |
| 41 | + render_data[c4d.RDATA_FRAMETO] = c4d.BaseTime(1, doc.GetFps()) |
| 42 | + render_data[c4d.RDATA_FORMAT] = c4d.FILTER_PNG |
| 43 | + render_data[c4d.RDATA_FORMATDEPTH] = c4d.RDATA_FORMATDEPTH_8 |
| 44 | + render_data[c4d.RDATA_ALPHACHANNEL] = False |
| 45 | + render_data[c4d.RDATA_MULTIPASS_SAVEIMAGE] = False |
| 46 | + if hasattr(c4d, "RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER"): |
| 47 | + render_data.GetDataInstance()[c4d.RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER] = True |
| 48 | + |
| 49 | + render_data[c4d.RDATA_PATH] = "renders/$prj" |
| 50 | + |
| 51 | + scene_path = os.path.join(output_dir, scene_name) |
| 52 | + doc.SetDocumentPath(output_dir) |
| 53 | + doc.SetDocumentName(scene_name) |
| 54 | + if not c4d.documents.SaveDocument( |
| 55 | + doc, |
| 56 | + scene_path, |
| 57 | + c4d.SAVEDOCUMENTFLAGS_0, |
| 58 | + c4d.FORMAT_C4DEXPORT, |
| 59 | + ): |
| 60 | + raise RuntimeError(f"Failed to save integration scene: {scene_path}") |
| 61 | + c4d.EventAdd() |
0 commit comments