x3dom, rotation and hiding shapes - javascript

I'm currently working on this using x3dom: http://folk.ntnu.no/emilh/modell.htm , and I have two problems.
First one is that when I load my model, it appears in a awkward position, I'd like to automaticly flip it and zoom so that you see it from a better side. Currently I have no idea how to do this.
Secondly I'm trying to make a button that toggles the visibility on the outer shell of the model, I've identified the shapes that builds up the shell, but I don't know how to toggle their visibility. So if I have the ...., what can I do to it to make it hidden?
Sorry for mixing Norwegian and English on the site :P
And thanks in advance!

There are two ways of dealing with the zoom level.
Change the scale attribute of your transform, making the shape bigger.
Add a viewpoint node, like so
<viewpoint id="view_id" position='0 10 15' orientation='-1 0 0 0.5'></viewpoint>
The position and orientation values will depend on your scene.

It is asked long time ago but for people who have same problem the solution is like following:
You can use
<vievpoint position="0 0 250">
to change default zoom of your object. first and second parameters for x y coordinates and third one for zoom. If you want to zoom out you can use positive values, to zoom in you can use negative values.
Whole code is like this:
<x3d width='500px' height='400px'>
<scene>
<viewpoint position="0 0 250"></viewpoint>
<tramsform>
<inline url="path">
</transform>
</scene>
</x3d>

For the visibility you can use the transparency attribute on the material tag. http://doc.x3dom.org/author/Shape/Material.html
The shape is still there but you can modify the transparency of it.

Related

Is it possible for the user (camera) to stick to a animated static-body entity?

Is it possible to "stick" the user (camera/cursor) to an animated static-body entity as it moves?
For example, if I jump on to a static-bodied box which has an animation that moves it along the y-axis, how the user remain on that box? Similarly, if a box is animating its scale, when the camera is no longer "on" the box, why does it not fall?
With a moving platform, this is possible but a bit hacky. You'll need to attach a physics component to the camera, and neither dynamic-body nor static-body quite does the right thing. I've written a component in aframe-extras to do it, called kinematic-body. Usage:
<a-entity camera="userHeight: 1.6"
universal-controls
kinematic-body></a-entity>
Note that this only works with universal-controls, not the A-Frame default controls.
After that, you need the platform to not only move, but also update el.body.position and el.body.velocity on the entity, so that physics is properly synced. You can do this manually, or follow along with other examples in aframe-extras:
<a-box id="platform1"
width="4" height="0.25" depth="4"
position="7 0.125 -15"
velocity="0 0 0"
toggle-velocity="axis: z; min: -5; max: 5;"
static-body></a-box>
Working demo and source code.
Scaling a static-body is harder. The physics engine has no concept of expanding that way, so you'd probably need to edit el.body manually, and this may or may not work.
There are other ways to do this without physics too, such as pointing a raycaster down from the camera and detecting the current platform that way.

Three.js: Panorama Cube to Zoom In and Transition Into a Different Panorama Cube

I am new to Three.js. I am using this example with 6 image cube for panorama effect, where one can pan, zoom in and out around cubes.
https://threejs.org/examples/?q=panorama#webgl_panorama_equirectangular
I want to figure out how, at maximum zoom-in level, I can transition user into a different panorama cube (with different image source), mapped to this particular cube part. So I would, sort of, open the next scene to take user further to the next level in his journey.
This is nearly what Google Street View does when you click on arrows to move forward down the road.
I do not see many examples out there. I researched and saw this may be possible with creating 2 scenes? Any ideas how to make it functional I would appreciate.
Detecting WHEN to transition:
In the example given, the mouse events are all given. The zoom is handled in onDocumentMouseWheel by adjusting the camera's fov property. "Zoom In" reduces the fov, and "Zoom Out" increases it. It would be trivial to detect when the fov has reached a minimum/maximum value, which would trigger your transition to a new scene.
Detecting WHERE to transition:
The next step is determining into which new scene you will transition. You could do something hotspot-like, where you shoot a ray from the camera to see if it hit a particular place (for example a THREE.Sphere which you have strategically positioned). But for simplicity, let's assume you only have the 6 directions you mentioned, and that you're still using the example's mouse control.
Camera movement is handled in onDocumentMouseMove by updating the lat and lon variables (which appear to be in degrees). (Note: It seems lon increases without bounds, so for clarity it might be good to give it a reset value so it can only ever be between 0.0-359.99 or something.) You can get all math-y to check the corners better, or you could simply check your 45's:
if(lat > 45){
// you're looking up
}
else if(lat < -45){
// you're looking down
}
else{
// you're looking at a side, check "lon" instead
}
Your look direction determines to which scene you will transition, should you encounter your maximum zoom.
Transitioning
There are lots of ways you can do this. You could simply replace the texture on the cube that makes up the panorama. You could swap in a totally different THREE.Scene. You could reset the camera--or not. You could play with the lights dimming out/in while the transition happens. You could apply some post-processing to obscure the transition effect. This part is all style, and it's all up to you.
Addressing #Marquizzo's concern:
The lighting is simply a suggestion for a transition. The example doesn't use a light source because the material is a MeshBasicMaterial (doesn't require lighting). The example also doesn't use scene.background, but applies the texture to an inverted sphere. There are other methods one can use if you simply can't affect the "brightness" of the texture (such as CSS transitions).
I added the following code the the example to make it fade in and out, just as an example.
// These are in the global scope, defined just before the call to init();
// I moved "mesh" to the global scope to access its material during the animation loop.
var mesh = null,
colorChange = -0.01;
// This code is inside the "update" function, just before the call to renderer.render(...);
// It causes the color of the material to vary between white/black, giving the fading effect.
mesh.material.color.addScalar(colorChange);
if(mesh.material.color.r + colorChange < 0 || mesh.material.color.r + colorChange > 1){ // not going full epsilon checking for an example...
colorChange = -colorChange;
}
One could even affect the opacity value of the material to make one sphere fade away, and another sphere fade into place.
My main point is that the transition can be accomplished in a variety of ways, and that it's up to #Vad to decide what kind of effect to use.

