Export HTML5 plug-in

This topic has been viewed 23193 times and has 30 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Can I check this getClosestItemAt method ? Where is object's coordinates ? If I write x an y direct in code - this method still return null. I take x y coordinates from js console after selected object by code. i.e.:
selecting object:

Code: Select all

HOME.setSelectedItems(itemSel);
console.log(itemSel);
and I take x y from itemSel[0].x and itemSel[0].y
I write this to my listener (from now always return this coordinates), and still i have null after use getClosestItemAt(x,y).

I thought i have to translate x,y from mouse, to have always the same coordinates, independed from actual view of camera, coresponding with object's x and y.
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Or maybe this is the problem. Shown after click on canvas.

Code: Select all

Error: WebGL warning: drawArrays: Feedback loop detected between tex target 0x0de1, tex unit 0, levels 0-0; and framebuffer attachment 0x8ce0, level 0.
viewmodel.min.js:20:53017
Error: WebGL: No further warnings will be reported for this WebGL context. (already reported 32 warnings) viewmodel.min.js:20:53017 
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Export HTML5 plug-in

Post by Puybaret »

The problem is that you read too quickly the setSelectedItems jsdoc [:(]
Emmanuel Puybaret, Sweet Home 3D creator
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

I don't understand. First of all I read all furnitures to table (FURNITURES[]). After this i print the links to select every funriture ( from this table). After click i do this:

Code: Select all

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].x);
		var itemSel2 = HOME.getSelectedItems();
		console.log("Read selected:" + a +", name:"+itemSel2[0].x);

every furniture has his own x and y coordinates. In console I have all object (with many data) in room (every furniture) after console.log(FURNITURES);
This is not problem with to fast reading.
How can I read proper x and y for one furniture ? (to check getClosestItemsAt)
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Maybe my questions are stupid and for many of You - "groundless", but I realy want understand structure of sweethome3d (in HTML5). Most (in my opinion - almost all) posts on this forum concerns on java version and problems with aplication ( directly on "painting" models). Can you show me the way to do this ? For example - if I confirm what x,y coordinates work with getClosestItemsAt, I will find the way how to calculate x,y depend of actual camera view. I want to eliminate errors before I started, I want to be sure I'm not making a simple mistake.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Export HTML5 plug-in

Post by Puybaret »

Your questions are not stupid, but most contributors in the forum are Sweet Home 3D users, not programmers (and even less JavaScript programmers). If you want to understand how to use Sweet Home 3D JS, learn how to use the debugger in your browser, this will help you in many cases.
By the way, [font=courier new]getClosestItemsAt[/font] method takes in parameter 2D coordinates, so translating to canvas space just consist of substracting [font=courier new]rect.x[/font] and [font=courier new]rect.y[/font] from [font=courier new]e.clientX[/font] and [font=courier new]e.clientY[/font]. Measuring pixel locations at screen with your mouse pointer would have given you the solution...
Emmanuel Puybaret, Sweet Home 3D creator
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Before I ask and write more question - i checked this - it's not working. I thought i have to recalculate x,y from plain rec to virtual canvas (2d to 3d coordinates - x,y only of course). I was ready to check every x,y combination to check proper work getClosestItemsAt function.
I change my code, this part:

Code: Select all

function getMousePos(canvas, evt) {
        var rect = canvas.getBoundingClientRect();
		console.log(rect);
		var x1 = evt.clientX - rect.x;
		var y1 =  evt.clientY - rect.y;
        return {
          x: (x1),
          y: (y1)
        };
      }

	  
	  
      canvas.addEventListener("mouseup", function (e) {
        var mousePos = getMousePos(canvas, e);
		var x = mousePos.x;
		var y = mousePos.y;
		console.log('mousePos:'+x+','+y);
		var cams = HOME.getCamera();
		console.log(cams);
		var obj = HPC.getComponent3D().getClosestItemAt(x, y);
		console.log("Finded objekt:"+obj);
         
      });

console after loading:

Code: Select all

Error: WebGL warning: drawArrays: Drawing to a destination rect smaller than the viewport rect. (This warning will only be given once) viewmodel.min.js:20:53017
All items: viewHome.html:118:7
Array(98) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
viewHome.html:119:4
All furnitures: viewHome.html:120:4
Array(80) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
viewHome.html:121:4
WebGLRenderingContext { canvas: canvas#viewerCanvas.viewerComponent
, drawingBufferWidth: 800, drawingBufferHeight: 600 }
viewHome.html:133:3
console after click on canvas:

Code: Select all

DOMRect { x: 11, y: 11, width: 802, height: 602, top: 11, right: 813, bottom: 613, left: 11 }
viewHome.html:137:3
mousePos:640,214 viewHome.html:152:3
Object { properties: null, name: null, x: 329.2859606627597, y: 529.2522494347633, z: 1276.0331000000006, yaw: 4.714197, pitch: 1.5707964, fieldOfView: 1.0995575, time: 1492084800000, lens: 0, … }
viewHome.html:154:3
Finded objekt:null viewHome.html:156:3
Error: WebGL warning: clear: This operation requires zeroing texture data. This is slow. viewmodel.min.js:20:55899
Error: WebGL warning: drawArrays: Texture level 0 would be read by TEXTURE_2D unit 0, but written by framebuffer attachment COLOR_ATTACHMENT0, which would be illegal feedback.
viewmodel.min.js:20:53017
Error: WebGL: No further warnings will be reported for this WebGL context. (already reported 32 warnings) viewmodel.min.js:20:53017 


make this errors problem?
code is ok ?
http://smarted.pl/sh3d/viewHome.html#
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

somebody can can check the code ? Now it's ok ? If ok, why it not working ? Maybe the errors are the problem ? Ho to eliminate this errors ?
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Somebody ????
boe666
Posts: 21
Joined: Wed Nov 21, 2018 2:28 pm
Country: POLAND
Contact:

Re: Export HTML5 plug-in

Post by boe666 »

Maybe, in first days of new year, somebody show my indolence.. I realy don't know why .getClosestItemAt(x, y) doesn't work....
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest