Exemplo n.º 1
0
 /// <summary>
 /// Creates a new empty geometry.
 /// </summary>
 public Geometry(Device device, SceneFlags sceneFlags, TraversalFlags traversalFlags = TraversalFlags.Single)
 {
     this.device         = device;
     this.sceneFlags     = sceneFlags;
     this.traversalFlags = traversalFlags;
     scenePtr            = RTC.NewScene(device.DevicePtr, sceneFlags, traversalFlags);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new empty geometry.
 /// </summary>
 public Geometry(SceneFlags sceneFlags, TraversalFlags traversalFlags = TraversalFlags.Single)
 {
     RTC.Register();
     this.sceneFlags     = sceneFlags;
     this.traversalFlags = traversalFlags;
     scenePtr            = RTC.NewScene(sceneFlags, traversalFlags);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Starts a new scene for the current client event.
        /// </summary>
        public void NewScene(ushort sceneId, SceneFlags flags, uint unk1 = 0u, byte unk2 = 0, uint unk3 = 0u, uint unk4 = 0u, uint unk5 = 0u)
        {
            #if DEBUG
            Console.WriteLine($"{owner.Character.Name} starting scene {sceneId} for event {activeEvent.Id:X4}.");
            #endif

            if (activeEvent == null)
            {
                throw new EventStateException($"Scene {sceneId} has no existing event in progress!");
            }

            if (!ScriptManager.IsValidEventScene(activeEvent.Id, sceneId))
            {
                throw new ArgumentException($"Invalid scene {sceneId} for event {activeEvent.Id:X4}!", nameof(sceneId));
            }

            activeEvent.SceneNew(sceneId, flags);

            owner.Session.Send(new ServerEventSceneStart
            {
                Event = activeEvent,
                Flags = flags,
                Unk1  = unk1,
                Unk2  = unk2,
                Unk3  = unk3,
                Unk4  = unk4,
                Unk5  = unk5
            });
        }
Exemplo n.º 4
0
        #pragma warning restore 465

        public static IntPtr NewScene(SceneFlags flags,
                                      AlgorithmFlags aFlags)
        {
            var retval = NativeMethods.rtcNewScene(flags,
                                                   aFlags);

            CheckLastError();
            return(retval);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new instance of the <see cref="Scene"/> class.
 /// </summary>
 public Scene()
 {
     m_flags      = SceneFlags.None;
     m_rootNode   = null;
     m_meshes     = new List <Mesh>();
     m_lights     = new List <Light>();
     m_cameras    = new List <Camera>();
     m_textures   = new List <EmbeddedTexture>();
     m_animations = new List <Animation>();
     m_materials  = new List <Material>();
 }
Exemplo n.º 6
0
        public uint PlaySceneByPackageId(uint sceneScriptPackageId, SceneFlags playbackflags = SceneFlags.Unk16, Position position = null)
        {
            SceneTemplate sceneTemplate = new SceneTemplate();

            sceneTemplate.SceneId        = 0;
            sceneTemplate.ScenePackageId = sceneScriptPackageId;
            sceneTemplate.PlaybackFlags  = playbackflags;
            sceneTemplate.ScriptId       = 0;

            return(PlaySceneByTemplate(sceneTemplate, position));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Instantiates a new scene with the given scene and algorithm flags.
        /// </summary>
        /// <param name="sceneFlags">The scene flags to use.</param>
        /// <param name="algorithmFlags">The algorithm flags to use.</param>
        public Scene(SceneFlags sceneFlags = SceneFlags.Dynamic
                     | SceneFlags.Coherent,
                     AlgorithmFlags algorithmFlags = AlgorithmFlags.Intersect1
                     | AlgorithmFlags.Intersect4)
        {
            if (!sceneFlags.HasFlag(SceneFlags.Dynamic))
            {
                sceneFlags |= SceneFlags.Dynamic;
            }

            this.sceneFlags     = sceneFlags;
            this.algorithmFlags = algorithmFlags;
            this.nativePtr      = RTC.NewScene(SceneFlags,
                                               AlgorithmFlags);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Reads the unmanaged data from the native value.
        /// </summary>
        /// <param name="nativeValue">Input native value</param>
        void IMarshalable <Scene, AiScene> .FromNative(ref AiScene nativeValue)
        {
            Clear();

            m_flags = nativeValue.Flags;

            //Read materials
            if (nativeValue.NumMaterials > 0 && nativeValue.Materials != IntPtr.Zero)
            {
                m_materials.AddRange(MemoryHelper.FromNativeArray <Material, AiMaterial>(nativeValue.Materials, (int)nativeValue.NumMaterials, true));
            }

            //Read scenegraph
            if (nativeValue.RootNode != IntPtr.Zero)
            {
                m_rootNode = MemoryHelper.FromNativePointer <Node, AiNode>(nativeValue.RootNode);
            }

            //Read meshes
            if (nativeValue.NumMeshes > 0 && nativeValue.Meshes != IntPtr.Zero)
            {
                m_meshes.AddRange(MemoryHelper.FromNativeArray <Mesh, AiMesh>(nativeValue.Meshes, (int)nativeValue.NumMeshes, true));
            }

            //Read lights
            if (nativeValue.NumLights > 0 && nativeValue.Lights != IntPtr.Zero)
            {
                m_lights.AddRange(MemoryHelper.FromNativeArray <Light, AiLight>(nativeValue.Lights, (int)nativeValue.NumLights, true));
            }

            //Read cameras
            if (nativeValue.NumCameras > 0 && nativeValue.Cameras != IntPtr.Zero)
            {
                m_cameras.AddRange(MemoryHelper.FromNativeArray <Camera, AiCamera>(nativeValue.Cameras, (int)nativeValue.NumCameras, true));
            }

            //Read textures
            if (nativeValue.NumTextures > 0 && nativeValue.Textures != IntPtr.Zero)
            {
                m_textures.AddRange(MemoryHelper.FromNativeArray <EmbeddedTexture, AiTexture>(nativeValue.Textures, (int)nativeValue.NumTextures, true));
            }

            //Read animations
            if (nativeValue.NumAnimations > 0 && nativeValue.Animations != IntPtr.Zero)
            {
                m_animations.AddRange(MemoryHelper.FromNativeArray <Animation, AiAnimation>(nativeValue.Animations, (int)nativeValue.NumAnimations, true));
            }
        }
Exemplo n.º 9
0
        private static void CreateGeometry(Device device, SceneFlags sceneFlags, TraversalFlags traversalFlags, MeshFlags meshFlags, TriangleMesh sphere, int numMeshes)
        {
            using (var scene = new Scene <Sphere>(device, sceneFlags, traversalFlags))
            {
                for (var t = 0; t < numMeshes; ++t)
                {
                    scene.Add(new Sphere(device, sceneFlags, traversalFlags, sphere, meshFlags));

                    for (int v = 0; v < sphere.Vertices.Count; ++v)
                    {
                        sphere.Vertices[v] = (Vector)sphere.Vertices[v] + new Vector(1, 1, 1);
                    }
                }

                scene.Commit();
            }
        }
Exemplo n.º 10
0
        /// <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]);
                }
            }
        }
Exemplo n.º 11
0
        public static IEnumerable <Tuple <String, Action, Func <Double, String> > > Geometries(Device device, SceneFlags sceneFlags, TraversalFlags traversalFlags)
        {
            var items = new Dictionary <String, Tuple <int, int> >
            {
                { "120", new Tuple <int, int>(6, 1) },
                { "1k", new Tuple <int, int>(17, 1) },
                { "10k", new Tuple <int, int>(51, 1) },
                { "100k", new Tuple <int, int>(159, 1) },
                { "1000k_1", new Tuple <int, int>(501, 1) },
                { "100k_10", new Tuple <int, int>(159, 10) },
                { "10k_100", new Tuple <int, int>(51, 100) },
                { "1k_1000", new Tuple <int, int>(17, 1000) },
                //{ "120_10000", new Tuple<int, int>(6, 8334) },
            };

            foreach (var item in items)
            {
                var sphere = (TriangleMesh)Sphere.GenerateSphere(device, item.Value.Item1);
                yield return(new Tuple <String, Action, Func <Double, String> >("create_static_geometry_" + item.Key,
                                                                                () => CreateGeometry(device, sceneFlags, traversalFlags, MeshFlags.Static, sphere, item.Value.Item2),
                                                                                (t) => String.Format("{0:N3} Mtris/s", 1e-6 * item.Value.Item2 * sphere.Indices.Count / 3)));
            }

            foreach (var item in items)
            {
                var sphere = (TriangleMesh)Sphere.GenerateSphere(device, item.Value.Item1);
                yield return(new Tuple <String, Action, Func <Double, String> >("create_dynamic_geometry_" + item.Key,
                                                                                () => CreateGeometry(device, sceneFlags, traversalFlags, MeshFlags.Dynamic, sphere, item.Value.Item2),
                                                                                (t) => String.Format("{0:N3} Mtris/s", 1e-6 * item.Value.Item2 * sphere.Indices.Count / 3)));
            }
        }
Exemplo n.º 12
0
        public static IEnumerable <Tuple <String, Action, Func <Double, String> > > Occlusions(Device device, SceneFlags sceneFlags, TraversalFlags traversalFlags, int numPhi, int w, int h)
        {
            Func <Double, String> timer = (t) => String.Format("{0:N3} Mrays/s", 1e-6 * w * h / t);

            using (var scene = new Scene <Sphere>(device, sceneFlags, traversalFlags))
            {
                scene.Add(new Sphere(scene.Device, sceneFlags, traversalFlags, numPhi));
                scene.Commit();

                if (traversalFlags.HasFlag(TraversalFlags.Single))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("coherent_occlusion1",
                                                                                    () => CoherentOcclusion1(scene, w, h),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet4))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("coherent_occlusion4",
                                                                                    () => CoherentOcclusion4(scene, w, h),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet8))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("coherent_occlusion8",
                                                                                    () => CoherentOcclusion8(scene, w, h),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet16))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("coherent_occlusion16",
                                                                                    () => CoherentOcclusion16(scene, w, h),
                                                                                    timer));
                }

                var random = new Random();
                var rays   = new Ray[w * h];

                for (var t = 0; t < w * h; ++t)
                {
                    rays[t] = new Ray(Vector.Zero, new Vector(2 * (float)random.NextDouble() - 1,
                                                              2 * (float)random.NextDouble() - 1,
                                                              2 * (float)random.NextDouble() - 1));
                }

                if (traversalFlags.HasFlag(TraversalFlags.Single))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("incoherent_occlusion1",
                                                                                    () => IncoherentOcclusion1(scene, w * h, rays),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet4))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("incoherent_occlusion4",
                                                                                    () => IncoherentOcclusion4(scene, w * h, rays),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet8))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("incoherent_occlusion8",
                                                                                    () => IncoherentOcclusion8(scene, w * h, rays),
                                                                                    timer));
                }
                if (traversalFlags.HasFlag(TraversalFlags.Packet16))
                {
                    yield return(new Tuple <String, Action, Func <Double, String> >("incoherent_occlusion16",
                                                                                    () => IncoherentOcclusion16(scene, w * h, rays),
                                                                                    timer));
                }
            }
        }
