How to do Zooming individually with two PerspectiveCameras with their two objects? - three.js

I have two objects in right and left side of window.
I want to zoom those objects individually when I hover it.
var itsLeftControls, itsRightControls;
itsRightControls = new THREE.TrackballControls(itsRightCamera);
itsLeftControls = new THREE.TrackballControls(itsLeftCamera);
document.getElementById('SubContainerLeft').onmouseover = function () {
aMouseOverActivate(itsLeftControls);
aMouseOverDeactivate(itsRightControls);
};
document.getElementById('SubContainerRight').onmouseover = function () {
aMouseOverActivate(itsRightControls);
aMouseOverDeactivate(itsLeftControls);
};
function aMouseOverActivate(theControl)
{
theControl.zoomSpeed = 0.8;
}
function aMouseOverDeactivate(theControl)
{
theControl.zoomSpeed = 0.0;
}
function animateLeft()
{
requestAnimationFrame(animateLeft);
renderLeft();
}
function renderLeft()
{
itsLeftControls.update();
itsLeftRenderer.render(itsLeftScene, itsLeftCamera);
}
function animateRight()
{
requestAnimationFrame(animateRight);
renderRight();
}
function renderRight()
{
itsRightControls.update();
itsRightRenderer.render(itsRightScene, itsRightCamera);
}
if I hover in left side and try to zoom with mouse scrolling wheel, it is working fine. after that when I hover in right side, I can see that same zooming effect in right side also without scrolling mouse.
How to fix this?

TrachballControls take a optional second argument that is the dom element onto which it will attach the mouse event listeners.
If this argument is not supplied, it will attach the event listeners to the document.
This means that both your trackball controls are listening for events on the document (rather than their respective containers which I think you want.)
So just send your scene container divs as the second arguments to TrackballControlls and you should be good to go.
var leftContainer = document.getElementById('SubContainerLeft');
var rightContainer = document.getElementById('SubContainerRight');
var itsRightControls = new THREE.TrackballControls(itsRightCamera, rightContainer);
var itsLeftControls = new THREE.TrackballControls(itsLeftCamera, leftContainer);

Related

Tooltip disappears when moving leaflet map

I add markers to the map and place them in the markercluster. For markers that are not clustered, I want to show the tooltip that I attach to the marker when I create it.
var geoMarkers = L.markerClusterGroup({ removeOutsideVisibleBounds:true, chunkedLoading: true, chunkProgress: this._updateProgress });
//start loop create markers
var marker = new L.marker(latlng, { icon: icon } );
marker.bindPopup(L._("Loading.."));
marker.bindTooltip(' text ');
geoMarkers.addLayer(marker);
//end loop
map.addLayer(geoMarkers);
map.on('layeradd', function(event) {
var layer = event.layer;
if (layer instanceof L.Marker && !(layer instanceof L.MarkerCluster)) {
layer.openTooltip();
}
});
To do this, I followed advice and listen for the layeradd event. When loading the map and moving to new markers, everything works. However, at any movement of the map, on those markers where the tooltip is already open, it is closed, since the layeradd event does not affect them. There is only one way to see the hint on them again - to zoom out so that the marker "hides" in the cluster and then again increasing the scale, I see the hint again. It is desirable that it be always present when the marker is not hidden in the cluster.
I ask for help or hints.
You can use the permanent tooltip option in order to maintain the visibility of your marker. Check here for official docs.
...
var geoMarkers = L.markerClusterGroup({ removeOutsideVisibleBounds:true, chunkedLoading: true, chunkProgress: this._updateProgress });
//start loop create markers
var marker = new L.marker(latlng, { icon: icon } );
marker.bindPopup(L._("Loading.."));
marker.bindTooltip(' text ', { permanent: true} ); // here define it
geoMarkers.addLayer(marker);
//end loop

Same data routine "CalcPrecio" works fine called from a button, but breaks when called from a Canvas event, in Lightswitch HTML client

