How to create an Adjustment Layer in After Effects via scripting? - after-effects

I know it's possible to create Shape Layers and Solids via scripting, but how do I create an Adjustment Layer?

It's pretty simple. Every layer can be turned into an Adjustment Layer.
You can simply create a solid layer and then turn it into one like this:
var solid = comp.layers.addSolid([0,0,0], 'LayerName', 1920, 1080, 1, duration);
solid.adjustmentLayer = true

Related

How to add osgEarth Features at runtime?

I'm playing around with osgEarth and while it's crazy easy to add features in the .earth file, I'm struggling to do it at runtime via the API. I want to let the user draw polygons on the map/globe so I need to be able to dynamically define geometry and styles based on user input.
Right now I'm just going for a static implementation to figure out what I need to do, but for the life of me I can't get anything to show up. Here is my sample code. I've already loaded a .earth file that defines the MapNode which is what I'm using here.
// Style
osgEarth::Symbology::Style shapeStyle;
shapeStyle.getOrCreate<osgEarth::Symbology::PolygonSymbol>()->fill()->color() = osgEarth::Symbology::Color::Green;
// Geometry
osgEarth::Symbology::Polygon* polygon = new osgEarth::Symbology::Polygon();
polygon->push_back(0, 0);
polygon->push_back(0, 10);
polygon->push_back(10, 10);
// Feature
osgEarth::Features::Feature* feature = new osgEarth::Features::Feature(polygon, mapNode->getMapSRS(), shapeStyle);
// Node
osgEarth::Annotation::FeatureNode* featureNode = new osgEarth::Annotation::FeatureNode(mapNode, feature);
featureNode->setStyle(shapeStyle);
featureNode->init();
mapNode->addChild(featureNode);
This should draw a green triangle near the middle of the map, but I don't see anything. Am I wrong in assuming that my polygon points are geo coordinates (lon, lat)? Is it wrong to just create my Style and Geometry on the fly like this? What am I doing wrong?
Update: This seems to work fine on a 3D (geocentric) map, but not on a 2D (projected) map which is what I'm after.
After poking around a bit I stumbled upon the osgearth_features example that comes with the SDK which includes examples of creating features programatically. I followed the pattern from the sample and came up with something that works.
// Style
osgEarth::Symbology::Style shapeStyle;
osgEarth::Symbology::PolygonSymbol* fillStyle = shapeStyle.getOrCreate<osgEarth::Symbology::PolygonSymbol>();
fillStyle->fill()->color() = osgEarth::Symbology::Color::Green;
osgEarth::Symbology::LineSymbol* lineStyle = shapeStyle.getOrCreate<osgEarth::Symbology::LineSymbol>();
lineStyle->stroke()->color() = osgEarth::Symbology::Color::Black;
lineStyle->stroke()->width() = 2.0f;
// Geometry
osgEarth::Symbology::Polygon* polygon = new osgEarth::Symbology::Polygon();
polygon->push_back(0, 0, 10000);
polygon->push_back(0, 10, 10000);
polygon->push_back(10, 10, 10000);
// Feature Options (references the geometry)
osgEarth::Drivers::OGRFeatureOptions featureOptions;
featureOptions.geometry() = polygon;
// Model Options (references the feature options and style)
osgEarth::Drivers::FeatureGeomModelOptions geomOptions;
geomOptions.featureOptions() = featureOptions;
geomOptions.styles() = new osgEarth::StyleSheet();
geomOptions.styles()->addStyle( shapeStyle );
geomOptions.enableLighting() = false;
// Model Layer Options (created using the model options)
osgEarth::ModelLayerOptions layerOptions("test polygon", geomOptions);
mapNode->getMap()->addModelLayer(new osgEarth::ModelLayer(layerOptions));
Defining the style and geometry is more or less the same as what I was doing before (I added a line symbol this time), but in this case I'm adding a ModelLayer to the Map. That ModelLayer uses some model options that reference my style and geometry through the feature options.
I don't know if this is the best way to do it or how scalable it is (can I do this over and over thousands of times?), bit it's at least got me going,

Open TK difference onRenderFrame and onUpdateFrame?

