Home › Forums › Programming › Access “app” from external JS
- This topic has 8 replies, 3 voices, and was last updated 2 years, 9 months ago by GLiFTeK.
-
AuthorPosts
-
2022-01-31 at 9:08 pm #48902justin_blenderCustomer
Hello,
I am trying to get some of your example custom shaders on github and apply the shader to an object on an existing scene which was created with the Verge3D App Mannager.
I did the following: copied the code from github into the App (into the function runCode(app) {}). In that example, some external modules from other files are being imported. So I downloaded those and re-linked them.
This was not working firstly because the myAwesomeApp.js is not a module thus you get the error ‘Cannot use import statement outside a module’.Instead I am binding new js file and declare it as a module.
function runCode(app) { let js = document.createElement("script"); js.type = "module"; js.src = "custom_shader.js" document.head.appendChild(js); }
Inside that file custom_shader.js now the modules are being imported. But once the code runs that file and gets to the point
app.scene.add(wireframe);
I am getting an error because the scene is undefined. So I understand from that file the ‘app’ is not accessabble.
That line was originallyv3d.scene.add(wireframe);
but I am trying to access the current scene of the App itself.
I have been researching for this for hours now. Sorry if the solution might be too obvious – but I am not getting it :/ Or maybe I am doing it totally wrong and there is an easier way.
I could “import” all those modules too by just copying them into the main app js code. But 1) that will make it all pretty messy and 2) I want to understand what I am not understanding here ;)
Thanks so much for your help.
Once that is solved I may likely stumble into the next problem…2022-02-01 at 7:06 am #48910Yuri KovelenovStaff2022-02-01 at 7:56 am #48914justin_blenderCustomerHello Yuri,
I was trying to implement this shader:
https://cdn.soft8soft.com/demo/examples/index.html#webgl_lines_fat_wireframe
——————————————————————-
I just had a look at this one
https://argos.vu/V3D/examples/index.html#webgl_materials_wireframe
too, it seems to be a bit more simple. I KIND OF managed to implement it, but not without having troubles (see image)
I dont know which of both is a “three.js” compatible one.
Attachments:
You must be logged in to view attached files.2022-02-01 at 12:51 pm #48934Yuri KovelenovStaff2022-02-01 at 1:16 pm #48935justin_blenderCustomerWait..What? There is ONE simple tick box for this?
I saw this example before. But I did not find any puzzles nor code nor material setting. But now I found it. Thank you for guiding me there again.Would be still great to know how to get there through coding though. I see that three.js supports dashed lines for example. I will try more with my half-working example and get back here.
2022-02-01 at 2:37 pm #48940justin_blenderCustomerOk figured it out. For anyone interested this is the coding solution to create a simple wireframe material and apply it to an object. It is really that simple. I was totally going too far
Now need to find out more about v3d material librariesfunction runCode(app) { const material1 = new v3d.MeshBasicMaterial({ color: 0xe0e0ff, wireframe: true, }); app.scene.children[0].material = material1; }
2022-02-01 at 2:46 pm #48942Yuri KovelenovStaff2022-02-01 at 3:28 pm #48943justin_blenderCustomerYou are welcome. As for the dashed material I copied a code snippet from your “dashed lines” example and tried to apply a dashed line to an object.
const material2 = new v3d.LineDashedMaterial({ color: 0xff0040, linewidth: 1, scale: 1, dashSize: 3, gapSize: 1 }); let x_geo = app.scene.children[1].geometry; x_geo.toNonIndexed(); const line = new v3d.Line(x_geo, material2); line.computeLineDistances(); app.scene.add(line);
I was getting the console warning
‘v3d.js:1 v3d.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.’
But still after adding the line
x_geo.toNonIndexed();
it doesnt workProbably doing something essentially wrong here. But as long I am not getting errors I am confident to be close to the solution. Any suggestion?
2022-02-02 at 6:38 am #48949GLiFTeKCustomerHi, if interested, you might check out my Quad Wireframee plugin.
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature! -
AuthorPosts
- You must be logged in to reply to this topic.