- This topic has 24 replies, 4 voices, and was last updated 3 years, 10 months ago by GLiFTeK.
-
AuthorPosts
-
2020-12-10 at 11:46 pm #36400jdockCustomer
Hi,
There seems to be an change with 3.5 that is affecting an approach I have used for ‘When Clicked’ events and cloned objects. I have been creating a When Clicked event with no object, then using the ‘if missed do…’ to return the Picked Object name, then decide what to do based on the name.
I have attached an example puzzle using the standard Cube template. This seemed to be an efficient approach compared to creating an event for every object I clone. In my project, I need to clone a lot of objects (think of Legos).
It seems with 3.5, the picked object name is coming back null. It seemed to work after updating the project, then stopped after I saved it. Seems to be replicable with the simple puzzle attached. It works at first, then stops returning the name with the Picked Object.
Perhaps this is not a good approach? Maybe it is a small bug in 3.5?
Thanks,
JonAttachments:
You must be logged in to view attached files.2020-12-11 at 1:43 am #36402GLiFTeKCustomerSometimes while debugging verge projects using its live server, things get stuck in the browser cache.
I find it useful to close it all down, including the verge process…
… clear browser cache (maybe not cookies).. Then try again.
Might be a solution to your issue.
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!2020-12-11 at 10:39 am #36415Yuri KovelenovStaffHi,
since you are using when clicked without a target object, then picked object should always return null. It still can be not null if you’re using another when clicked puzzle somewhere else. The reason is that picked object is a global variable, so depending on previous events happened in your app it may be null or not null.
2020-12-11 at 4:09 pm #36419jdockCustomerThanks guys – browser cache did not seem to affect the behavior, but a good thought.
Yuri, I know this is an odd approach, but in 3.4 and prior, the picked object always returned the mesh name. I put an example of 3.4 with this puzzle attached. Check out the console output. I was careful to name the original mesh Cube.0 so the clone name would be predictable (Cube.1, Cube.2, etc.). Here’s the 3.4 example: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:091950d814/applications/CloneTest/CloneTest.html
Here’s the exact same in 3.5: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/CloneTest35/CloneTest.htmlJust updating the project after upgrade to 3.5 does not affect the behavior, but changing a puzzle and saving does.
Again, if this is a terrible approach, I am open to other ideas to be able to capture click events of cloned objects. Here’s my production project that involves a lot of cloning: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/ShoreStationDock/index.html
Perhaps a custom routine? I’m not a great coder, so I’d need help:)
Thanks,
Jon2020-12-14 at 6:29 am #36467Yuri KovelenovStaffJust updating the project after upgrade to 3.5 does not affect the behavior, but changing a puzzle and saving does.
Yep, re-saving your Puzzles after updating to a new version is a right (and sometimes necessary) thing to do. Or you mean it gets broken after resaving the Puzzles? If so, please attach your cube test application so that we take a look!
Here’s my production project that involves a lot of cloning: https://cdn.soft8soft.com/AROAJSY2GOEHMOFUVPIOE:ff74dcf89a/applications/ShoreStationDock/index.html
Perfect!
2020-12-14 at 2:16 pm #36483jdockCustomerHere are the two versions. CloneTest.zip if from 3.4, CloneTest35.zip is from 3.5.
2020-12-14 at 2:17 pm #36485jdockCustomerHere’s 3.5
2020-12-14 at 2:18 pm #36487jdockCustomerIf the ’empty when clicked’ approach is bad, maybe some guidance in creating a custom event handler that just returns the mesh name from any click?
2020-12-15 at 11:25 am #36518Yuri KovelenovStaffYep, CloneTest35 works for me, and CloneTest does not (I’m not sure how it even worked for you )
maybe some guidance in creating a custom event handler that just returns the mesh name from any click?
well, may be you could use a variable, to which you can save your object name, and which will be updated with new object names from the picked object puzzle.
2020-12-15 at 8:37 pm #36541jdockCustomerYuri,
I gave this a try. I created a list called ‘AllObjects’ and added all mesh objects to it. I have attached the puzzle where I add any new cloned objects to the ‘AllObjects’ list. It seems the When Clicked event does not see the change to the list. It looks like the event only pays attention to the contents of the list when it is initiated – correct?
Thanks,
JonAttachments:
You must be logged in to view attached files.2020-12-15 at 11:38 pm #36549jdockCustomerOK, so I did find a workaround: The attached puzzle worked (not in the preview window though). The code in the ‘Exec Script’ puzzle is:
// Built-in variables: app, v3d, VARS, PROC
var mouse = new v3d.Vector2();
var raycaster = new v3d.Raycaster();
mouse.set((VARS[‘mouseX’] / window.innerWidth) * 2 – 1, – (VARS[‘mouseY’] / window.innerHeight) * 2 + 1);
raycaster.setFromCamera(mouse, app.camera);var intersects = raycaster.intersectObjects(app.scene.children);
if (intersects.length > 0) {
VARS[‘temp’] = intersects[0].object.name;
} else {
VARS[‘temp’] = null;
}This returns the name of the mesh if hit, or null if not.
Thanks,
JonAttachments:
You must be logged in to view attached files.2020-12-16 at 10:19 am #36561Yuri KovelenovStaffIt seems the When Clicked event does not see the change to the list. It looks like the event only pays attention to the contents of the list when it is initiated – correct?
Yep, the event listener is only applied to the original contents.
OK, so I did find a workaround
Awesome! Thanks for sharing your solution.
2020-12-21 at 11:29 pm #36789jdockCustomerYuri,
I have having difficulty getting the ‘code puzzle’ to work with the 3D embedded. I have the 3D window in an iframe with an id = 3dFrame. I seem to be getting the correct mouse coordinates, but the raycaster doesn’t seem to intersect anything. Any ideas?
Here’s my attempt to refer to the embedded window height and width:
`// Built-in variables: app, v3d, VARS, PROC
var mouse = new v3d.Vector2();
var raycaster = new v3d.Raycaster();
var x = document.getElementsByName(‘3dFrame’);
mouse.set((VARS[‘mouseX’] / x.innerWidth) * 2 – 1, – (VARS[‘mouseY’] / x.innerHeight) * 2 + 1);
raycaster.setFromCamera(mouse, app.camera);var intersects = raycaster.intersectObjects(app.scene.children);
if (intersects.length > 0) {
VARS[‘temp’] = intersects[0].object.name;
} else {
VARS[‘temp’] = null;
}Jon
2020-12-22 at 10:19 am #36822Yuri KovelenovStaff2020-12-23 at 10:55 pm #36849jdockCustomerYuri,
I tried something slightly different. If you look at the visual_logic.js content and go to the function initObjectPicking function inside registerOnClick, this changed from 3.4 to 3.5:
if (!isPicked) {
_pGlob.pickedObject = ”;
cbIfMissedDo(event);
}if I change this to as it was in 3.4, any intersected object from the mouse event gets returned with PickedObject, but isPicked remains false:
if (!isPicked) {
_pGlob.pickedObject = objName;
cbIfMissedDo(event);
}
I changed this in the visual_logic.js and it works as before. Any chance this could be put back into 3.5? If not, I can just remember to tweak it.
Thanks,
Jon -
AuthorPosts
- You must be logged in to reply to this topic.