obectjViewport viewportSz in microsoft ML

jad maqdah 21 Reputation points
2022-11-29T15:11:49.113+00:00

Hello, I have been trying to programmatically write 3D GLB objects in PowerPoint using C++. I have figured out all the camera settings and options, but the only thing I need to calculate is the objViewport Sz.

Here is the link of the element and its attribute: https://video2.skills-academy.com/en-us/openspecs/office_standards/ms-odrawxml/c20ace8b-ea42-4d0f-9f7e-e0bbd467152b

I cannot find an equation anywhere to calculate the viewportSz attribute. This is important because when the 3d GLB object is written to PowerPoint, the viewport is either too zoomed in (some parts of it don't fit in the viewport) or zoomed out (the object is very small).

Does it have to do with the object's extents (i.e., the bounding box extents) (max extent in X, max extent in Y, max extent in Z)?

Can someone help me please?

Thank you!

Office Open Specifications
Office Open Specifications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Open Specifications: Technical documents for protocols, computer languages, standards support, and data portability. The goal with Open Specifications is to help developers open new opportunities to interoperate with Windows, SQL, Office, and SharePoint.
138 questions
{count} votes

Accepted answer
  1. Hung-Chun Yu 976 Reputation points Microsoft Employee
    2022-12-03T20:14:04.123+00:00

    Hi @jad maqdah

    Calculation of viewportSz is, unfortunately, too complex to be reduced to mathematical equations. There are two basic steps that are run after a 3D Model is first inserted into Office: calculating the frame bounds, and then calculating the full frame size. We also run variations on these steps after any Office commands that change the camera settings.

    Let’s refer to the bounds stored in the p:xfrm (transform) element of the p:graphicFrame element as the “3D Model Frame Rect”. Each app (PowerPoint, Excel, Word) have their own default Frame Rect dimensions for newly inserted 3D Models. PowerPoint chooses a default starting frameRect such that the width = slideWidth*2/3, the height = slideWidth*4/9, and the anchor is centered in the slide. I didn’t research the Excel or Word starting frame rect logic; they are probably similar.

    1. Update the 3D Model Frame Rect to match the aspect ratio of the 3D model
      a. Start with originalFrameRect, the original 3D Model Frame Rect as described above (some fixed size relative to the doc slide/page).
      b. Calculate originalFrameSize as the min of originalFrameRect's width or height.
      c. Measure visibleBoundsRatios – A 2D ratio vector where visibleBoundsRatios.dx is the ratio of the how much of the (square) 3D camera viewport is filled on the x-axis, and visibleBoundsRatios.dy reflects the y-axis. We actually render the 3D model to a small texture and scan the image to measure this. For example, a value of (1.0,0.5) means the 3D scene fully fills the camera on the x-axis, but only fills 50% of the y-axis.
      i. Note: We init our cameras to leave buffer around the 3D scene, and the scene is probably bigger on one axis than the other, so both values in the ratio vector are almost always smaller than 0.9 on each axis.
      ii. Note: For an example seahorse model, which is tall and skinny, we measure this visible bounds ratio as (0.125, 0.858).
      d. Calculate adjustedFrameRect = originalFrameSize * visibleBoundsRatios. This effectively shrinks originalFrameRect to have the aspect ratio of the camera output, but inscribed within and slightly smaller than the original/default frame rect.
    2. Calculate “fullFrameSize”, which will then be stored in attribute viewportSz inside element am3d:objViewport:

    a. Measure visibleBoundsRatios (same as described in part 1, and it should be the same exact value until the camera is changed or scene is rotated)
    b. Inflate visibleBoundsRatios on whichever axis (x or y) allows its aspect ratio (visibleBoundsRatios.x / visibleBoundsRatios.y) to equal (adjustedFrameRect.width / adjustedFrameRect.height).
    c. Calculate fullFrameSize = adjustedFrameRect.height / visibleBoundsRatios.dy

    This is a complex algorithm, and could be challenging to emulate exactly like Office does it. The hardest part to emulate is probably 1.c and 2.a, which involve rasterization and image scanning. Perhaps you could approximate these steps instead, given some knowledge of how your camera and 3D scene were programmatically assembled.

    Let me know if this helped

    Hung-Chun Yu

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. jad maqdah 21 Reputation points
    2022-12-05T18:29:06.05+00:00

    Hi @Hung-Chun Yu

    Thank you very much for your answer! This really helps! :)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.