SCSceneGraph

Inherits From:
NSObject

Conforms To:
NSCoding

Declared In:
Sc21/SCSceneGraph.h

Class Description

An SCSceneGraph encapsulates a Coin scenegraph and provides an abstraction for reading Inventor and VRML files.

Superscenegraph creation

When a scene is read that contains no light or no camera, nothing would be visible, so by default SCSceneGraph inserts a light or camera if none is found. This is called superscenegraph creation can be controlled in several ways:

The delegate method shouldCreateDefaultSuperSceneGraph determines whether or not the internal default superscenegraph creation code should be run. If no such delegate method is found, the value of the checkbox in SCSceneGraph's IB inspector is used. The default setting is to create the default superscenegraph.

In addition, the createSuperSceneGraph delegate method lets you specify your own superscenegraph creation code.

For more information about the delegate methods refer to the NSObject(SCSceneGraphDelegate) documentation.


Global Variables

Synopsis:

NSString * SCCouldNotOpenFileNotification;

Description:

Posted if opening a requested file for reading failed because the file does not exist or cannot be read.

Synopsis:

NSString * SCReadErrorNotification;

Description:

Posted if an error occured when reading a file or memory buffer.

The actual error message reported by SoInput is stored in the notification's userInfo dictionary (as value for the key description).

Note that this does not necessarily mean that reading the file/buffer failed. (For instance missing texture images are reported without aborting loading the file.) If you want to know whether reading failed, check the value returned by readFromFile:


Synopsis:

NSString * SCNoCameraFoundInSceneNotification;

Description:

Posted if setSceneGraph: is called with a scenegraph that does not contain a camera. (The check is done after superscenegraph creation.)

Register for this notification if you want to issue a warning to your users that they will not be able to see anything.


Synopsis:

NSString * SCNoLightFoundInSceneNotification;

Description:

Posted if setSceneGraph: is called with a scenegraph that does not contain a light. (The check is done after superscenegraph creation.)

Register for this notification if you want to issue a warning to your users that they will not be able to see much in the scene (since only ambient light will be used.)


Synopsis:

NSString * SCSceneGraphChangedNotification;

Description:

Posted when the scenegraph is changed through setRoot:


Method Types

Initialization
- initWithContentsOfFile:
- initWithContentsOfURL:
Reading from files and URLS and loading data
- readFromFile:
- readFromURL:
- loadDataRepresentation:
Automatic headlight configuration
- headlight
Camera handling.
- camera
- viewAll
Accessing the actual Coin scenegraph
- root
- setRoot:
Delegate handling
- setDelegate:
- delegate

Instance Methods

camera

- (SCCamera *)camera

Returns the camera used for viewing the scene. Note that SCCamera is a only a proxy class, so you'll have to use SCCamera's soCamera and setSoCamera: methods to access the actual Coin camera.


delegate

- (id)delegate

Returns the receiver's delegate.


headlight

- (SoDirectionalLight *)headlight

If an additional light was added as part of the superscenegraph, this method returns this headlight. Otherwise, NULL is returned.


initWithContentsOfFile:

- (id)initWithContentsOfFile:(NSString *)filename

Initializes the receiver, a newly allocated SCSceneGraph instance, with the contents of the file filename. The filename argument may be a full or relative pathname and should include an extension that identifies the data type in the file.

If the file cannot be opened, an SCCouldNotOpenFileNotification is posted. If an error occurs while reading the file, an SCReadErrorNotification is posted. (Note that such an error does not necessarily mean that loading the file fails.)

If no valid scenegraph can be read from the file (either because the file cannot be opened or a fatal error occured when reading the file), the receiver is freed, and nil is returned.


initWithContentsOfURL:

- (id)initWithContentsOfURL:(NSURL *)URL

Initializes the receiver, a newly allocated SCSceneGraph instance, with the contents of the URL url.

If an error occurs while reading the URL, an SCReadErrorNotification is posted. (Note that such an error does not necessarily mean that loading the file fails.)

If the URL does not contain a valid scenegraph, the receiver is freed, and nil is returned.


loadDataRepresentation:

- (BOOL)loadDataRepresentation:(NSData *)data

Read scene from data using SoInput::setBuffer().

Posts an SCReadErrorNotification if an error occurs when reading data. (Note that such an error does not necessarily mean that loading the buffer will fail. Check the value returned by this method to find out whether reading was successful or not.)

Returns YES if reading the scenegraph was successful, and NO otherwise.


readFromFile:

- (BOOL)readFromFile:(NSString *)filename

Read a new Coin scenegraph from the file name.

Posts an SCCouldNotOpenFileNotification if the file cannot be read.

Posts an SCReadErrorNotification if an error occurs when reading the file. (Note that such an error does not necessarily mean that loading the file will fail. Check the value returned by this method to find out whether reading was successful or not.)

Returns YES if reading the scenegraph was successful, and NO otherwise.


readFromURL:

- (BOOL)readFromURL:(NSURL *)URL

Read a new Coin scenegraph from URL.

Posts an SCReadErrorNotification if an error occurs when reading the file. (Note that such an error does not necessarily mean that loading the file will fail. Check the value returned by this method to find out whether reading was successful or not.)

Returns YES if reading the scenegraph was successful, and NO otherwise.


root

- (SoGroup *)root

Returns the root node in the receiver's Open Inventor scenegraph, or NULL if there is no valid scenegraph.

Note that this is the root as previously set by setRoot:, or the top node of the scenegraph read from a file, URL, or memory buffer. It thus does not contain the superscenegraph. If for some reason you want to access the complete scenegraph (including the superscenegraph) that is actually used for rendering, you can get it by calling SoSceneManager::getSceneGraph().


setDelegate:

- (void)setDelegate:(id)newdelegate

Makes newdelegate the receiver's delegate.


setRoot:

- (BOOL)setRoot:(SoGroup *)root

Sets the receiver's Coin scenegraph to root.

By default, the internal implementation will check whether root contains at least one light source and one camera. If no light is found, a headlight (i.e. a light following the active camera) will be added. If a camera is found, it will be used as active camera; otherwise, a perspective camera will be added before the scenegraph. (See the class introduction at the top of this page for more information on how to control this behaviour.)

Returns YES if the scenegraph was set successfully, and NO if an unexpected problem occured. (Currently the only reason when NO would be returned is when the delegate method createSuperSceneGraph: returns NULL, which is interpreted as an indication that setting the new scenegraph should be aborted.)

Note that it is perfectly fine to pass NULL as root, in which case the old scenegraph will be released and the scenegraph set to NULL. Since this is considered a valid operation, setRoot: will return YES in this case.

On return values of YES, both the passed and the actual scene graph will be ref()'ed. On NO, the passed scene graph will not be ref()'ed.


viewAll

- (void)viewAll

Positions the current camera so that the whole scene is visible, by sending viewAll:self to the receiver's SCCamera.


Sc21 version 1.0 © 2003-2004 Systems in Motion AS.