Is it possible to make a single entity perform multiple animations? - animation

I want to know if I can make one object, like a box or sphere, do 2 animations, as in rotation and color.
I know you can set these in the property section of the animation attribute, but if I try to put multiple animation attributes on one object, or if I try to put 2 properties in 1 animation attribute, it either doesn't animate, or only does one of the animations.
Here is the code I'm using, I would appreciate if any of you could edit it to make it work, if this is possible:
<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/1.0.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-sky color="lightblue"></a-sky>
<a-box position="0 0 -5" width="2" depth="2" height="2" color= rgb(0,0,0)
animation="
property: rotation;
from: 0 0 0;
to: -360 -360 -360;
loop: true;
dur: 3000;
dir: alternate;
property: color;
from: rgb(0,0,0);
to: rgb(255,255,255);
loop: true;
dur: 3000;
dir: alternate;"></a-box>
</a-scene>
</body>
</html>

You need to split the animation instructions into separate animation components, which should look like this:
animation__<id>="stuff"
// like this:
animation__first="single animation related stuff"
animation__second="another single animation related stuff"
your code should look a bit more like this:
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<a-scene>
<a-sky color="lightblue"></a-sky>
<a-box position="0 0 -5" width="2" depth="2" height="2" color=rgb(0,0,0)
animation__rotation="
property: rotation;
from: 0 0 0;
to: -360 -360 -360;
loop: true;
dur: 3000;
dir: alternate;"
animation__color="
property: color;
from: rgb(0,0,0);
to: rgb(255,255,255);
loop: true;
dur: 3000;
dir: alternate;"></a-box>
</a-scene>

Related

issue with paperjs rotate

Using paperjs if I rotate p.view.rotate(update.deg); it is working fine with out issue.
If I refresh the page and call the above function p.view.rotate(update.deg); onload then the view is different. it is displaying a slight zoom.
default image rotation
After reloading the page I am rotating p.view with the previous value. then it is displaying as
Here is my js file
https://github.com/muralibobby35/annotateJs/blob/master/opentok-whiteboardnew.js
I was not able to run your code but I would suggest, for an easier project state preservation, that you use transformations (scale, rotation, ...) through layer rather than through view.
That would allow you to easily export/import your project whithout having to manually restore state by calling view.rotate() like methods on window reload.
Here is a fiddle demonstrating the solution.
It simulates window reload by exporting/importing a project from one canvas to another empty one.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Debug Paper.js</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.11.5/paper-full.min.js"></script>
<style>
html,
body {
margin : 0;
overflow : hidden;
height : 100%;
}
main {
display : flex;
height : 100vh;
}
canvas {
flex : 1;
border : 1px solid;
}
</style>
</head>
<body>
<main>
<canvas id="canvas1" resize></canvas>
<canvas id="canvas2" resize></canvas>
</main>
<script type="text/paperscript" canvas="canvas1">
// draw a square
var rectangle = new Path.Rectangle({
from: view.center - 50,
to: view.center + 50,
fillColor: 'orange'
});
// rotate layer rather than view so transformations are persisted when exporting
project.activeLayer.rotate(30);
// export datas and store them in global variable just for the demo, to simulate a page reload
window.exportedDatas = project.exportJSON();
</script>
<script type="text/paperscript" canvas="canvas2">
// import the exported datas
project.importJSON(window.exportedDatas);
// see that rotation is preserved
</script>
</body>
</html>

How do I rotate a 3d model in A-Frame by moving or dragging the mouse?

Based on this How do I rotate a box in A-Frame by moving or dragging the mouse?
how i can do it with a 3d model? i need rotate a 3d model/object in a view
i have tried this code, but doesn't works
<html>
<head>
<title>Rotation</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://aframe.io/releases/0.4.0/aframe.min.js"></script>
</head>
<body>
<script type="text/javascript">
AFRAME.registerComponent('drag-rotate-component',{
schema : { speed : {default:1}},
init : function(){
this.ifMouseDown = false;
this.x_cord = 0;
this.y_cord = 0;
document.addEventListener('mousedown',this.OnDocumentMouseDown.bind(this));
document.addEventListener('mouseup',this.OnDocumentMouseUp.bind(this));
document.addEventListener('mousemove',this.OnDocumentMouseMove.bind(this));
},
OnDocumentMouseDown : function(event){
this.ifMouseDown = true;
this.x_cord = event.clientX;
this.y_cord = event.clientY;
},
OnDocumentMouseUp : function(){
this.ifMouseDown = false;
},
OnDocumentMouseMove : function(event)
{
if(this.ifMouseDown)
{
var temp_x = event.clientX-this.x_cord;
var temp_y = event.clientY-this.y_cord;
if(Math.abs(temp_y)<Math.abs(temp_x))
{
this.el.object3D.rotateY(temp_x*this.data.speed/1000);
}
else
{
this.el.object3D.rotateX(temp_y*this.data.speed/1000);
}
this.x_cord = event.clientX;
this.y_cord = event.clientY;
}
}
});
</script>
<a-scene>
<a-assets>
<a-asset-item id="man" src="./assets/models/man/man.dae"></a-asset-item>
</a-assets>
<a-collada-model src="#man" rotation="0 45 0"></a-model>
<a-sky color="#ECECEC"></a-sky>
<a-entity position="0 -0.5 1">
<a-camera look-controls="enabled:false"></a-camera>
</a-entity>
</a-scene>
</body>
</html>
Thanks in advance!
Also have tried this, but not luck
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title - Demo 3D Model</title>
<meta name="description" content="Inlabs demo - 3D Model">
<script src="../../../dist/aframe-master.js"></script>
</head>
<body>
<a-scene>
<a-assets>
<a-asset-item id="man" src="./assets/models/man/man.dae"></a-asset-item>
</a-assets>
<a-collada-model src="#man" rotation="0 45 0"></a-model>
<a-sky color="#ECECEC"></a-sky>
<a-entity position="0 -0.5 1">
<a-camera drag-rotate-component look-controls="enabled:false"></a-camera>
</a-entity>
</a-scene>
</body>
</html>
Attach the drag-rotate-component to the model not the camera.
<a-collada-model drag-rotate-component>
Also, you don't need to add -component to the component name.
EDIT: sorry, my bad, this is not correct as it doesn't answer the question.
I think you simply forgot to append the name of the component drag-rotate-component as an attribute to the camera entity. See this pen.
<a-camera drag-rotate-component look-controls="enabled:false"></a-camera>

