Extracting data from 3D annotation
Hello , Im using c++ sdk , I've created function to create the 3d annotation with embedded data ( my embedded data is GLTF file 😞
ASBool EmbedDataTo3dAnnot(PDPage pdPage,
PDAnnot theAnnot, // 3D annot
ASPathName GLTFPathName, // ASPathName to the U3D file
ASPathName* asPosterPathName, // ASPathName to the poster file
const char* strJsFileName) // Path to the JavaScript file
{
CosObj cosAnnot = PDAnnotGetCosObj(theAnnot);
CosDoc cosDoc = CosObjGetDoc(cosAnnot);
ASPathName jsPathName = NULL;
ASBool bRet = true;
DURING
// *** Create the required 3D stream dictionary
// Open data file
ASFile asGLTFFile = NULL;
ASInt32 iRet = ASFileSysOpenFile(ASGetDefaultUnicodeFileSys(), GLTFPathName, ASFILE_READ, &asGLTFFile);
if ((iRet != 0) || (asGLTFFile == NULL)) {
AVAlertNote("error opening 3D data file.");
E_RETURN (false);
}
// Read data stream from the file
ASStm fileStm = ASFileStmRdOpen(asGLTFFile, 0);
if(fileStm == NULL){
AVAlertNote("empty 3D data stream.");
E_RETURN (false);
}
// Set the stream's entries
CosObj attrObj = CosNewDict(cosDoc, false, 1);
CosDictPutKeyString(attrObj, "Subtype", CosNewName(cosDoc, false, ASAtomFromString("GLTF")));
CosDictPutKeyString(attrObj, "Type", CosNewNameFromString(cosDoc, false, "3D"));
CosDictPutKeyString(attrObj, "Filter", CosNewNameFromString(cosDoc, false, "FlateDecode"));
PDDoc pdDoc = PDPageGetDoc(pdPage);
// Create the optional "VA" entry
CosObj cosArray = CosNewArray(cosDoc, true, 0);
if(CosObjGetType(cosArray) == CosArray) {
CosDictPutKeyString(attrObj, "VA", cosArray);
ASUns32 i = 0;
for(ASUns32 iCounter = 0; iCounter < NUM_VIEWS; iCounter++) {
CosObj cosOneView = BuildOneView(pdDoc, cosAnnot, VIEW_NAMES[iCounter]);
if(CosObjGetType(cosOneView) == CosDict) {
CosArrayPut(cosArray, i, cosOneView);
i++;
}
}
}
// Create a new 3D stream and set it under 3DD key in the annot dictionary
CosObj stm3D = CosNewStream(cosDoc, true, fileStm, 0, true, attrObj, CosNewNull(), -1);
CosDictPutKeyString(cosAnnot, "3DD", stm3D);
ASStmClose(fileStm);
ASFileClose(asGLTFFile);
// Embed optional JavaScript code in the 3D stream
// Open JavaScript file
#ifdef WIN_PLATFORM
const char* strPathFlag = "Cstring";
#else
const char* strPathFlag = "POSIXPath";
#endif
jsPathName = ASFileSysCreatePathName (ASGetDefaultFileSys(),
ASAtomFromString(strPathFlag), strJsFileName, 0);
ASFile asJsFile = NULL;
iRet = ASFileSysOpenFile(ASGetDefaultFileSys(), jsPathName, ASFILE_READ, &asJsFile);
ASFileSysReleasePath (ASGetDefaultFileSys(), jsPathName);
if ((iRet == 0) && (asJsFile != NULL)) {
// Read js code from the js file and set it in the 3D stream
ASStm jsFileStm = ASFileStmRdOpen(asJsFile, 0);
if (jsFileStm != NULL) {
CosObj cosJs = CosNewDict(cosDoc, false, 1);
CosDictPutKeyString(cosJs, "Filter", CosNewNameFromString(cosDoc, false, "FlateDecode"));
CosObj stm3dJsCode = CosNewStream(cosDoc, true, jsFileStm, 0, true, cosJs, CosNewNull(), -1);
CosDictPutKeyString(attrObj, "OnInstantiate", stm3dJsCode);
}
ASStmClose(jsFileStm);
ASFileClose(asJsFile);
}
// Set the optional animation style dictionary in the 3D stream
CosObj animationDict = CosNewDict(cosDoc, false, 1);
if(CosObjGetType(animationDict) == CosDict) {
CosDictPutKeyString(attrObj, "AN", animationDict);
CosDictPutKeyString(animationDict, "Type",
CosNewName(cosDoc, false, ASAtomFromString("3DAnimationStyle")));
CosDictPutKeyString(animationDict, "Subtype",
CosNewName(cosDoc, false, ASAtomFromString("Linear")));
CosDictPutKeyString(animationDict, "PC", CosNewInteger(cosDoc, false, -1));
CosDictPutKeyString(animationDict, "TM", CosNewInteger(cosDoc, false, 1));
}
// Set the optional indirect reference to the page object in the annot dictionary
CosDictPutKeyString(cosAnnot, "P", PDPageGetCosObj(pdPage));
// Set the optional "Contents" entry in the annot dictionary
CosDictPutKeyString(cosAnnot, "Contents", CosNewString(cosDoc, false, "3D Model", strlen("3D Model")));
// Create a poster for the 3D annotation
CosObj formXObj = BuildFormXObj(asPosterPathName, pdDoc);
if (!CosObjEqual(formXObj, CosNewNull())){
// Build the required "AP" entry for the 3D annotation
CosObj apprDict = CosNewDict(cosDoc, false, 1);
CosDictPutKeyString(apprDict, "N", formXObj);
CosDictPutKeyString(cosAnnot, "AP", apprDict);
}
// *** Set the optional default initial view of the 3D artwork
// You are supposed to parse the U3D model file and retrieve the format spec
// such as transformation matrix for the view. Then construct the "MS", "CO", "C2W"
// (if value for "MS" is "M"), etc. entries.
// *** Set the optional activation dictionary
CosObj activationDict = CosNewDict(cosDoc, false, 1);
if(CosObjGetType(activationDict) == CosDict) {
CosDictPutKeyString(cosAnnot, "3DA", activationDict);
CosDictPutKeyString(activationDict, "DIS", CosNewName(cosDoc, false, ASAtomFromString("I")));
// Set the optional activation choice
CosDictPutKeyString(activationDict, "A", CosNewName(cosDoc, false, ASAtomFromString("PO")));
}
HANDLER
DisplayExceptionMsg();
bRet = false;
END_HANDLER
return bRet;
}
And also I have a function to create pdf with 3d annotation
How can i extract the GlTF file from my annotation and save it as a temp file ?
