simple vector graphics + animation DSL - animation

I'm looking for a vector graphics format that supports simple animations. At first I thought SVG would be the best. But SVG animation doesn't have any support in libraries. Is there some other format that would be useable for this?
I would like to have a Rust library, but have no problems writing an FFI to a C or C++ library either.
Any tips are welcome.

SVG's have some cool animation capabilities, i.e. transform: matrix() attribute + CSS transitions. My personal webpage in my profile has an example SVG I animated using CSS.
Here is some material I have gathered, I'm not sure of any other libraries though. The Three.js link has tons of additional info. Hope this helps.
Greensock Library
-- Greensock Animation Platform (GSAP) is a suite of tools for scripted animation. GSAP animates anything JavaScript can touch; i.e. CSS , SVG, React, & canvas. Overall, GSAP can manipulate property values at high speeds, which is one of the core techniques involved in CSS based transitions.
Aframe.io
-- A-Frame is a web framework based on Three.js for building virtual reality (VR) experiences. In addition to animation it features many other components and customizations.
Boxy SVG
-- Manipulate SVGs in a browser editor, with tutorials and more.
Gif.js
Vectr and Pixlr
Three.js Libraries & Plugins
Three.js WebGL
Lastly, two really cool sites I have found using WebGL/Three.js/SVG animation:
Interactive Example 1
Interactive Example 2

To your question/request..
"..I would like to have a Rust library, but have no problems writing
an FFI to a C or C++ library either."
I would recommend, a couple of nice options using Rust, C or C++.
The approach I took/recommend was 2 steps: first using Resvg to interact with the SVG, and then used another lib to animate.
Option 1:
please check out popular Resvg is a great lib Link, and github 1300 stars
Option 2:
please check out UX-Animate, which also has Rust apps & samples
// Scaling example in rust
use ux::prelude::*;
use ux::{Surface, Window};
#[derive(Default, Application)]
struct Application {
window: Window,
}
impl Application {
fn new() -> Self {
let app: Self = Default::default();
app.window
.set_window_size(512, 512)
.set_title("UX Framework - Scaling")
.show()
.connect_destroy(move |_win| Application::quit());
app.window.set_background_color(Some(color::GRAY_9));
let surface = Surface::new();
surface.set_size(400.0, 400.0);
// we should also change surface content size to avoid distortion
surface.set_content_size(400.0, 400.0);
surface.set_position(56.0, 56.0);
app.window.set_child(&surface);
surface.connect_draw(move |_widget, ctx, width, height| {
ctx.clear_rect(0.0, 0.0, width as f64, height as f64);
ctx.set_fill_color(color::TEAL_9); // Fill color
ctx.begin_path();
ctx.rect(10.0, 10.0, 90.0, 90.0);
ctx.fill();
ctx.scale(0.6, 0.6);
ctx.set_fill_color(color::ORANGE_9); // Fill color
ctx.begin_path();
ctx.rect(30.0, 30.0, 90.0, 90.0);
ctx.fill();
ctx.scale(0.8, 0.8);
ctx.set_fill_color(color::INDIGO_9); // Fill color
ctx.begin_path();
ctx.rect(50.0, 50.0, 90.0, 90.0);
ctx.fill();
false
});
app
}
}
fn main() {
Application::run();
}

Related

How are rich UI icon animations done?

I have recently come across beautiful icon animations in Apple's Home app. This is example of opening/closing garage doors: https://giphy.com/gifs/0it1uTDtVR1Uw1FByx
I wonder how to make these animations. There are ways I can think of:
Manually creating shapes and animating them in code (this would be so hard to do)
Using some animation tool and exporting *.gif frames (but in this way we will lose vector graphics)
Using some animation tool and exporting *.svg frames (is this efficient?)
Using some animation tool that will generate code (for example JS/CSS) with all the shapes and animation (Does such tool/program exist?)
Does anyone have experience with creating this type of animations? It would be great if you could share this experience :)
Obviously no answer will be exhaustive. Pure "CSS3 art" is route that I've seen people use because it can define complex geometry and animations precisely. But here are some ways I've looked into using SVGs.
You can actually embed a script tag in an SVG that animates the elements. Something like this:
<svg>
<!-- svg objects -->
<script><![CDATA[!
//... Javascript to animate svg objects...
]]></script>
</svg>
You can also use a library like snapsvg.io where the construction of an animated svg is done purely with JavaScript. Here's the example they use for their quickstart page:
var s = Snap("#svg");
var bigCircle = s.circle(150, 150, 100);
bigCircle.attr({
fill: "#bada55",
stroke: "#000",
strokeWidth: 5
});
var smallCircle = s.circle(100, 150, 70);
var discs = s.group(smallCircle, s.circle(200, 150, 70));
discs.attr({
fill: "#fff"
});
bigCircle.attr({
mask: discs
});
smallCircle.animate({r: 50}, 1000);
Otherwise you can use a codeless animated-svg creator like this one.
Disclaimer: I haven't tested the codeless site past the demo plan and probably will never use it. My personal preference would probably be the first suggestion but a JavaScript library like snapsvg.io seems like a nice middle ground.
I would go with option 4. Using some animation tool that will generate code (for example JS/CSS) with all the shapes and animation
I think it can be done with a tool called lottie, which uses json file exported by AfterEffects plugin called bodymovin.
Lottie web docs

