/* © Siemens AG, 2017-2018 Author: Dr. Martin Bischoff (martin.bischoff@siemens.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // Modified by Lydia Ebbinghaus & Jana-Sophie schönfeld. using UnityEngine; namespace RosSharp.RosBridgeClient { [RequireComponent(typeof(RosConnector))] public class ImageSubscriberMod : UnitySubscriber { public MeshRenderer meshRenderer; public bool stopProcessing; private Texture2D texture2D; // Modified. // Changed to public to check if imageMessage is received and to get image data. public byte[] imageData; public bool isMessageReceived; // Added to allow subscriber to process messages. public bool oneMessageReceived; protected override void Start() { base.Start(); texture2D = new Texture2D(1, 1); if(!stopProcessing)meshRenderer.material = new Material(Shader.Find("Standard")); } private void Update() { if (!stopProcessing && isMessageReceived) ProcessMessage(); } protected override void ReceiveMessage(MessageTypes.Sensor.CompressedImage compressedImage) { imageData = compressedImage.data; isMessageReceived = true; // Modified. oneMessageReceived=true; } private void ProcessMessage() { texture2D.LoadImage(imageData); texture2D.Apply(); meshRenderer.material.SetTexture("_MainTex", texture2D); isMessageReceived = false; } } }