private SEACamera AppendCamera(Scene scene, Node node, Camera camera, SEAObject3D parent) { int sIndex = GetIndexByTag(node); if (sIndex != -1) return (SEACamera)Writer.Objects[sIndex]; SEACamera cam = new SEACamera(GetValidString(objects, node.Name)); cam.parent = parent != null ? GetIndex(parent) : -1; cam.transform = To3x4Array(node.Transform * camera.ViewMatrix); cam.fov = camera.FieldOfview; objects.Add(cam); Writer.AddObject(cam); cam.tag = node; return cam; }
/// <summary> /// Constructs a new Scene. /// </summary> /// <param name="scene">Unmanaged AiScene struct.</param> internal Scene(AiScene scene) { _flags = scene.Flags; //Read materials if(scene.NumMaterials > 0 && scene.Materials != IntPtr.Zero) { AiMaterial[] materials = MemoryHelper.MarshalArray<AiMaterial>(scene.Materials, (int) scene.NumMaterials, true); _materials = new Material[materials.Length]; for(int i = 0; i < _materials.Length; i++) { _materials[i] = new Material(materials[i]); } } //Read scenegraph if(scene.RootNode != IntPtr.Zero) { _rootNode = new Node(MemoryHelper.MarshalStructure<AiNode>(scene.RootNode), null); } //Read meshes if(scene.NumMeshes > 0 && scene.Meshes != IntPtr.Zero) { AiMesh[] meshes = MemoryHelper.MarshalArray<AiMesh>(scene.Meshes, (int) scene.NumMeshes, true); _meshes = new Mesh[meshes.Length]; for(int i = 0; i < _meshes.Length; i++) { _meshes[i] = new Mesh(meshes[i]); } } //Read lights if(scene.NumLights > 0 && scene.Lights != IntPtr.Zero) { AiLight[] lights = MemoryHelper.MarshalArray<AiLight>(scene.Lights, (int) scene.NumLights, true); _lights = new Light[lights.Length]; for(int i = 0; i < _lights.Length; i++) { _lights[i] = new Light(lights[i]); } } //Read cameras if(scene.NumCameras > 0 && scene.Cameras != IntPtr.Zero) { AiCamera[] cameras = MemoryHelper.MarshalArray<AiCamera>(scene.Cameras, (int) scene.NumCameras, true); _cameras = new Camera[cameras.Length]; for(int i = 0; i < _cameras.Length; i++) { _cameras[i] = new Camera(cameras[i]); } } //Read Textures if(scene.NumTextures > 0 && scene.Textures != IntPtr.Zero) { AiTexture[] textures = MemoryHelper.MarshalArray<AiTexture>(scene.Textures, (int) scene.NumTextures, true); _textures = new Texture[textures.Length]; for(int i = 0; i < _textures.Length; i++) { _textures[i] = Texture.CreateTexture(textures[i]); } } //Read animations if(scene.NumAnimations > 0 && scene.Animations != IntPtr.Zero) { AiAnimation[] animations = MemoryHelper.MarshalArray<AiAnimation>(scene.Animations, (int) scene.NumAnimations, true); _animations = new Animation[animations.Length]; for(int i = 0; i < _animations.Length; i++) { _animations[i] = new Animation(animations[i]); } } }