How to draw a curve in A-frame?

I'm getting started with A-Frame and this is a very basic question. I checked a number of examples to draw a line and then a curve in A-Frame but they don't show up in the scene. I have a plane there that shows up correctly.
I can use document.querySelector('a-plane').object3D; to get the plane but document.querySelector('a-curve').object3D; returns undefined.
Here is a code sample:
<!DOCTYPE html>
<html>
<head>
<title>A-frame room</title>
<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"> </a-plane>
<a-sky color="#ffffff"></a-sky>
<a-curve type="CatmullRom" curve="closed:true" visible="true">
<a-curve-point id="checkpoint1" position="0 0 -4" visible="true"></a-curve-point>
<a-curve-point id="checkpoint2" position="0 10 -4" visible="true"></a-curve-point>
<a-curve-point id="checkpoint3" position="0 10 -8" visible="true"></a-curve-point>
<a-curve-point id="checkpoint4" position="0 0 -8" visible="true"></a-curve-point>
</a-curve>
</a-scene>
</body>
</html>
You need to import the JS component that provides <a-curve>. It's a community component.
https://www.npmjs.com/package/aframe-curve-component

Is there any callback function in Aframe <a-animation>

When I create an element of a-animation,I want to know the exact time when the animation finished.I know the "dur" or "begin" can calculate the approximate time,but is there any callback function when I use the a-animation element!
You can listen to the animationend event on the a-animation element. Like so:
sphereAnimation.addEventListener('animationend', function () {
sphere.setAttribute('color', '#88ff99');
});
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<a-scene>
<a-plane color="#EFED5E" rotation="45 0 0" scale="3 3 3" position="0 0 -3"></a-plane>
<a-sphere id="sphere" color="#EF2D5E" position="0 0 -3">
<a-animation
id="sphereAnimation"
attribute="position"
to="0 2 -3"
direction="alternate"
repeat="3"
easing="ease-in-out">
</a-animation>
</a-sphere>
</a-scene>
The 'a-animation' tag is depricated in favour of animation="". You need to attach the event handler for the animationcomplete event to the object which is being animated. Here's what worked for me.
<html>
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script>
function sphereEventListener(){
aSphere.addEventListener('animationcomplete', function(){
console.log("Do something interesting here...");
});
};
</script>
</head>
<body onload="sphereEventListener()">
<a-scene>
<a-sphere
animation="dur: 1000; property: position; to: 5 0 -10"
id="aSphere"
position="-5 0 -10"
>
</a-sphere>
<a-sky color="black"></a-sky>
</a-scene>
</body>

How to export d3.js animation to vector frames to create an AfterEffects sequence?

I'm creating some basic animations using d3.js, such as bar chart animations that show a transition between two sets of data. Ultimately, I want to bring this animation into Adobe AfterEffects to include as part of a larger video. I want to export the web animation as a series of vector frames (ai or svg, or png if necessary) to import into After Effects or Illustrator. How can I do this?
Thanks!
This actually may be quite simple with the way d3.js does transitions! Since d3.js directly changes the DOM elements for doing transitions, you can simply save the DOM elements at each 1/30th of a second. Here's a complete example:
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
svg { border:1px solid black; }
</style>
</head>
<body>
<svg id="svg" width="480" height="240" xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red" />
</svg><br/>
<button id="b1" type="button">Animate</button>
<script type="text/javascript">
var svg = d3.select("svg");
var b1 = d3.select("#b1");
var duration = 1000;
var nTimes = 30;
var x = new XMLSerializer();
var n = 0;
function outputToConsole() {
console.log(x.serializeToString(document.getElementById("svg")));
if(n++ >= 30)
return;
setTimeout(outputToConsole, 33); // 33 milliseconds is close to 1/30th of a second
}
b1.on("click", function() {
svg.select("circle").transition().duration(duration).attr("cx",150);
outputToConsole();
});
</script>
</body>
</html>
The last step would be to save each of those outputted svg elements into individual .svg files on disk (instead of just outputting them to the console like in the above example). I haven't tried it yet, but probably one could use something like FileSaver.js. Then optionally the .svg files could be converted into .png files using something like ImageMagick.

Resources