The "Hello World" Example

Default input and output files

When run with no command line arguments the following definitions are used to define the relevant input and output files. Note the working directory is set to IN_INSTALL_DIR at the top of the main() function.

#ifdef _WIN64
#define IN_INSTALL_DIR _T("..\\..\\..\\..\\bin\\win64\\")
#elif defined _WIN32
#define IN_INSTALL_DIR _T("..\\..\\..\\..\\bin\\win32\\")
#else
#error "Architecture not supported!"
#endif
WARNING: with the SetCurrentDirectory solution, data directory is "..\\..\\samples\\data"
#define IN_3DFILE   "..\\..\\samples\\data\\step\\helloworld.stp"
#define IN_POSTERIMAGE   "..\\..\\samples\\data\\images\\empty.jpg"
#define IN_POSTERIMAGE_W  100
#define IN_POSTERIMAGE_H  100
#define IN_JSFILE   ""
#define OUT_FILE    "..\\..\\samples\\publish\\publishgallery\\sample_HelloWorld.pdf"

Adding a license key

The license key is defined in the A3DSDKLicenseKey.h header. You must replace this key with your valid key generated from the HOOPS Publish downloads page, otherwise, the program will run but nothing will happen.

&#35;include <A3DSDKLicenseKey.h>

The license key is registered with the DLLs with:

iRet = A3DLicPutLicense(A3DLicPutLicenseFile, pcCustomerKey, pcVariableKey);
CHECK_RET;

Creating a PDF document and page

A new document is created and a page is added in standard US Letter Format.

create empty document
A3DPDFDocument* pDoc = NULL;
iRet = A3DPDFDocumentCreateEmpty(&pDoc);
CHECK_RET;
if(pDoc != NULL)
{
creating a document page from scratch
   A3DPDFPageData sPageData;
   sPageData.m_ePageOrientation = kA3DPDFPageLandscape;
   sPageData.m_ePageSize = kA3DPDFPageLetter;  // standard letter format: 612 x 792
   constintiPageWidth = 792, iPageHeight = 612;
   A3DPDFPage* pPage = NULL;
   iRet = A3DPDFDocumentAppendNewPage(pDoc, &sPageData, &pPage);
   CHECK_RET;

The macro A3D_INITIALIZE_DATA is the standard method for initialising HOOPS Publish structures.

Loading the STEP File and creating the PRC stream

The STEP File is loaded in using

iRet = A3DAsmModelFileLoadFromFile(in_3dfile, &sReadParam, &pModelFile);

The structure sReadParam is of type A3DRWParamsLoadData and has multiple flags that control how the file is loaded, what is read, how it is tessellated etc. These are documented in the HOOPS Publish reference manual. If you have any queries as to how to set these parameters please contact the HOOPS Support team.

If the load was successful then a PRC Stream is created from the model file entity

if(pModelFile)
{
creating the PRC stream from the model file 
that is going to be inserted into the PDF file
   A3DRWParamsExportPrcData sParamsExportData;
   A3D_INITIALIZE_DATA(A3DRWParamsExportPrcData, sParamsExportData);
   iRet = A3DPDF3DStreamCreateFromModelFileAsPRC(pDoc, 
      pModelFile, 
      &sParamsExportData, 
      &pStream, NULL);
   CHECK_RET;

Adding a Poster Image

A poster image is a raster representation of the 3D annotation that is displayed when the annotation is not activated. By default user interaction is needed to activate a 3D annotation, although activation can also happen automatically when the document is opened. If no poster image is specified when a 3D annotation is created, HOOPS Publish will automatically generate one.

creating the poster image
A3DPDFImageData sImageData;
A3DPDFImage* pImage;
A3D_INITIALIZE_DATA(A3DPDFImageData, sImageData);
sImageData.m_pcFileName = in_posterfile;
sImageData.m_iHeight = IN_POSTERIMAGE_H;
sImageData.m_iWidth = IN_POSTERIMAGE_W;
sImageData.m_eFormat = kA3DPDFImageFormatJpg;
iRet = A3DPDFImageCreate(pDoc, &sImageData, &pImage);
CHECK_RET;

The image defined in pImage is added to the annotation as the poster image as the m_pPosterImage parameter of the A3DPDF3DAnnotData structure passed when the 3D Annotation is created - see "Creating the 3D Annotation" below.

Creating the 3D Artwork

The ’artwork’ for the annotation represents the model (the stream), and Javascript and the named views (stored camera parameters).

creating the 3D artwork
A3DPDF3DArtwork* p3DArtwork;
A3DPDF3DArtworkData s3DArtworkData;
A3D_INITIALIZE_DATA(A3DPDF3DArtworkData, s3DArtworkData);
s3DArtworkData.m_pStream = pStream;
s3DArtworkData.m_pcJavaScriptFileName = in_jsfile;
s3DArtworkData.m_eAnimationStyle = kA3DPDFAnimStyleNoAnimation;
iRet = A3DPDF3DArtworkCreate(pDoc, &s3DArtworkData, &p3DArtwork);
CHECK_RET;

Creating the 3D Annotation

After adding the stream to the artwork, the 3D annotation can be created. A number of parameters that can control how the annotation looks can be set:

sAnnotData.m_bOpenModelTree = false;
sAnnotData.m_bShowToolbar = false;
sAnnotData.m_eLighting = kA3DPDFLightCADOptimized;
AnnotData.m_eRenderingStyle = kA3DPDFRenderingSolid;
sAnnotData.m_sBackgroundColor.m_dRed = 0.25;
sAnnotData.m_sBackgroundColor.m_dGreen = 0.25;
sAnnotData.m_sBackgroundColor.m_dBlue = 0.25;
sAnnotData.m_bTransparentBackground = false;
sAnnotData.m_eActivateWhen = kA3DPDFActivPageOpened;
sAnnotData.m_eDesactivateWhen = kA3DPDFActivPageClosed; 
sAnnotData.m_iAppearanceBorderWidth = 0;
sAnnotData.m_pPosterImage = pImage;  
sAnnotData.m_p3DArtwork = p3DArtwork;
A3DPDF3DAnnot* p3DAnnot = NULL;
iRet = A3DPDF3DAnnotCreate(pDoc, &sAnnotData, &p3DAnnot);
CHECK_RET;

Inserting the 3D Annotation in the page

The annotation position is described via a rectangle with the coordinate origin at the bottom left of the page. In the example below the annotation covers the entire page.

if(p3DAnnot != NULL)
{
position the 3D annotation in the page
   A3DPDFRectData sPos;
   A3D_INITIALIZE_DATA(A3DPDFRectData, sPos);
coordinates are from bottom left of the page 
   sPos.m_iLeft = 0;              // lower left x
   sPos.m_iBottom = 0;            // lower left y
   sPos.m_iRight = iPageWidth;    // upper right x
   sPos.m_iTop = iPageHeight;     // upper right y
   iRet = A3DPDFPageInsert3DAnnot(pPage, p3DAnnot, &sPos);
   CHECK_RET;
}

Cleaning up

To clean up, the model file must be deleted, although this should not be done before the Artwork has been created as it is at this point that the actual conversion takes place. The modified PDF document must then be saved and closed.

cleaning up
WARNING: DO NOT CALL THIS BEFORE A3DPDF3DArtworkCreate!
iRet = A3DAsmModelFileDelete(pModelFile);
CHECK_RET;
saving the document 
iRet = A3DPDFDocumentSave(pDoc, out_pdffile);
CHECK_RET;
iRet = A3DPDFDocumentClose(pDoc);
CHECK_RET;