Masked element in Snap SVG doesn't come into view when translated

I have a group of elements that are masked by a rect in SnapSVG and I want to translate the elements, bringing new ones into view (and hiding ones that are currently in view). The code is really simple - here's a codepen: http://codepen.io/austinclemens/pen/ZbpVmX
As you can see from the pen, box1, which starts outside the mask element (clip) should cross through it when animated, but it never appears. Moreover, box2, which should move out of the clipping area, remains visible.
This example seems to do a similar thing and has no problems: http://svg.dabbles.info/snaptut-masks2
Here's the code from codepen:
var t = Snap('#target')
var clip=t.rect(200,200,200,200).attr({fill:'#fff'})
var box1=t.rect(300,100,50,50).attr({fill:'#000'})
var box2=t.rect(300,300,50,50).attr({fill:'#000'})
var boxgroup=t.group(box1,box2)
boxgroup.attr({mask:clip})
boxgroup.animate({transform:'t100,300'},2000)
I notice that the svg.dabbles examples translates the clip region by 0,0 at one point, but adding something like that doesn't seem to get me anywhere.
Ok, I figured this out thanks in part to this really great article about SVG transforms: http://sarasoueidan.com/blog/svg-transformations/
The upshot is that when I translate the box group, it takes the mask with it. This is a little confusing to me still - I guess the mask attribute is causing this somehow? Anyways, the solution is to apply an opposite translation to the mask to keep it in place. Check the pen to see it in action but basically I just had to add:
clip.animate({transform:'t-100,-300'},2000)
The tricky part of this is that you now need to synchronize the movement of the mask and the movement of the box group.
edit - I now demonstrate how synchronization can be achieved using snap's set.animate method on the codepen.

raphael animate shape

I don't want a whole chart library for this. All I want is to animate 1 rectangular box from 0 to a set value, like a linear guage, but without the need for labels or array of values. Whats the cleanest way to do this, using raphael. The guage container should have background color set.
square.animate({height: scale}, 1000, 'bounce');

Detecting shape coordinates in Canvas

I'm writing drag & drop functionality in my HTML5 Canvas application and am wondering how to detect if I'm clicking on a shape other than a rectangle or square, in which case I would do something like this inside of my 'mousedown' event handler:
if (evt._x > 13 && evt._x < 202 .... ) {}
I don't see how to easily do something like that with an arc like this:
ctx.arc(25, 25, 20, 0, (Math.PI/180)*360);
I hope that is clear, thank you in advance.
Just use isPointInPath, which checks if a given point is within the current drawing path. If you're drawing multiple shapes to the canvas, than a good technique is to associate each of your shapes with a "hidden" canvas, draw each path to its respective canvas, than test isPointInPath against each of these, offsetting the destination/mouse coordinates as needed. Theres no reason to resort to your own calculations for this.
First you check if the click is within a shape's bounding box (the smallest rectangle which fully encloses the shape). If it is, then you do the more complex math to determine if the click is within the shape itself. You'll have to implement this math yourself as I don't think there's anything built-in for it.
You'll get the formula you need here and also in Polygon article of Wikipedia.
This may sound stupid, but you can use <area> tags inside a <map> over an <img> to create interactive polygonal shapes. They have their own onclicks/mouseovers/etc. already implemented by all browsers.

Categories

Resources