I am currently programming a Jump n' Run game in C# using OpenTK Framework and OpenGL.
Open TK provides preset functions like GameWindow.Run(); or GameWindow.onUpdateFrame(); onRenderFrame();
As far as i thought through it, all actions that draw OpenGL elements or primitives should belong into onRenderFrame, whereas game events like player movement should be performed in onUpdateFrame, so these actions can be calculated in advance before rendering a new frame.
Am I right? Would it make a difference to perform all actions in the onRenderFrame method? OpenTK suggests not to override these methods and subscribing to their Events (onRenderFrameEvent) instead.
http://www.opentk.com/files/doc/class_open_t_k_1_1_game_window.html#abc3e3a8c21a36d226c9d899f094152a4]
What is subscribing and how would i subscribe to an event instead of overriding a method?
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
this.gameObjects.moveObjects();
this.player.Move();
if (this.player.jumpstate == true) this.player.Jump();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.LoadIdentity();
GL.Translate(0.0f, 0.0f, -3.5f);
this.gameObjects.drawObjects();
this.player.Draw();
SwapBuffers();
}
It's pretty much as the comments said: update your world in the UpdateFrame event and render it in RenderFrame.
This makes sense when you realize that your game will run on wildly different hardware. Some computers might only be able to render your game at 15fps. Others will achieve a solid 60fps. And players with 120Hz monitors will want your game to run at 120fps in order to enjoy the full potential of their systems.
In all those cases, you want your game logic to run at the same speed and give identical results.
The simplest way to achieve this is by setting a fixed UpdateFrame rate in GameWindow.Run():
using (var game = new GameWindow())
{
game.VSync = VSyncMode.Adaptive;
game.Run(60.0, 0.0);
}
This code snippet instructs OpenTK to raise 60 UpdateFrame events per second and as many RenderFrame events as the system can handle, up to the refresh rate of the monitor. When running on a slower system, OpenTK will drop RenderFrame events in order to ensure a solid 60 UpdateFrame events per second. This is typically called a "fixed timestep".
See Fix Your Timestep! for why this is desirable.
See Quake 3 for why you should not perform your world updates inside the RenderFrame event (short version: in Quake 3, numerical inaccuracies on high fps allow players to jump higher and gain a competitive advantage.)
Edit: for the second part of your question, see understanding C# events. For example:
using (var game = new GameWindow())
{
game.RenderFrame += (sender, e) =>
{
GL.Clear(ClearBufferMask.ColorBufferBit);
game.SwapBuffers();
};
}
There is no inherent advantage to subscribing GameWindow.RenderFrame compared to inheriting from GameWindow and overloading its OnRenderFrame method. Pick whichever approach fits your code structure better.

Cocos2d CCLabelBMFont how to add a background to string

I am wondering how can I add a border & background to labels generated via CCLabelBMFont class in cocos2d.
I don't want to use sprites because my labels are generated on the fly and will keep changing and the size of labels are also different.
Also, I want user to touch and move these labels across the screen. When user picks a label it wiggles a bit like in free air. In that case, I wish to keep low complexity and preserve memory and cpu calculations.
Anyone knows best ways to achieve this?
IOS app LetterPress has similar effects.
Create your own class, that will incapsulate creation of complex node.
It will have several layers, for example, the first layer can be simple CCLayerColor of given rect with zOrder -2, the next layer will be your CCLabelBMFont with zOrder -1 and then you can overload draw method to draw border over your control. All that you draw in this method will be drawn with zOrder 0.
Then you can encapsulate any effects in this class. For example, you can rotate it a bit with method pick, etc. Whatever you want.

How to make complex charts using Raphael

I supposed to make this type of charts, is it posssible to make through Raphael or any good Plug-in for Raphael. ( i prefer raphael, because already i using this), I am attaching the image that what i need to produce?
thanks for advance..
I'd genuinely advise just drawing the thing manually using the Raphael library. When we had a requirement for an uncommon graph type, I attempted to get existing graphing libraries to draw it, but it was awful. I mocked up a prototype in an evening to demonstrate how much cleaner it is to draw it manually with raphael, and we ended up using it. Best thing you can try to do is prototype what you are looking for: create a dummy set of Json for the graph and try to plot from this data. You should find that it's relatively straight forward to divide the content area up:
numberOfMonths = 6;
barsPerMonth = 2;
marginLeft = 40;
marginRight = 40;
graphArea = canvasWidth - marginLeft - marginRight;
monthWidth = graphArea / numberOfMonths;
barWidth = monthWidth / barsPerMonth;
Just define all of the margins and widths that you want. Define the range of your axes and define a tick scale/count. That should get you started.

Cocos2D find out the layer which is being used among several layer

Hi guys
I am new to the cocos2D.In my game i have one scene and several layer to display Menu,pause,level finish,game over. now i want to find out the layer which is being used on top of the scene. i already tried and got the solution to solve it by using boolean variable for every layer. but this is not a good way to use i thought.
please provide some suggestions
Thanks
Riash
You can simply keep a pointer to the active layer. And it is better to have different scenes for every game state because in this case your management will become much simpler. That's because typically your game scene will have more then one layer. For example: background, level objects, controls and so on.