How-To: Create standard views (Right, Left, Top, Bottom, Front, Back and Iso)

To programmatically create standard views for CAD models in PDF,

  1. Get the bounding box of the model and calculate the camera center point.
//To get the camera center
A3DBoundingBoxData pboxdata;
A3D_INITIALIZE_DATA(A3DBoundingBoxData, pboxdata);
A3DMiscComputeBoundingBox(pModelFile, 0, &pboxdata);

double centerx, centery, centerz;
centerx = (pboxdata.m_sMax.m_dX + pboxdata.m_sMin.m_dX) / 2;
centery = (pboxdata.m_sMax.m_dY + pboxdata.m_sMin.m_dY) / 2;
centerz = (pboxdata.m_sMax.m_dZ + pboxdata.m_sMin.m_dZ) / 2;
  1. The position of the camera is a point that represents the position of the viewpoint. Normally, the camera position is placed slightly away from the objects that you wish to view

More informtion for the Camera definition Defining 3D — HOOPS Publish Documentation documentation

//To compute the position that slighlty aways 
double highestValue = centerz;
double pboxdataMax = pboxdata.m_sMax.m_dZ;
double pboxdataMin = pboxdata.m_sMin.m_dZ;

if (highestValue < centerx)
{
	highestValue = centerx;
	pboxdataMax = pboxdata.m_sMax.m_dX;
	pboxdataMin = pboxdata.m_sMin.m_dX;
}
if (highestValue < centery)
{
	highestValue = centery;
	pboxdataMax = pboxdata.m_sMax.m_dY;
	pboxdataMin = pboxdata.m_sMin.m_dY;
}

double maxFactor = (pboxdataMax - highestValue) * 5;
double minFactor = (pboxdataMin - highestValue) * 5;
  1. Finally, we can create standard views (Right, Left, Top, Bottom, Front, Back and Iso)
// creating the views
A3DPDFView* pViewDef;
A3DPDFView* pViews[6]; memset(pViews, 0, 4 * sizeof(A3DPDFView*));
A3DUTF8Char viewnameDef[] = "Right View";
const A3DUTF8Char* viewnames[6] = { "Left View", "Top View","Bottom View", "Front View", "Back View", "ISO view" };
// Right View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMax.m_dX + maxFactor, centery, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	true, viewnameDef, &pViewDef));

// Left View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMin.m_dX + minFactor, centery, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[0], &pViews[0]));


// Top View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, centery, pboxdata.m_sMax.m_dZ + maxFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[1], &pViews[1]));

// Bottom View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, centery, pboxdata.m_sMin.m_dZ + minFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[2], &pViews[2]));

// Front View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, pboxdata.m_sMin.m_dY + minFactor, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[3], &pViews[3]));

// Back View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	centerx, pboxdata.m_sMax.m_dY + maxFactor, centerz,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[4], &pViews[4]));


// ISO View
CHECK_RET(CreateView(pDoc, p3DArtwork,
	pboxdata.m_sMax.m_dX + maxFactor, pboxdata.m_sMax.m_dY + maxFactor, pboxdata.m_sMax.m_dZ + maxFactor,	// camera position
	centerx, centery, centerz,		// target position
	0, 0, 0,	// up vector unused - roll is used instead
	0,	// roll
	kA3DPDFPerspectiveMode, 0, 30,
	false, viewnames[5], &pViews[5]));
  1. You may adjust the values to find the best fitting for your usage.

The furnished code demonstrates how to programmatically create standard views for CAD models in PDF. By obtaining the bounding box of the model and calculating the camera center point, you can define the camera position and target position for each view. The code creates views such as Right, Left, Top, Bottom, Front, Back, and ISO view by fixing the camera and target positions, roll, perspective mode, and other parameters. Adjusting the values allows customization for your specific needs. It’s worth noting that this code snippet appears to be specific to the HOOPS Publish Documentation and may not directly relate toany other application that correlated to an AI services provider or any other domain.