Romania
Joined: Apr 24, 2014
Post Count: 676
Status:
Offline
Re: Export HTML5 plug-in
I'am not sure but could be a problem of browser rather than coding. Look at this answer
---------------------------------------- A computer program does what you tell it to do, not what you want it to do. Murphy's Law When all else fails, read the instructions. Murphy's Law If you don't like "AS IS", DIY. Dorin's law
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Export HTML5 plug-in
Thanks for trying to help Dorin, but your link points to problems in the Online version, not with the HTML5 viewer version. Anyway, you're not wrong when your speak about browsers, because the viewer could also not work correctly on some browsers (even if I don't hope so).
boe666, the most helpful code is the one tested on a real web server with a real SH3D file. So please, upload your failing HTML5 code on a public web server with a SH3D file. You could also use the very good JavaScript debuggers available in all modern browsers, and find what's wrong by yourself.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
POLAND
Joined: Nov 21, 2018
Post Count: 21
Status:
Offline
Re: Export HTML5 plug-in
ok. So I clean the code, and put all on this link: http://smarted.pl/sh3d/viewHome.html# As You can see - all object are selectable by code. But not by the mouse. Please check console.
Code below:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>View home with Sweet Home 3D HTML5 Viewer</title>
</td></tr></table> <div style="position: absolute; bottom: 5px; text-align: center; width: 95%; z-index: -1"> <a href="http://www.sweethome3d.com">Sweet Home 3D</a> HTML5 Viewer / Version 1.4 - Distributed under GNU General Public License </div>
<!-- Copy the following script to view your home in the previous canvas --> <script type="text/javascript"> var homeUrl = "test.zip"; var onerror = function(err) { if (err == "No WebGL") { alert("Sorry, your browser doesn't support WebGL."); } else { console.log(err.stack); alert("Error: " + (err.message ? err.constructor.name + " " + err.message : err)); } }; var onprogression = function(part, info, percentage) { var progress = document.getElementById("viewerProgress"); if (part === HomeRecorder.READING_HOME) { // Home loading is finished progress.value = percentage * 100; info = info.substring(info.lastIndexOf('/') + 1); } else if (part === Node3D.READING_MODEL) { // Models loading is finished progress.value = 100 + percentage * 100; if (percentage === 1) { document.getElementById("viewerProgressDiv").style.visibility = "hidden"; setTimeout(myfunction,1000); } } document.getElementById("viewerProgressLabel").innerHTML = (percentage ? Math.floor(percentage * 100) + "% " : "") + part + " " + info; };
var canvas = document.getElementsByTagName('canvas')[0];
function selectI(a) { var HOME = HPC.getHome(); var FURNITURES = HOME.getFurniture();
var itemSel = [FURNITURES[a]]; HOME.setSelectedItems(itemSel); console.log(itemSel); console.log("Selected by Link: ID:" + a +", name:"+itemSel[0].name); } function myfunction() { var UP = HPC.getUserPreferences(); UP.setAerialViewCenteredOnSelectionEnabled(true); var HOME = HPC.getHome(); var FURNITURES = HOME.getFurniture(); var ITEMS = HOME.getSelectableViewableItems(); console.log("All items: "); console.log(ITEMS); console.log("All furnitures: "); console.log(FURNITURES);
var tt = 'All FURNITURES:<br/>'; var i; for (i = 0; i < FURNITURES.length; i++) { tt += '<a href=\"#\" style=\"float:left;border:1px #000000 solid; padding:2px; margin:2px;\" onclick=\"selectI('+i+');\" >'+FURNITURES.name+'</a>'; } document.getElementById("PRitemlist").innerHTML=tt;
canvas.addEventListener("mouseup", function (e) { var rect = canvas.getBoundingClientRect; var x = e.clientX ;//- e.layerX; var y = e.clientY ;//- e.layerY; console.log('mouse pointer:' + x + ', ' + y ); console.log("Finded objekt:"); var obj = HPC.getComponent3D().getClosestItemAt(x, y); console.log("Finded objekt:"+obj);
POLAND
Joined: Nov 21, 2018
Post Count: 21
Status:
Offline
Re: Export HTML5 plug-in
Ok, so if nobody can help in this situation, maybe sombody can help - how to calculate z dimention and z,y depend of actual camera's position ? Where can I find proper values?
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Export HTML5 plug-in
I tried your program in Safari debugger and the object returned at the line
var obj = HPC.getComponent3D().getClosestItemAt(x, y);
was "almost" found. By "almost", I mean that your x,y coordinates are wrong, and you should translate them in canvas space, removing rect.x and rect.y (but rect can't be correct because you forgot brackets at the end of canvas.getBoundingClientRect).
You should really learn how to use a JavaScript debugger.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
POLAND
Joined: Nov 21, 2018
Post Count: 21
Status:
Offline
Re: Export HTML5 plug-in
I'm trying to understand this, i think it's depend on camera position (before i think the getClosestItemAt calculate this automaticaly) but without any examples i don't know how to start.
France
Joined: Nov 7, 2005
Post Count: 9426
Status:
Offline
Re: Export HTML5 plug-in
I wrote you how to fix your issue. Sorry, I can't help you more, it's really basic JavaScript.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
POLAND
Joined: Nov 21, 2018
Post Count: 21
Status:
Offline
Re: Export HTML5 plug-in
so, if I understand this proper. I have to translate x,y coordinates (given from flat rectangle) to coordinates in the actual perspective of my model's floor. After this, method getClosestItemAt fill return objects. Am I Correct ?