JSON model does not load correctly in three js - three.js

I am trying to load the json model in this url : https://jsoneditoronline.org/?id=3c08fd2e9d4a4a01ab86ffc23ffbe347 into my three js file using this code :
var loader = new THREE.ObjectLoader();
loader.load("models/unique-house.json",function ( obj ) {
scene.add( obj );
console.log(JSON.stringify(obj));
scene.traverse(function(children){
objects.push(children);
});
});
But I am getting only the object named Stone as the output, all the other objects are not added. The console.log statement prints this object in this link :
https://jsoneditoronline.org/?id=e6b9edcd19a24c359ec07415d47beb52
And my output is :
The expected output is :
I downloaded the model from https://clara.io/view/dab2e20a-3ba1-46fe-9cde-7e4e75a1aca5
Can anyone please tell me if there is a problem with the json file or if there is a problem in the way the json file has been parsed?

Related

How to write data in a file without replacing the existing data using cy.writeFile

I'm trying to save some data from API in a .json file using cy.writeFile method, but my code is replacing the existing data.
What I need is to add additional data.
cy.intercept('POST', 'http://viasphere.localhost/sites/datatable').as('response')
cy.contains('Sortir').click()
cy.wait('#response').get('#response').then(xhr => {
console.log(xhr)
let siteID = xhr.response.body.data[0].id
let creationDate = xhr.response.body.data[0].created_at
let RM = xhr.response.body.data[0].metal_rollout
let clientGroup = xhr.response.body.data[0].client_contact_group
cy.writeFile('SiteAPIdata.json', {siteID2: siteID})
After the run, the data existing inside the SiteAPIdata.json file is being replaced by the new data.
The SiteAPIdata.json file is located in cypress/fixtures/ folder.
Thank you!
Assuming you want to append the new data to the existing data, that can easily be accomplished by using cy.readFile() before writing.
...
cy.readFile('SiteAPIdata.json').then((data) => {
data.siteID = siteID;
cy.writeFile('SiteAPIdata.json', data);
})

JS React GLTF loader query parameters

I have the .gltf and .bin files in a azure storage account. Downloading these files requires a SAS URI that follows the pattern: https://<saName>.blob.core.windows.net/<pathToBlob>?<sas>. While I build a SAS that is valid for downloading both the .gltf and .bin files, I am running into an issue where I specify the .gltf URL to the useGLTF hook. That call goes through, but when fetching the .bin file, under the hood the loader is dropping the query params, resulting in a URL https://<saName>.blob.core.windows.net/<pathToBin> which fails.
Is there a way to make the loader keep the query parameters?
For anyone running into this, you can use the setURLModifier(). In my case, this looks as:
const { scene, animations } = useGLTF(props.path, false, false, (loader) => {
loader.manager.setURLModifier((url) => {
# alter the URL and return the new value
return url;
})
});

Unable to view PDF attached with ServiceNow table records

I am able to successfully attach PDF file with ServiceNow table record using GlideSysAttachment API and attachment.write() function in script, however whenever I download and try to open same, I get the error shown in below screenshot.
Code snippet
(function execute() {
try{
var rec = new GlideRecord('incident');
var attachment = new GlideSysAttachment();
var incidentSysID = incident.number;
rec.get(incidentSysID);
var fileName = 'Test_Incident.pdf';
var contentType = 'application/pdf'; // Also tried with contentType as 'text/pdf'
var content = pdf_content;
var agr = attachment.write(rec, fileName, contentType, content);<br>
gs.info('The PDF attachment sys_id is: ' + agr);
}catch(err){
gs.log('Got Error: ' + err);
gs.info(err);
}
})()
I also tried "AttachmentCreator" with ecc_queue within script but same error occurs. Below is code for it.
(function execute()
{var attCreator = new GlideRecord('ecc_queue');
attCreator.agent = "AttachmentCreator";
attCreator.topic = "AttachmentCreator";
attCreator.name = "Test.pdf" + ":" + "text/pdf";
//Also tried, "Test.pdf:application/pdf"
attCreator.source = "incident"+":"+ incident.number;
// Record Table name and sys_id of the particular record
var content = pdf_content; // pdf_content is any string variable
var stringUtil = new GlideStringUtil();
var base64String = stringUtil.base64Encode(content);
var isValid=GlideStringUtil.isBase64(base64String);
var base64String= gs.base64Encode(content);
gs.info("Is valid base64 format in ecc_queue ? "+ isValid);
attCreator.payload = base64String; //base64 content of the file
attCreator.insert();
})()
I am able to attach and view excel and word files with similar scripts without any issues. I have checked system properties for attachments but everything looks fine. I am able to view the PDF file uploaded from UI to particular table records however not the one I attach via REST API or scripts.
I have also tried sending encoded data as bytes, base64 or simple string but nothing seems to work. I don't get any errors and attachment id is returned each time on creation of attachment.
After modifying my code slightly for above functions w.r.t scoped application instead of global; I got some information from logs when I debug:
05:38:38.411 Security restricted: File type is not allowed or does not match the content for file Test.pdf
05:38:38.410 Security restricted: MIME type mismatch for file: Test.pdf. Expected type:application/pdf, Actual type: text/plain
05:38:38.394 App:XYZ App x_272539_xyz_ap: Is valid base64 format in ecc_queue ? true
First a comment: This line in your code is accidentally working -- make sure you understand that a task number is not the object sys_id
var incidentSysID = incident.number; // should be incident.sys_id
Next, it's unclear where the PDF content is coming from. IF your complete code is listed, I would expect the errors given as you have noted that pdf_content is "any string variable."
ServiceNow does have a the capability to create a PDF from an HTML argument.
Generating a PDF from HTML
Here's a helpful blog post for getting a PDF (Platform generated) of an existing record:
Love PDF? PDF loves you too

Convert Document.getFileAsync data to FormData for Office file uploading

I'm working on Office Add-in project, I need to get current Office file and upload to our server.
Below is upload file from File Browser to our server
var fdata = new FormData();
fdata.append('data', file);
fdata.append('totalFileSizeBytes', file.size);
fdata.boundary = '----boundary';
xhr.send(fdata);
And I got Office file info via function: Document.getFileAsync (https://dev.office.com/reference/add-ins/shared/document.getfileasync)
But I don't know how to convert File info from Document.getFileAsync to FormData.
I tried read File info slice by slice then concat to an array and pass to FormData, but it wasn't success.
The answer is a bit late, but hopefully might help future folks looking for this - I wasted some time trying to figure this out.
The File object returned by the Document.getFileAsync is not usable with FormData. Also what the Microsoft Documentation shows you does not get you a file that you can just drop into FormData.
First, you'll have to combine the slices returned to a docdata array as per the Microsoft example shows (https://learn.microsoft.com/en-us/javascript/api/office/office.document?view=office-js#getfileasync-filetype--options--callback-). But then instead of creating a string out of it by using charCodeAt, you'll want just use the combined docdata array and do this:
const file = new File(
[new Uint8Array(docdata)],
'testfile.docx',
{ type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
);
Which you can then proceed to append to your FormData:
const fd = new FormData();
fd.append('file', file);
The new File() gave me an error. But the a new Blob() did the trick
var aFile = new Blob(
[new Uint8Array(docdata)],
{ type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
);
formData.append('file', aFile, 'testfile.docx');

Greasemonkey: using XPath to get elements from distant XML-document

What Im trying to do with my Greasemonkey script is:
to read some distant XML document;
convert it into XML object;
and then use XPath to get the elements inside of it.
The getElementsByTagName(TagName) method works fine with my XML-object, but evaluate("XPath expression") doesn't. Any suggestions? See the code below:
GM_xmlhttpRequest({
method: "GET",
url: "http://www.someserver.com/atom.xml",
onload: function(response) {
if (!response.responseXML) {
var xmlDoc = new DOMParser().parseFromString(response.responseText, "application/xml");
}
// this section works fine and returns the data of the first <entry>..</entry>
var snapEntries = xmlDoc.getElementsByTagName("entry");
alert (snapEntries[0].data);
// this section doesn't work for unknown reason and returns nothing
var snapEntriesXpath = xmlDoc.evaluate("//entry", xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
alert (snapEntriesXpath.snapshotItem(0).data);
}
});
IIRC, the .data attribute won't be present for every kind of search.
You probably need to use:
var snapEntriesXpath = xmlDoc.evaluate (
"//entry//text()", xmlDoc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
);
But several other issues could be at play. If that doesn't do it, (1) link to the exact XML file; use pastebin.com if necessary. (2) Report what Firefox's error console (CtrlShiftJ) reports.

Resources