Exemplo n.º 13
0
        private static void CreateGeometry(SceneFlags sceneFlags, TraversalFlags traversalFlags, MeshFlags meshFlags, TriangleMesh sphere, int numMeshes)
        {
            using (var scene = new Scene<Sphere>(sceneFlags, traversalFlags))
            {
                for (var t = 0; t < numMeshes; ++t)
                {
                    scene.Add(new Sphere(sceneFlags, traversalFlags, sphere, meshFlags));

                    for (int v = 0; v < sphere.Vertices.Count; ++v)
                        sphere.Vertices[v] = (Vector)sphere.Vertices[v] + new Vector(1, 1, 1);
                }

                scene.Commit();
            }
        }
Exemplo n.º 14
0
        public static IEnumerable<Tuple<String, Action, Func<Double, String>>> Occlusions(SceneFlags sceneFlags, TraversalFlags traversalFlags, int numPhi, int w, int h)
        {
            Func<Double, String> timer = (t) => String.Format("{0:N3} Mrays/s", 1e-6 * w * h / t);

            using (var scene = new Scene<Sphere>(sceneFlags, traversalFlags))
            {
                scene.Add(new Sphere(sceneFlags, traversalFlags, numPhi));
                scene.Commit();

                if (traversalFlags.HasFlag(TraversalFlags.Single))
                    yield return new Tuple<String, Action, Func<Double, String>>("coherent_occlusion1",
                                                                                 () => CoherentOcclusion1(scene, w, h),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet4))
                    yield return new Tuple<String, Action, Func<Double, String>>("coherent_occlusion4",
                                                                                 () => CoherentOcclusion4(scene, w, h),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet8))
                    yield return new Tuple<String, Action, Func<Double, String>>("coherent_occlusion8",
                                                                                 () => CoherentOcclusion8(scene, w, h),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet16))
                    yield return new Tuple<String, Action, Func<Double, String>>("coherent_occlusion16",
                                                                                 () => CoherentOcclusion16(scene, w, h),
                                                                                 timer);

                var random = new Random();
                var rays = new Ray[w * h];

                for (var t = 0; t < w * h; ++t)
                    rays[t] = new Ray(Vector.Zero, new Vector(2 * (float)random.NextDouble() - 1,
                                                              2 * (float)random.NextDouble() - 1,
                                                              2 * (float)random.NextDouble() - 1));

                if (traversalFlags.HasFlag(TraversalFlags.Single))
                    yield return new Tuple<String, Action, Func<Double, String>>("incoherent_occlusion1",
                                                                                 () => IncoherentOcclusion1(scene, w * h, rays),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet4))
                    yield return new Tuple<String, Action, Func<Double, String>>("incoherent_occlusion4",
                                                                                 () => IncoherentOcclusion4(scene, w * h, rays),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet8))
                    yield return new Tuple<String, Action, Func<Double, String>>("incoherent_occlusion8",
                                                                                 () => IncoherentOcclusion8(scene, w * h, rays),
                                                                                 timer);
                if (traversalFlags.HasFlag(TraversalFlags.Packet16))
                    yield return new Tuple<String, Action, Func<Double, String>>("incoherent_occlusion16",
                                                                                 () => IncoherentOcclusion16(scene, w * h, rays),
                                                                                 timer);
            }
        }
