Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature node libs #140

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open

Feature node libs #140

wants to merge 25 commits into from

Conversation

kalwalt
Copy link
Member

@kalwalt kalwalt commented Mar 12, 2022

jsartoolkitNFT imported in a node environment

This continue from #128. As said in the issue and other, we should create an independentlib for node. The main reason is the loading of files, in node.js is different compared to a browser env. I will try to use the NODEFS loading the FyleSystem (FS). Note that this code in the PR is quite experimental, and i can't assure of the result.

Tasks to be completed

  • develop a uniqe lib for node
  • removing not necessary code for node
  • implement the basic methods to run a simple app

@kalwalt
Copy link
Member Author

kalwalt commented Apr 1, 2022

The new loadCamera function now can run without errors but i don't receive a message like:
artoolkitNFT_ES6_wasm.js:9 [warning] *** Camera Parameter resized from 640, 480. ***
This should come from setCamera() inside setup():

int setup(int width, int height, int cameraID) {
int id = gARControllerID++;
arController *arc = &(arControllers[id]);
arc->id = id;
arc->width = width;
arc->height = height;
arc->videoFrameSize = width * height * 4 * sizeof(ARUint8);
arc->videoFrame = (ARUint8*) malloc(arc->videoFrameSize);
arc->videoLuma = (ARUint8*) malloc(arc->videoFrameSize / 4);
setCamera(id, cameraID);
webarkitLOGi("Allocated videoFrameSize %d", arc->videoFrameSize);
EM_ASM_({
if (!artoolkitNFT["frameMalloc"]) {
artoolkitNFT["frameMalloc"] = ({});
}
var frameMalloc = artoolkitNFT["frameMalloc"];
frameMalloc["framepointer"] = $1;
frameMalloc["framesize"] = $2;
frameMalloc["camera"] = $3;
frameMalloc["transform"] = $4;
frameMalloc["videoLumaPointer"] = $5;
},
arc->id,
arc->videoFrame,
arc->videoFrameSize,
arc->cameraLens,
gTransform,
arc->videoLuma //$5
);
return arc->id;
}

setCamera:
int setCamera(int id, int cameraID) {
if (arControllers.find(id) == arControllers.end()) { return -1; }
arController *arc = &(arControllers[id]);
if (cameraParams.find(cameraID) == cameraParams.end()) { return -1; }
arc->param = cameraParams[cameraID];
if (arc->param.xsize != arc->width || arc->param.ysize != arc->height) {
ARLOGw("*** Camera Parameter resized from %d, %d. ***\n", arc->param.xsize, arc->param.ysize);
arParamChangeSize(&(arc->param), arc->width, arc->height, &(arc->param));
}
// ARLOGi("*** Camera Parameter ***\n");
// arParamDisp(&(arc->param));
deleteHandle(arc);
if ((arc->paramLT = arParamLTCreate(&(arc->param), AR_PARAM_LT_DEFAULT_OFFSET)) == NULL) {
webarkitLOGe("setCamera(): Error: arParamLTCreate.");
return -1;
}
// ARLOGi("setCamera(): arParamLTCreated\n..%d, %d\n", (arc->paramLT->param).xsize, (arc->paramLT->param).ysize);
// setup camera
if ((arc->arhandle = arCreateHandle(arc->paramLT)) == NULL) {
webarkitLOGe("setCamera(): Error: arCreateHandle.");
return -1;
}
// AR_DEFAULT_PIXEL_FORMAT
int set = arSetPixelFormat(arc->arhandle, arc->pixFormat);
arc->ar3DHandle = ar3DCreateHandle(&(arc->param));
if (arc->ar3DHandle == NULL) {
webarkitLOGe("setCamera(): Error creating 3D handle");
return -1;
}
arglCameraFrustumRH(&((arc->paramLT)->param), arc->nearPlane, arc->farPlane, arc->cameraLens);
arc->kpmHandle = createKpmHandle(arc->paramLT);
return 0;

It could depends by the type of printings, maybe stream by ARLOGw is not outputted in node?

@kalwalt
Copy link
Member Author

kalwalt commented Apr 1, 2022

i make a simple test, i added a simple std::cout message before:

if (arc->param.xsize != arc->width || arc->param.ysize != arc->height) { 
 		ARLOGw("*** Camera Parameter resized from %d, %d. ***\n", arc->param.xsize, arc->param.ysize); 
 		arParamChangeSize(&(arc->param), arc->width, arc->height, &(arc->param)); 
 	}

and i get the message in the console, so i assume that for some reason simply the camera is not resized.

@kalwalt kalwalt self-assigned this Apr 1, 2022
@kalwalt
Copy link
Member Author

kalwalt commented Jun 29, 2022

Testing new node listeners, but actually the code (see node/example.js) can't detect and track the pinball image. If the data passed to the process function it should print that the nft marker is tracked, Instead i got a NftMarkerInfo struct with a not found marker. When i have a bit of time i will try to debug why is not detecting.

@kalwalt
Copy link
Member Author

kalwalt commented Sep 30, 2022

In regards of the previous comment: this could be caused because artoolkitNFT.NFTMarkerInfo Is not attached to the global scope when It Is passed through the EM_ASM_ inside the getNFTMarkerInfo function (ARToolKitJS.cpp). This Is a reminder when i come back from holiday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant