convert .obj to .glb using npm+laravel - javascript

I am stopped at one point for 2 days and not able to fix.
Can anyone please help me through this?
Question: How can I convert .obj file o .glb?
I used obj2gltf package of npm and search to implement it with Laravel but nothing helped. so now I am confused that does I am doing anything wrong?
Also I tried this article to use the node with PHP/Laravel and another solution from stack overflow.
Can anyone please help me through this?
Thank you in the advance guys.

Unfortunately, there is no solution in pure PHP. But you may create a JS script that converts your files using obj2gltf lib and then execute the script from the PHP in some kind of like that:
//php
$converter = '/path/to/your/script.js';
$objFilePath = '/path/to/your/3d.obj';
$glbFilePath = trim(shell_exec("node $converter $objFilePath"));
And let's say, your JS is converting your 3D object and then returning a path to the converted file:
// script.js
const obj2gltf = require("obj2gltf");
const fs = require("fs");
obj2gltf(process.argv[2])
.then(function (gltf) {
const data = Buffer.from(JSON.stringify(gltf));
fs.writeFileSync("result.gltf", data);
console.log(process.cwd() + "/result.gltf");
});

Related

Save data to an external file

Hello, I am currently developing a website for my personal needs for which I need to be able to regularly save data in a "data.json" file, which I can then retrieve for later use.
I then remembered that I had already used the "file sync" module of NodeJs before, but this time I can't manage to use it with my project as it doesn't seem to apply to my html files...
I suspect that there are other easier solutions or that I must be using NodeJs wrong in this case.
I use the sublime text editor and I work on 2 html files linked to the same script.js and style.css file
Would you have solutions to propose to me?
Thank you, cordially,
Florent
Let's say at the backend.
const htmlTxt = `
<html>
...
</html>
`
// write the file locally
fs.writeFileSync("sampleHtml.html", htmlTxt);
// read the contents of the file
console.log(fs.readFileSync("sampleHtml.html", "utf8"));
I would use the File system module.
So on your nodeJS server, you would have to add:
const fs = require('fs');
then create your json:
let jsonElement = {
aa: 'aa',
test: 123,
};
let data = JSON.stringify(jsonElement);
And save it to file
fs.writeFileSync('json_file.json', data);
https://nodejs.org/api/fs.html

Extracting Pure Javascript from NodeJS project [duplicate]

I don't know how to get a javascript file to work for web-browser functionalit, when it's coded as node.js.
The code in question is from a github graphenejs-lib. I want to convert this node.js code into js:
import {Apis} from "graphenejs-ws";
var {ChainStore} = require("graphenejs-lib");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
console.log("connected to:", res[0].network);
ChainStore.init().then(() => {
ChainStore.subscribe(updateState);
});
});
let dynamicGlobal = null;
function updateState(object) {
dynamicGlobal = ChainStore.getObject("2.1.0");
console.log("ChainStore object update\n", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);
}
There is another github from the same developer, steemjs-lib, that shows both the node.js use, and the browser use in the README default page.
I don't know how to make graphenejs-lib into browser javascript, like the steemjs-lib has been made into a regular javascript working version. I contact the dev, but have yet to receive a response.
I figured other people actually know how to do what the dev did for steemjs-lib, and get the graphenejs-lib to work in a browser.
Can you help me out? Thank you.
You can use Browserify to help you with that:
Note that not all of the Node's APIs will be available in the browser.
Use browserify. https://wzrd.in/ will package it for you if you just want to use that one library. https://wzrd.in/standalone/graphenejs-lib#latest
<script src="https://wzrd.in/standalone/graphenejs-lib#latest"></script>
<script>
const {ChainStore} = graphenejsLib;
...
</script>

How to wrap node express output so that it can be included as javascript?

Trying to modify node.js express to wrap the standard output in javascript (utilising document.write) so that I can include it into other HTML files. I want to encode the output at the express level and decode it at the client.
Edit: I want to create a standard node app that generates HTML output but wrap it just before sending with the javascript. This is so I can continue to utilise express-handlebars and other add ons without disruption to the output.
If this is already a thing in node please point me to documentation on how to achieve it? Otherwise I'm looking for where to change the code in express to wrap each output.
For clarity; to answer please include a reference the correct express file(s) and start with existing code to produce a modified version that achieves my goal.
The Express version I am looking at is 4.15.4. I've viewed the code and found the index.js and route.js files (https://github.com/expressjs/express/tree/master/lib/router) but don't understand enough to know where to modify the code.
Example
My initial goal would be for my node app to return encoded HTML wrapped in code similar to the following:
var str = "<encoded content goes here>";
document.write(decodeURI(str));
Example way to call my node from HTML:
<script src='http://localhost:3000/'></script>
Feel free to comment on the approach if you have an opinion.
Thanks!
I think I worked it out.
In file https://github.com/expressjs/express/blob/master/lib/response.js # line 116 I added the following code:
chunk = "str = \""+encodeURI(body)+"\";\ndocument.write(decodeURI(str));\n";
Seems to have worked.
So:
res.send = function send(body) {
var chunk = body;
var encoding;
var len;
var req = this.req;
var type;
// settings
var app = this.app;
<added my code here>
// allow status / body

Photoshop script to ignore .ds_store

my skills with javascript are about 0, I only know some html and css.
I hope someone can still help me solving this.
I am working in photoshop with a script that grabs pictures, does some magic and places them into a psd file as layers. As you might guess i haven't written the script but its needed for work.
The problem is, its grabbing the .ds_store files as well as the images, which results in an error warning.
this is the line that defines the source:
var taschenQuelle = Folder.selectDialog();
alert("Click OK to start processing.", "TEASER 2014");
var listeAllerTaschen = taschenQuelle.getFiles();
How can I specify that its ignoring the system files?
Best,
Lukas
you can ignore .dotfile and get files have 3-characters file extension by using following a snippet.
//#target "Photoshop"
var f = Folder.selectDialog("select");
alert(f.getFiles(function (file) {return /^[^.]+\.[^.]{3}$/i.test(file.name)}));
thank you
mg

Displaying .dcm files with XTK's X.volume()

According to the lesson 15 I pass .dcm file to the volume. I get no errors (e.g. no parsing errors I faced before) but nothing is displayed. What could be wrong with the .dcm files?
Here is a excerpt of the code I use:
function demo(file){
var _dicom = [file];
var r = new X.renderer3D();
r.init();
var v = new X.volume();
v.file = _dicom.map(function(v) {
return file;
});
r.add(v);
r.render();
r.onShowtime = function() {
v.volumeRendering = true;
};
};
I pass the full file path here. Well, I'm not sure it's a correct wording, but I'd lile to know, what dicom settings or parameters could cause such a behaviour, no errors and no diplayed data. Thanks in advance.
Did you try to drag the .dcm file into http://slicedrop.com and see the same effect? DICOM support currently only exists for uncompressed DICOM files and we didn't get Ultrasound too work yet. So on uncompressed MR data or CT data in DICOM it should work.

Categories

Resources