Beispiel #1
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     smi = new SMInstance(this);
     smi.StartSM();
     workTime          = float.PositiveInfinity;
     workTimeRemaining = float.PositiveInfinity;
 }
 protected override void OnSpawn()
 {
     base.OnSpawn();
     smi = new SMInstance(this);
     smi.StartSM();
     Subscribe(-794517298, OnDoBuildingDamageDelegate);
     if (destroyOnDamaged)
     {
         Subscribe(774203113, DestroyOnDamagedDelegate);
     }
     if (hitpoints <= 0)
     {
         Trigger(774203113, this);
     }
 }
Beispiel #3
0
        public ColorDepthImage GetImage()
        {
            //Checks to make sure that the camera has been properly initialized
            if (Status == CameraStatus.Stopped)
            {
                throw new InvalidOperationException("The camera cannot produce data unless it is running");
            }

            //Acquires the frame
            Status acquisitionResult = SMInstance.AcquireFrame(true);

            if (acquisitionResult.IsError())
            {
                throw new Exception("Unable to capture frame: " + acquisitionResult);
            }

            Texture2D colorTex = new Texture2D(WIDTH, HEIGHT, TextureFormat.RGBA32, false);
            Texture2D depthTex = new Texture2D(WIDTH, HEIGHT, TextureFormat.RGBA32, false);

            //Extract the color image
            Image     colorImage = SampleStream.Sample.Color;
            ImageData colorImageData;

            colorImage.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_RGB32, out colorImageData);
            colorImageData.ToTexture2D(0, colorTex);

            //Extract and map the depth image
            Image      initialDepthImage = SampleStream.Sample.Depth;
            Projection proj       = SMInstance.CaptureManager.Device.CreateProjection();
            Image      depthImage = proj.CreateDepthImageMappedToColor(initialDepthImage, colorImage);
            ImageData  depthImageData;

            depthImage.AcquireAccess(ImageAccess.ACCESS_READ, PixelFormat.PIXEL_FORMAT_RGB32, out depthImageData);
            depthImageData.ToTexture2D(0, depthTex);

            //Clean up resources
            colorImage.Dispose();
            depthImage.Dispose();
            initialDepthImage.Dispose();
            proj.Dispose();
            colorImage.ReleaseAccess(colorImageData);
            depthImage.ReleaseAccess(depthImageData);

            //Release the acquired frame
            SMInstance.ReleaseFrame();

            return(new ColorDepthImage(colorTex, depthTex));
        }
Beispiel #4
0
        public void StartCapture()
        {
            //Checks to make sure that the camera has not already been started
            if (Status != CameraStatus.Stopped)
            {
                throw new InvalidOperationException("A camera cannot be started if it is already running");
            }

            //Updates the status
            Status = CameraStatus.Running;

            //Initialize the sense manager and streams
            SampleStream = SampleReader.Activate(SMInstance);
            SampleStream.EnableStream(StreamType.STREAM_TYPE_COLOR, WIDTH, HEIGHT, FPS, StreamOption.STREAM_OPTION_STRONG_STREAM_SYNC);
            SampleStream.EnableStream(StreamType.STREAM_TYPE_DEPTH, WIDTH, HEIGHT, FPS, StreamOption.STREAM_OPTION_STRONG_STREAM_SYNC);
            SMInstance.Init();
        }
Beispiel #5
0
        public void StopCapture()
        {
            //Checks to make sure that the camera has not already been stopped before starting it again
            if (Status != CameraStatus.Running)
            {
                throw new InvalidOperationException("A camera cannot be stopped if it is not running");
            }

            //Updates the status
            Status = CameraStatus.Stopped;

            //Dispose of the created stream
            SampleStream.Dispose();
            SampleStream = null;

            //Close the sense manager
            SMInstance.Close();
        }
 protected override void OnLoadLevel()
 {
     smi = null;
     base.OnLoadLevel();
 }