This is jscript over Lightswitch HTML Client
Same routine Works fine called from a Button, but fails when called from a Canvas event, showing an undefined data error.
// Creates a Canvas and add an eventlistner Works fine
myapp.AddEditLito.Montajes_render = function (element, contentItem) {
var itemTemplate = $("<canvas id='myCanvas' width='600' height='150'></canvas>");
var canvas = myCanvas;
myCanvas.addEventListener('mousedown', function (event) {
var context = canvas.getContext('2d');
DibTriangulo(screen, 50); // Draws a triangle, everything fine until here
// here is the problem,
CalcPrecio(screen, 1); // breaks with "Undefined Data.. etc."
}, false);
};
// Called from a Button, same routine works perfect!!
myapp.AddEditLito.Button1_execute = function (screen) {
CalcPrecio(screen, 1); // Works fine
};
// This routine Works perfect called from a button, but fails when called from a Canvas event!
function CalcPrecio(screen, col) {
$.each(screen.Liquidas.data, function (i, p) {
p.valor = p.cantidad * p.unitario;
});
};
//What I´m doing wrong? Heeeelp!
This problem is a result of calling your DibTriangulo and CalcPrecio routines from your canvas' mousedown event handler with just screen as the first parameter.
In your mousedown event handler and the _render closure it's defined in, the screen object is not specifically set to refer to the LightSwitch screen instance and instead simply refers to the window.screen object.
To resolve this you can simply change your code to use contentItem.screen as shown in the following revised _render method:
myapp.AddEditLito.Montajes_render = function (element, contentItem) {
var itemTemplate = $("<canvas id='myCanvas' width='600' height='150'></canvas>");
var canvas = myCanvas;
myCanvas.addEventListener('mousedown', function (event) {
var context = canvas.getContext('2d');
DibTriangulo(contentItem.screen, 50); // Changed to pass in contentItem.screen
CalcPrecio(contentItem.screen, 1); // Changed to pass in contentItem.screen
}, false);
};
The reason using just screen works in your button's _execute method is because the _execute method receives the LightSwitch screen object as its parameter (which you then use when calling your CalcPrecio method).

Tracking frames and/or time during an animation

Can I call a function(one that will make another object visible/invisible) on a specific animation frame or time? I would like to have arrows describe the movement of the animation at certain times during the animation. While I can just make them visible when I start the animation and make them invisible when the animation stops, I would like to specify ranges inside the animation to do this
playPatientAnim: function (anim, callback) {
var pending = 1;
var me = this;
var finish = callback ? function () {
if (pending && !--pending) {
callback.call(me, anim);
}
} : null;
me.currentPatient.skinned.forEach(function (mesh) {
mesh.animations.forEach(function(anim){
anim.stop();
});
});
me.currentPatient.skinned.forEach(function (mesh) {
var animation = mesh.animations[anim];
animation.stop();
if (animation) {
pending++;
animation.onComplete = finish;
animation.play();
}
});
if (finish) {
finish();
}
}
You can make a mesh visible or invisible ( mesh.visible = false; //or true ). To change visibility at certain time you could use timestamp:
new Date().getTime() and calculate how you want to do the sequence of your animation.

How to hide and show scenes using three.js

I am creating scene using Three.js webgl library. I am having a texture in the first scene. Clicking on this texture, i am trying to navigate to the next scene. I have written a function to handle this scenario to move to the next scene. Clicking on this texture, it is moving to the second scene as expected, but it shows on top of the first scene. So, i would like to know How to programmatically show or hide scenes.
You can use something like:
function setVisibility (parent, node)
{
node.visible = parent.visible;
}
function traverseVisibility (parent, callback)
{
var child, i, num_children = parent.children.length;
for (i = num_children - 1; i >= 0; i--)
{
child = parent.children[i];
callback (parent, child);
traverseVisibility (child, callback);
}
}
yourNode.visible = false; // or true
traverseVisibility (yourNode, setVisibility);

How to move an image randomly on the screen of a view in mobile flex?

I have to create an mobile flex application with tabbed navigator view. One of the view must satisfy this condition: when the view is selected, an image will appear for one second and then disappear for half a second, then reappear at a random position on the screen of the view. This will repeat until another view is selected.
I'm new to Mobile Flex and I need your help.
Thanks you in advance.
Best regards,
HBLE
Use enterFrame event or a Timer to hide/show the image.
Set the image x and y properties to show the image at a specific position
Use Math.random() to generate a random number in the interval [0,1]
Important:
When tab is active call init();
When changing to other tab do not forget to stop the timer and remove event listeners.
(for performance reasons and to avoid memory leaks)
Sample code:
var isVisible:Boolean = false;
function init():void
{
// we show / hide with a delay of 1 second
var t:timer = new Timer(1000);
t.addEventListener(TimerEvent.Timer, onTimer);
t.start();
}
function onTimer(event:TimerEvent):void
{
if(isVisible)
{
hideImage();
}
else
{
showAndMoveImage();
}
isVisible = !isVisible;
}
function hideImage():void
{
myImage.visible = false;
}
function showAndMoveImage():void
{
// we reposition image in screen, assume image size is smaller then screen
myImage.x = Math.random() * (stage.width - myImage.width);
myImage.y = Math.random() * (stage.height - myImage.height);
myImage.visible = true;
}

Resources