`Autodesk.Viewing.ScreenShot.getScreenShotWithBounds` 使用查看器的默认相机尺寸而不是边界
`Autodesk.Viewing.ScreenShot.getScreenShotWithBounds` uses viewer's default camera dimensions instead of bounds
在 this advice 之后,我正在尝试将我们对 viewer::getScreenshot
的使用替换为 Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
,后者调用 Autodesk.Viewing.ScreenShot.getScreenShot
以支持更大的屏幕截图。但是,边界将被忽略。该行为似乎是它制作了查看者默认相机的屏幕截图或与其尺寸相对应。然后它拉伸图像以适应给定的宽度和高度。我希望该函数 return 给定边界框内元素的屏幕截图。
函数 getScreenShotWithBounds
是否应该做一些与我假设不同的事情?
示例代码(LMV 7.40.0):
const bbounds: THREE.Bbox3; // calculated for some elements I want to screenshot
Autodesk.Viewing.ScreenShot.getScreenShotWithBounds(NOP_VIEWER, Math.ceil(bbounds.size().x * 4), Math.ceil(bbounds.size().y* 4), (blob) => window.open(blob), {bounds: bbounds, margin: 0});
查看器手动截图
getScreenShotWithBounds 的返回图像
更新:
我误解了函数。 Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
刚好适合相机视图的边界。边界不用于任何裁剪。参见 。
您得到的压缩图像是在暗示它,但是从 source code 中的评论中并不清楚您应该保持 Viewer 的比例width
和 height
输入参数。因此,您应该 仅根据需要缩放 它们:getScreenShotWithBounds(NOP_VIEWER, viewer_width * x, viewer_height * x, etc
然后 options
中的 bounds
应该负责裁剪。
Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
的给定宽度和高度必须与查看器具有相同的宽高比(参见 ),即:
getScreenShotWithBounds(NOP_VIEWER, NOP_VIEWER.getDimensions().width * 4, NOP_VIEWER.getDimensions().height * 4, options);
getScreenShotWithBounds
刚好适合相机视图的边界(在内部称为 viewer.navigation.fitBounds(true, bounds, false);
)。边界不用于任何类型的裁剪/像素计算或其他。
要通过裁剪获得特定的纵横比,您必须在 options
参数中提供 getCropBounds
。
例如通过裁剪强制纵横比:
getCropBounds: function(viewer: Autodesk.Viewing.Viewer3D, camera: Autodesk.Viewing.UnifiedCamera, bounds: THREE.Box3): THREE.Box2 {
// calculate the crop bounds in pixels
// if the crop bounds are larger the screenshot's width / height is taken
const aspectRatio = new THREE.Vector2(4, 3);
const viewerBoundsWidthRatio = width / aspectRatio.x;
const viewerBoundsHeightRatio = height / aspectRatio.y;
const cropToHeight = viewerBoundsWidthRatio > viewerBoundsHeightRatio;
const smallerScaleRatio = cropToHeight ? viewerBoundsHeightRatio : viewerBoundsWidthRatio;
const cropBoundsSize = aspectRatio.clone().multiplyScalar(smallerScaleRatio);
const cropBounds = new THREE.Box2(new THREE.Vector2(0, 0), new THREE.Vector2(cropBoundsSize.x, cropBoundsSize.y));
const offset = cropToHeight ? new THREE.Vector2((width - cropBoundsSize.x) / 2, 0) : new THREE.Vector2(0, (height - cropBoundsSize.y) / 2);
cropBounds.min.add(offset);
cropBounds.max.add(offset);
return cropBounds;
}
在 this advice 之后,我正在尝试将我们对 viewer::getScreenshot
的使用替换为 Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
,后者调用 Autodesk.Viewing.ScreenShot.getScreenShot
以支持更大的屏幕截图。但是,边界将被忽略。该行为似乎是它制作了查看者默认相机的屏幕截图或与其尺寸相对应。然后它拉伸图像以适应给定的宽度和高度。我希望该函数 return 给定边界框内元素的屏幕截图。
函数 getScreenShotWithBounds
是否应该做一些与我假设不同的事情?
示例代码(LMV 7.40.0):
const bbounds: THREE.Bbox3; // calculated for some elements I want to screenshot
Autodesk.Viewing.ScreenShot.getScreenShotWithBounds(NOP_VIEWER, Math.ceil(bbounds.size().x * 4), Math.ceil(bbounds.size().y* 4), (blob) => window.open(blob), {bounds: bbounds, margin: 0});
查看器手动截图
getScreenShotWithBounds 的返回图像
更新:
我误解了函数。 Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
刚好适合相机视图的边界。边界不用于任何裁剪。参见
您得到的压缩图像是在暗示它,但是从 source code 中的评论中并不清楚您应该保持 Viewer 的比例width
和 height
输入参数。因此,您应该 仅根据需要缩放 它们:getScreenShotWithBounds(NOP_VIEWER, viewer_width * x, viewer_height * x, etc
然后 options
中的 bounds
应该负责裁剪。
Autodesk.Viewing.ScreenShot.getScreenShotWithBounds
的给定宽度和高度必须与查看器具有相同的宽高比(参见
getScreenShotWithBounds(NOP_VIEWER, NOP_VIEWER.getDimensions().width * 4, NOP_VIEWER.getDimensions().height * 4, options);
getScreenShotWithBounds
刚好适合相机视图的边界(在内部称为 viewer.navigation.fitBounds(true, bounds, false);
)。边界不用于任何类型的裁剪/像素计算或其他。
要通过裁剪获得特定的纵横比,您必须在 options
参数中提供 getCropBounds
。
例如通过裁剪强制纵横比:
getCropBounds: function(viewer: Autodesk.Viewing.Viewer3D, camera: Autodesk.Viewing.UnifiedCamera, bounds: THREE.Box3): THREE.Box2 {
// calculate the crop bounds in pixels
// if the crop bounds are larger the screenshot's width / height is taken
const aspectRatio = new THREE.Vector2(4, 3);
const viewerBoundsWidthRatio = width / aspectRatio.x;
const viewerBoundsHeightRatio = height / aspectRatio.y;
const cropToHeight = viewerBoundsWidthRatio > viewerBoundsHeightRatio;
const smallerScaleRatio = cropToHeight ? viewerBoundsHeightRatio : viewerBoundsWidthRatio;
const cropBoundsSize = aspectRatio.clone().multiplyScalar(smallerScaleRatio);
const cropBounds = new THREE.Box2(new THREE.Vector2(0, 0), new THREE.Vector2(cropBoundsSize.x, cropBoundsSize.y));
const offset = cropToHeight ? new THREE.Vector2((width - cropBoundsSize.x) / 2, 0) : new THREE.Vector2(0, (height - cropBoundsSize.y) / 2);
cropBounds.min.add(offset);
cropBounds.max.add(offset);
return cropBounds;
}