Exemplo n.º 15
0
 public Sphere(SceneFlags sceneFlags, TraversalFlags traversalFlags, int numPhi, MeshFlags meshFlags = MeshFlags.Static)
 {
     geometry = new Geometry(sceneFlags, traversalFlags);
     geometry.Add(GenerateSphere(numPhi), meshFlags);
 }
Exemplo n.º 16
0
 public Sphere(SceneFlags sceneFlags, TraversalFlags traversalFlags, IMesh mesh, MeshFlags meshFlags = MeshFlags.Static)
 {
     geometry = new Geometry(sceneFlags, traversalFlags);
     geometry.Add(mesh, meshFlags);
 }
Exemplo n.º 17
0
 public Sphere(SceneFlags sceneFlags, TraversalFlags traversalFlags, int numPhi, MeshFlags meshFlags = MeshFlags.Static)
 {
     geometry = new Geometry(sceneFlags, traversalFlags);
     geometry.Add(GenerateSphere(numPhi), meshFlags);
 }
Exemplo n.º 18
0
 public static extern IntPtr NewScene(SceneFlags flags, TraversalFlags aFlags);
Exemplo n.º 19
0
 public static extern IntPtr rtcNewScene(SceneFlags flags,
                                         AlgorithmFlags aFlags);
Exemplo n.º 20
0
 public void SceneNew(ushort sceneId, SceneFlags flags)
 {
     ActiveScene = new Scene(sceneId, flags);
 }