Inconsitent lighting and colors in threejs

I have been experimenting with threejs for the past few days and have been experiencing inconsistencies in the lighting of my models. So I decided to do a little experiment. Here are side-by-side pictures of scenes containing the same model and the same lighting(Ambient, color: #FFFFFF, intensity: 0.3) one created using javascript and the other using threejs editor:
Using threejs editor
Using JS
Why are the colors and lighting different? Am I missing something?
You probably have not configured a sRGB workflow in your app. So try it with the following line:
renderer.outputEncoding = THREE.sRGBEncoding;

Google Cardboard view using three.js?

Is it possible to add a Google Cardboard view camera, as shown in the image below, to Google VR View, using Three.js? If so, how can I do it?
More specifically, how can I add Three.js to the Google VR View code below?
function onLoad() {
// Load VR View.
vrView = new VRView.Player('#vrview', {
width: window.innerWidth,
height: window.innerHeight,
video: 'crusher-final.mp4',
is_stereo: true,
loop: false,
});
}
This is not possible using the VRView-library as it runs within an iframe and doesn't provide any interface for you to add content to the 3d-views. However, it is fully open-source and implemented using three.js, see here for the source-code: https://github.com/googlevr/vrview
So you could use that code and add your stuff to it or implement it yourself.
The easiest way to do it is to use the WebVR-polyfill that does most of the work automatically. This will allow you to use the WebVR-API even if it is not yet supported by the browser.
Three.js has support for the WebVR-API built in, so there is not much more to do than to enable it using renderer.vr.enabled = true and setting the VR display to use via navigator.getVRDisplays().then(displays => renderer.vr.setDevice(displays[0]));.
See the webvr-examples and the WebVR-specification for further reference.

WebGL rendering on Firefox - Light effects show darker than in Chrome

I have a scene where one light is present, and diamonds.
Light properties:
Point light, position: 0 0 30, intensity: 1, distance 60, color: White.
The diamonds material is Phong, color:Red, no emissive, specular: White, shininess 10.
On Chrome, the diamons shine as suppose to, but on Firefox the diamonds not shine at all, and looks very dark (like have something black on it).
I have tried to use both Firefox on desktop Windows and Android mobile phone.
I would like to ask what I am missing?
Below are the settings in my code:
// Renderer:
ren=new THREE.WebGLRenderer({ antialias:true,alpha:true });
ren.shadowMap.enabled=true;
elm.appendChild(ren.domElement); // the renderer is added to a DOM element "elm"
// Light
var o=new THREE.PointLight(0xffffff,1,60);
o.position.set(0,0,30);
o.name="sun"; // light will be later added to the scene, and use "update materials" flag to update the materials of the entire scene.
// The diamond's material: (I gave a new parameter "name", for later use. I guess it should not makes trouble to the engine....)
var mt=new THREE.MeshPhongMaterial({ name:"RedDiamond", transparent:true, opacity:0.85, fog:false, color:0xff0020, specular:0xffffff, shininess:10 });
Live example can see here: https://www.crazygao.com/VideoGames/Lamps, since the first level (loading may takes a bit time only for the first time, the opening scene though is yet not complete). The lighting difference issue can be seen even in the progress scene (with the flash one)
My question: What should I do to make the diamonds shine in Firefox, but not make the entire scene too bright in Chrome? (I tried adding Ambient light to the scene, then in Chrome it becomes too bright....)
Is the problem comes from my settings, or it is the nature of Firefox? What are the best steps I can take to solve this issue?
Thanks a lot
My guess is that you're missing that the webgl canvas is composited with the HTML behind it. By default the browser expects the values of the pixels in the canvas to represent premultiplied alpha values. That means there are many possible invalid colors
Example RGBA = 1,1,1,0
That's an invalid color because since alpha = 0 and multiplying by 0 = 0 then R, G, and B also have to be zero
When the values are invalid the results are undefined and so you'll get different results on different browsers
This answers covers some of the solutions.

How to create scaleable svg animations?

Consider creating an SVG animation: a rectangle move into the scene from left side of the svg image and move out from right side and this is a loop.
(And i don't what to use canvas libraries or any javascript code).
[1] Is it possible to create this simple animation with any application (just like flash but with svg export) (I know Adobe Illustrator let us export vectors but not sure about animating theme).
[2] Also as SVG is vector based i intend to make this svg animating fluid (setting the width of svg to 100% an content scale automatically) is it also possible?
(I know how to do such these things using canvas libraries like snap.svg kinetic ... with bunch of js code i'm looking for some GUI App which let a graphic designer having no idea what JS is do it like Adobe Flash for example).
Any solution?
I am not sure about GUI App but fluid animations are possible. Look at the following elements: animate, animateMotion, animateTransform, animateColor.
Here are some examples and documentation:
MDN: animate, animateMotion
W3C

Resources