How to make an object invisible at a particular keyframe without moving it in Blender (2.59)? - blender

I'm quite new to blender, and I'm doing some experiments with it.
I've been searching for a way to make an object disappear from sight at a particular key-frame, without moving it out of the camera view. E.g. at frame 1, cube is there, at (0, 0, 0) and at frame 2, it's not visible anymore, but still there at position (0,0,0), at frame 3 it gets visible again.
After searching the web, I came upon this page which suggests to move the object to another layer, but since it applies to blender 2.49, it seems the software has changed since then: I'm unable to find the 'Layer' option when inserting a key-frame.
I've found some other sites but either they suggest to use a technique similar to the one linked above, or they suggest to change the alpha of the texture, which I'm not interested in.
So, what's the preferred method to make an object invisible in blender 2.59?
Additional information (not relevant for the answer I'm expecting, IMO):
I'm using blender to make models for Unity.
I'm using 2.59 because that's the one that works with the unity version that I have.

There are lots of ways to achieve this effect.
The easiest way is to keyframe the visibility of the object.
To do this, you simply go to the outliner, and click the little eyeball next to your object name, then hover over the closed eyeball and hit "i" to keyframe. The eye will then turn yellow to indicate it's keyframed. Do the same with the camera icon (so that your render behaves the same way). Then go to the point where you want the object to appear, and click the eyball and camera again to make them reappear, then hit "i" again over each to keyframe them... Isn't blender a wonderful program? I love being able to keyframe just about everything! :D
There are also these less easy, but variously useful methods, which you may also use in case you want some sort of transition in your vanishing/appearing:
My perferred way is to just move the opbejct off the screen, keyframe position, then set the animation (in the Graph Editor) curve type to "constant" (Key -> Interpolation Mode -> Constant), and move the object into place and set the keyframe where you want it to appear. It will thus instantaneously appear.
Set the material properties of the object to Transparent, and choose "Z-Transparency" and set alpha to 0. Then simply keyframe the alpha (hover mouse over Alpha value and hit "i"), then go to where you want it to appear, change the alpha value to 1, and keyframe again. This will make it fade in over time, or you can change the curve to constant in the Graph editor, as described in method 1.
If you want to mask the object while it is still in place, you could make a cube around it, set the cube material transparency to "mask", and then move the cube off camera to unmask the object, rather than moving the object. This is handy for when you want to partially unmask something in the course of the animation. For example, if you are creating a text overlay for a video, where you want text to appear as if it's coming out of your hand, you can animate the masked object to follow the contour of your hand as it pulls away to reveal the text.

In Blender 2.65, you can animate the objects visibility toggle in your Outliner panel.
Next to your scene objects there will be three icons: an eye, a cursor, and a camera.
Follow these steps to animate viewport visibility:
Find the object you wish to animate in the Outliner Panel
Mouse over the eye icon and hit "i" on your keyboard to set a keyframe.
Go to the next frame and turn the eye off, then hit "i" moused over it again.
Do the same thing with the camera icon to animate render visibility. I will usually keyframe both the viewport and render visibility icons in tandem so as not to forget to have these toggled when its time to render.

In version 2.9 the eye icon cannot be used to set a keyframe. I've found the best way for me is to use the Object Properties tab and under Transform set the three scale values (X,Y,Z) to zero for invisibility. You can then click the diamond to the right to set the keyframe. To make the object re-appear return the scale values to their original and click on the diamond keyframe icon again.
Obviously you can make it a lot easier for yourself by applying scale to the objects first then just switch them between 0 and 1.

AFAIK there is no easy way to directly set an object invisible in your case. Although the visibility can be animated in Blender (in outline view mive your cursor on the eye and press i) Unity3D doesn't recognise it.
Possible workarounds:
Move it to (1000, 0, 0)
Scale it by a very small value
A more elaborated approach could be to use a driver like when turning FK/IK animation on and off dynamically via a variable.

I found out (today!) that, in Blender 2.8 (& presumably beyond), you can control visibility of objects in animations either in viewports and/or renders. Select the object and, in the Object Properties, open the Visibility section. You will see a dot beside the Viewports and Renders options. Click on the dot in either Viewports or Renders (or both). The relevant boxes should turn green. Either make the object visible or invisible by checking or clearing its box and then click 'i' to insert a keyframe. Repeat the process in other keyframes.

Another way to do this is to make a cube around it and add a boolean modifier to the object you want to disappear, set the operation to difference and select the cube as the modifier's object target. Then turn off the cube's visibility and animate the visibility of the modifier.

Related

How to animate colors in an object in blender

I was making an magic ball in blendeR.I have made the uv sphere ball already and also i have added 5-6 different colors with the help of light sources.Now i want the colors to animated or move in an jiggly way like whirl.Please see the link something like this :
http://luisbc.deviantart.com/art/Magic-Ball-II-364636015
I just want to make the colors inside my ball to move/circulate in a way.I don't know how to use Automatic Key Frame as well as how to make the lights move in a direction in my ball.
Please help me out.
Thanks.
The basics of animation are -
Move to the frame that you want to specify a value.
Alter the value you want to animate.
Insert a keyframe for the value.
Repeat for other frames in the animation.
The Automatic keyframe option can automate step 3 - but it will only add keyframes to values that have already been keyed. That means you have to manually add the first keyframe for a value, then as you change the value new keys will be created. Remember that it creates a keyframe on the current frame for the altered value so change frames before changing anything.
In blender almost any value can be animated, that could be the location and/or rotation of an object, the texture mapping values for a material or the colour of the material.
You can press I to add a keyframe, in the 3Dview this will show a list of common choices for location/rotation/scale and combinations of each. For values found elsewhere it will key the value located under the cursor. You can also right click on a value and select Insert Keyframe.
For help using blender you will find blender.stackexchange a better place to ask for help.

WinRT - ImageButton for transparent PNGs

I'm using XAML Toolkit ImageButton control to be able to create normal and pressed states for a button. Code is:
<toolkit:ImageButton NormalStateImageSource="ms-appx:///Assets/1_off.png"
PressedStateImageSource="ms-appx:///Assets/1_on.png"
Width="500"
Height="200">
</toolkit:ImageButton>
Issue I'm facing is, say I have a shape which isn't rectangle or square. For example I have PNGs for star and arrow object. Is there a way to set their boundary corresponding to shape? If not, please advice the best approach to handle such scenarios.
There are two options I tried
When clicking using mouse or touch - you'd check the last position of the pointer before click and see if the image in your button has a non-transparent pixel at that position.
Pros:
It's simpler than option 2.
You get most precise information
Cons:
You can't tell if a button got clicked with mouse, touch, pen, keyboard or by narrator using automation, so you could end up filtering out keyboard clicks just because the mouse cursor is a bit off. You could possibly use some heuristics like how long ago was the pointer move or pointer down event before the click event, but it's a bit hacky and might be unreliable.
Generate a vector path for your image and put it in the button template as a Path element with Fill="Transparent", then mark any other non-transparent or hit testable template elements (buttons, borders with Background="Transparent", etc.) as IsHitTestVisible="false".
Pros:
Doesn't break any input methods
Can be quite precise
For some shapes like a circle - the Path.Data could be quite simple or you could even use something like an Ellipse element instead
Cons:
You need to generate the path somehow
A complex path might adversely affect performance
A better solution overall in most cases is to leave the hit-testable area rectangular. The reason is - an arbitrary shape is a finicky and unreliable hit test target so it makes clicking your button more difficult. Using the default rectangular border or at most - an ellipse shape is a lot simpler and more usable.

What secret things are happening to my NSButtonCell?

I'm writing an OS X app (target 10.10, Xcode 6.1) and I'm really confused by my custom NSButtonCell subclass. It seems like there are things going on here that shouldn't. I'm new to OS X programming, so I'm asking if anyone has insight into the inner workings of NSButtonCell.
First, what seems to be working?
I can set the button's image and title. The image appears normally.
The storyboard sets up the button to be Style: Textured and Type: Momentary Change. It's not Bordered, not Transparent, and doesn't allow Mixed State.
List of complaints:
I override -drawTitle:withFrame:inView: to draw the title in a custom color depending on the cell's highlighted. This color should be #cccccc when the cell is not highlighted, but it's actually #d6d6d6.
The button has both image and alternate image. The image that's drawn is never the alternate image, so I override -drawImage:withFrame:inView: to pick the correct image for cell's highlighted. This appears to work, but what the heck, NSButtonCell? How is on/off state different from highlighted? I've tried many of the Type options and none seem to change the fact that pressing the button will momentarily change highlighted, and toggle state.
Speaking of momentarily changing highlighted, it appears that its duration is about as short as possible, so I had to implement a sort of "debouncer" to prevent -drawWithFrame:inView: from being called more frequently than a specified threshold.
My button cell also has properties myBackgroundColor and myAlternateBackgroundColor. I'm not using backgroundColor because I need to be able to draw a custom background shape (filled rect, filled circle, etc). The alternate background color is used when highlighted. The problem here is that the alternate background color should be #93edbf but appears to be #a1eecb! In order to get it to look like #93edbf, I need to set the color to #84ecb2.
So far this has all been about one particular instance of this button cell. But in another instance, the alternate background isn't drawing at all! I've read through the storyboard code and the buttons are as identical as they can be. My view controller code likewise updates both button cells' properties at the same time. Why would one button behave differently from another?
I want the button to highlight on mouse down instead of "momentarily" after mouse up. I haven't yet implemented this in my custom cell. Man, NSButtonCell is really lacking some things. How does something like that happen? Don't the OS X and iOS teams ever talk to each other?
What could it be?
I've already verified that the cell's controlTint is set to NSClearControlTint. I've checked for background filters, compositing filters and content filters on the off chance they had anything to do with this.
I know Apple really wants us to use their native look and feel for UI elements, but I never thought they'd go so far as to force the use of some highlight tint.

Change size of window in Cocoa?

I have a window whose size I need to change when the user clicks on it. I am using [self setFrame:windowFrame display:YES animate:YES] to accomplish this.
Even though the window successfully changes size (I increase its height), it moves the contents of the window up with it. How do I prevent this from happening? I want the contents to remain in place.
I am on OSX Mountain Lion developing an app for OSX using Objective-C and Cocoa.
EDIT: Constraints and/or Springs and Struts will not work as I need to move the contents around after the window is resized.
Constraints and/or Springs and Struts will not work as I need to move the contents around after the window is resized.
In that case, you should use NSViewAnimation.
A single view animation can actually perform multiple animations to multiple views, and you can even do one to a window, despite the class's name and the fact that windows aren't views in Cocoa.
You create a view animation with initWithViewAnimations:, which takes an array of dictionaries. Each dictionary identifies the target (NSViewAnimationTargetKey) and what to do to it: Either change the target's frame (NSViewAnimationStartFrameKey and NSViewAnimationEndFrameKey) or fade the target in or out (NSViewAnimationEffectKey). For your case, you'll be changing the targets' frames.
When the user does the thing that causes the resize of the window, you'll need to compute the desired overall size of the window (taking care to adjust its frame's position so it doesn't grow off the screen), as well as the new frames—both positions and sizes—of your views. Everything that will move and/or change size, create a dictionary for it and throw it into the array. Then create the view animation.
An NSViewAnimation is a kind of NSAnimation, which provides all the methods for starting and stopping the animation, monitoring its progress, hooking into it, and chaining multiple NSAnimations together. If nothing else, you'll need to start the animation.
If you are using the Interface Builder to build these views, then I believe one approach is to set the "struts and springs." These are available under the "size inspector" and are the red arrows and bars above the "autosizing" label. Play around with these to get the effect that you want, but the general idea is that the arrows control how the size of the view adjusts to changes in the size of the parent view, and the bars control the relationship of the edges of the view to the edges of the parent view as the size changes.
In constraint-based layout, set the views around the edge of your window to be a fixed distance from their superview's edge.
Xcode will infer a lot of resizability from that; if anything still isn't resizing properly, adjust its constraints so that its width and/or height is no longer constant.
The easiest way is to move your views until blue lines show up in the editor. Each blue line corresponds to a rule in the HIG about how things should be lain out, and if you drop the view there, Xcode will create constraints matching those guidelines. For example, if you set a view 20 points from the right edge of its superview, you'll get a blue line for that, and if you drop the view there, you'll create a constraint that the view must remain that distance from that edge.
The superview isn't the only view with which you can create HIG-based constraints. You can also create guideline constraints between sibling views. For example, if you put a button next to another button at the appropriate distance, you'll get a blue line across that distance, and if you drop it, you'll create a constraint that those two buttons must remain that distance from each other.
If you want to do something really custom, the three buttons in the lower-right corner of the nib editor will let you create any constraint you want. What you have selected determines what constraints you can create; the nib editor's outline view will help you make sure you have the selection you want.
You are going to have to iterate through all of your subviews and change their frame positions based on the delta of your window frame.
so if you expand your window frame by 20 in all directions, all your subviews are going to have to increase their frame positions by (20,20) to offset the windows movement.

Draw Lines on gtk.TextView

I'm trying to show the "selection" of a certain sub-string in a
gtk.TextView by drawing a border around the word. The only way to mark
text in a TextView that I've found so far is by placing TextTags with
modified properties. This does not seem to offer a way to draw a border,
though, DOES GTK SUPPORT THIS OR IS THIS A PROBLEM WITH ONLT PYGTK
I figured out how to draw on a text view !!!
To begin with lets assume the reference to your gtk.TextView is in a variable called viewer, Inside one of ur classes
Also the draw function has to be called with an event called expose-event else the drawings will be refreshed and will not stay on the screen
The next part is the gtk.TextView consists of 7 types of gtk.gdk.windows on which u can draw
gtk.TEXT_WINDOW_WIDGET
gtk.TEXT_WINDOW_TEXT
gtk.TEXT_WINDOW_LEFT - not displayed by default
gtk.TEXT_WINDOW_RIGHT - not displayed by default
gtk.TEXT_WINDOW_TOP - not displayed by default
gtk.TEXT_WINDOW_BOTTOM
gtk.TEXT_WINDOW_PRIVATE
For the drawing to appear on gtk.TextView We have to draw on gtk.TEXT_WINDOW_TEXT
An Example Code is as shown Below
if(viewer!=None):
viewer.connect("expose-event", expose_view)
self.drawable=viewer.get_window(gtk.TEXT_WINDOW_TEXT)
def expose_view(self,window,event):
if(self.drawable!=None):
self.drawable.draw_line(self.drawable.new_gc(),1,1,30,30)
# (1,1) and (30,30) are the coordinates and u can give the values accordingly
In a gtk.TextBuffer tags are used to set one or more pre-defined text attributes. Without subclassing, this is limited to the properties of a gtk.TextTag, and doesn't include anything akin to a border or outline property. There is no difference between PyGTK and plain GTK+ in this regard.
While somewhat hacky, the easiest way to do what you want to do is to connect to the expose-event of your gtk.TextView, get the coordinates of your string and draw on event.window, which is the gdk.Window of the event provided in the expose callback.
(Note that you don't have to get and store the gtk.TEXT_WINDOW_TEXT window, you just need to check what window the expose event is for in the callback, probably ignoring the expose if it's not for the text window.)
Instead, you could presumably subclass one or more of TextBuffer/TextView/TextTag to add a border tag, but whether it's reasonable to do so is another question.