I’m starting by telling the viewer to launch with the document specified as the bubble.json file:
Helpers.launchViewer('viewerDiv', 'urn:' + '/resources/41bbc339-294e-4eb1-b5ee-f4f303df46bbviewable/bubble.json');//this.props.modelPath);
function launchViewer(div, urn) {
getToken.accessToken.then((token) => {
var options = {
'document': urn,
'env': 'Local',
};
Autodesk.Viewing.Initializer(options, () => {
viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById(div));
viewer.start(options.document, options);
Autodesk.Viewing.Document.load(urn, options, onDocumentLoadSuccess, onDocumentLoadFailure);
viewer.loadExtension('Autodesk.ModelStructure');
});
});
}
I then get the following errors:
Xhr.js:940 POST http://localhost:3000/oss-ext/v2/acmsessions 404 (Not
Found)
Otg.js:198 Uncaught TypeError: Cannot read property 'manifest' of null
at Otg.js:198
at Function. (Otg.js:143)
at l (Xhr.js:564)
at XMLHttpRequest.u (Xhr.js:668)
I wonder if maybe when I'm returning the files from my server if there's information I'm not including that's needed, or if I'm doing something else incorrecty. Thanks!
EDIT:
I've also tried loading the result.svf instead of the bubble and get the following error:
Error while processing SVF:
{"url":"/derivativeservice/v2/derivatives/urn%3Aresources%2F0d3f37ff-d195-451b-9a3c-35402f326f4dviewable%2Foutput%2F1%2Fresult.svf","exception":"SyntaxError:
Failed to execute 'open' on 'XMLHttpRequest': Invalid
URL","stack":"Error: Failed to execute 'open' on 'XMLHttpRequest':
Invalid URL\n at Object.g._rawGet
(blob:http://localhost:3000/a2115ade-285d-4398-8b8b-ae7704e9cc25:1:60485)\n
at
blob:http://localhost:3000/a2115ade-285d-4398-8b8b-ae7704e9cc25:1:59206\n
at n
...
I solved the problem myself - the Autodesk documentation specifies that 'urn:' has to come before the urn when loading a document. Loading the document locally, the relative file path should be used without the 'urn:' affix.
you dont need to add urn prefix in offline viewer
viewer only supports http/https url as document
refer to 0.svf file to render
for more infomation check this question.
Related
I've tried to change the object color in Autodesk Forge Viewer using the following link.
https://adndevblog.typepad.com/cloud_and_mobile/2015/12/change-color-of-elements-with-view-and-data-api.html
But, I've got the below issue when trying to load the extension "Autodesk.ADN.Viewing.Extension.Color".
"Uncaught (in promise) Extension failed to .load() : Autodesk.ADN.Viewing.Extension.Color at ExtensionManager.js:390"
That's an old article. Now the load() function of the extension needs to return true on a successful load - as shown here:
https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/viewer_basics/extensions/
So just return true at this place in the code:
_self.unload = function() {
console.log('Autodesk.ADN.Viewing.Extension.Color unloaded');
return true;
};
return true; // <<-- add this here
};
I am following a tutorial to resize images via Cloud Functions on upload and am experiencing two major issues which I can't figure out:
1) If a PNG is uploaded, it generates the correctly sized thumbnails, but the preview of them won't load in Firestorage (Loading spinner shows indefinitely). It only shows the image after I click on "Generate new access token" (none of the generated thumbnails have an access token initially).
2) If a JPEG or any other format is uploaded, the MIME type shows as "application/octet-stream". I'm not sure how to extract the extension correctly to put into the filename of the newly generated thumbnails?
export const generateThumbs = functions.storage
.object()
.onFinalize(async object => {
const bucket = gcs.bucket(object.bucket);
const filePath = object.name;
const fileName = filePath.split('/').pop();
const bucketDir = dirname(filePath);
const workingDir = join(tmpdir(), 'thumbs');
const tmpFilePath = join(workingDir, 'source.png');
if (fileName.includes('thumb#') || !object.contentType.includes('image')) {
console.log('exiting function');
return false;
}
// 1. Ensure thumbnail dir exists
await fs.ensureDir(workingDir);
// 2. Download Source File
await bucket.file(filePath).download({
destination: tmpFilePath
});
// 3. Resize the images and define an array of upload promises
const sizes = [64, 128, 256];
const uploadPromises = sizes.map(async size => {
const thumbName = `thumb#${size}_${fileName}`;
const thumbPath = join(workingDir, thumbName);
// Resize source image
await sharp(tmpFilePath)
.resize(size, size)
.toFile(thumbPath);
// Upload to GCS
return bucket.upload(thumbPath, {
destination: join(bucketDir, thumbName)
});
});
// 4. Run the upload operations
await Promise.all(uploadPromises);
// 5. Cleanup remove the tmp/thumbs from the filesystem
return fs.remove(workingDir);
});
Would greatly appreciate any feedback!
I just had the same problem, for unknown reason Firebase's Resize Images on purposely remove the download token from the resized image
to disable deleting Download Access Tokens
goto https://console.cloud.google.com
select Cloud Functions from the left
select ext-storage-resize-images-generateResizedImage
Click EDIT
from Inline Editor goto file FUNCTIONS/LIB/INDEX.JS
Add // before this line (delete metadata.metadata.firebaseStorageDownloadTokens;)
Comment the same line from this file too FUNCTIONS/SRC/INDEX.TS
Press DEPLOY and wait until it finish
note: both original and resized will have the same Token.
I just started using the extension myself. I noticed that I can't access the image preview from the firebase console until I click on "create access token"
I guess that you have to create this token programatically before the image is available.
I hope it helps
November 2020
In connection to #Somebody answer, I can't seem to find ext-storage-resize-images-generateResizedImage in GCP Cloud Functions
The better way to do it, is to reuse the original file's firebaseStorageDownloadTokens
this is how I did mine
functions
.storage
.object()
.onFinalize((object) => {
// some image optimization code here
// get the original file access token
const downloadtoken = object.metadata?.firebaseStorageDownloadTokens;
return bucket.upload(tempLocalFile, {
destination: file,
metadata: {
metadata: {
optimized: true, // other custom flags
firebaseStorageDownloadTokens: downloadtoken, // access token
}
});
});
"Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT" was working with viewer version 6, but when I upgrade viewer version to 7.*, its not working.
I have tried to handle "Autodesk.Viewing.GEOMETRY_LOADED_EVENT", and then call the model.getObjectTree() function, but I get the following error
{instanceTree: null, maxTreeDepth: 0, err: undefined}
How can I handle the object_tree_created event for viewer 7 in my code?
Obviously the model database (which contains object tree data) failed to load (and hence the object tree event was not fired and the object tree was not accessible) and it could have been for incorrect code or networking. Did you get other errors especially network interruptions in your browser's dev tools when loading the model? What is your code to load the model? If loading from Forge did you follow the migration guide and here to use loadDocumentNode?
Autodesk.Viewing.Initializer({ env: 'AutodeskProduction', getAccessToken}, () => {
const viewer = new Autodesk.Viewing.GuiViewer3D(container);
Autodesk.Viewing.Document.load(urn, viewerDocument =>{
var defaultModel = viewerDocument.getRoot().getDefaultGeometry();
viewer.loadDocumentNode(viewerDocument, defaultModel);
I am trying to load a trained keras model into web browser using tensorflowjs.
I was able to convert the keras model to tensorflowjs model but unable to load model in chrome extension.
My background.js code to load model
async function app() {
alert('Loading model..');
model = await loadModel("model.json");
alert('Sucessfully loaded model');
}
chrome.runtime.onInstalled.addListener(function(details) {
alert("extension loaded");
chrome.tabs.executeScript(null,
{file:"https://cdn.jsdelivr.net/npm/#tensorflow/tfjs#1.0.0/dist/tf.min.js"});
app();
});
THe url "https://cdn.jsdelivr.net/npm/#tensorflow/tfjs#1.0.0/dist/tf.min.js" is added in permissions key in manifest file.
When i try to laod the extension it fails givind message loadModel is not defined.
Any suggestions on fixing this issue?
loadModel is not defined.
1 - Make sure that the script is loaded in the background process of the tabs
2 - You need to use tf.loadModel() instead of loadModel()
I upgraded the forge viewer version of my solution to 6.* to utilize the latest released feature "Document browser extension" as it mentions here
This extension doesn't appear for me, please help.
I got it to work after some experimenting.
Here is my workflow in case you still need it.
First, initialize the viewer:
// initialize the viewer
Autodesk.Viewing.Initializer(adOptions, () => {
// when initialized, call loading function
this.loadDocument(encodedUrn);
});
Then, load your document in the function called above:
// load the document from the urn
Autodesk.Viewing.Document.load(
encodedUrn,
this.onDocumentLoadSuccess,
this.onDocumentLoadFailure,
);
In the success callback you can now do the following:
onDocumentLoadSuccess(doc) {
// get the geometries of the document
const geometries = doc.getRoot().search({ type: 'geometry' });
// Choose any of the available geometries
const initGeom = geometries[0];
// and prepare config for the viewer application
const config = {
extensions: ['Autodesk.DocumentBrowser'],
};
// create the viewer application and bind the reference of the viewerContainer to 'this.viewer'
this.viewer = new Autodesk.Viewing.Private.GuiViewer3D(
this.viewerContainer,
config,
);
// start the viewer
this.viewer.start();
// load a node in the fetched document
this.viewer.loadDocumentNode(doc.getRoot().lmvDocument, initGeom);
}
I hope this will make it work for you as well. What helped me was the reference to the loadDocumentNode function in this blog post.