Exemplo n.º 21
0
 public Scene(ushort id, SceneFlags flags)
 {
     Id    = id;
     Flags = flags;
 }
Exemplo n.º 22
0
        public static IEnumerable<Tuple<String, Action, Func<Double, String>>> Geometries(SceneFlags sceneFlags, TraversalFlags traversalFlags)
        {
            var items = new Dictionary<String, Tuple<int, int>>
            {
                { "120", new Tuple<int, int>(6, 1) },
                { "1k", new Tuple<int, int>(17, 1) },
                { "10k", new Tuple<int, int>(51, 1) },
                { "100k", new Tuple<int, int>(159, 1) },
                { "1000k_1", new Tuple<int, int>(501, 1) },
                { "100k_10", new Tuple<int, int>(159, 10) },
                { "10k_100", new Tuple<int, int>(51, 100) },
                { "1k_1000", new Tuple<int, int>(17, 1000) },
                //{ "120_10000", new Tuple<int, int>(6, 8334) },
            };

            foreach (var item in items)
            {
                var sphere = (TriangleMesh)Sphere.GenerateSphere(item.Value.Item1);
                yield return new Tuple<String, Action, Func<Double, String>>("create_static_geometry_" + item.Key,
                                                                             () => CreateGeometry(sceneFlags, traversalFlags, MeshFlags.Static, sphere, item.Value.Item2),
                                                                             (t) => String.Format("{0:N3} Mtris/s", 1e-6 * item.Value.Item2 * sphere.Indices.Count / 3));
            }

            foreach (var item in items)
            {
                var sphere = (TriangleMesh)Sphere.GenerateSphere(item.Value.Item1);
                yield return new Tuple<String, Action, Func<Double, String>>("create_dynamic_geometry_" + item.Key,
                                                                             () => CreateGeometry(sceneFlags, traversalFlags, MeshFlags.Dynamic, sphere, item.Value.Item2),
                                                                             (t) => String.Format("{0:N3} Mtris/s", 1e-6 * item.Value.Item2 * sphere.Indices.Count / 3));
            }
        }
Exemplo n.º 23
0
 void RecreateScene(uint sceneScriptPackageId, SceneFlags playbackflags = SceneFlags.Unk16, Position position = null)
 {
     CancelSceneByPackageId(sceneScriptPackageId);
     PlaySceneByPackageId(sceneScriptPackageId, playbackflags, position);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Called when the object is selected in the editor
 /// </summary>
 private void OnEnable()
 {
     // Grab the serialized objects
     mTarget   = (SceneFlags)target;
     mTargetSO = new SerializedObject(target);
 }
Exemplo n.º 25
0
 public Sphere(SceneFlags sceneFlags, TraversalFlags traversalFlags, IMesh mesh, MeshFlags meshFlags = MeshFlags.Static)
 {
     geometry = new Geometry(sceneFlags, traversalFlags);
     geometry.Add(mesh, meshFlags);
 }