Example #1
0
    // Returns room properties of the given |room|.
    private static RoomProperties GetRoomProperties(GvrAudioRoom room)
    {
        RoomProperties roomProperties;
        Vector3        position = room.transform.position;
        Quaternion     rotation = room.transform.rotation;
        Vector3        scale    = Vector3.Scale(room.transform.lossyScale, room.size);

        ConvertAudioTransformFromUnity(ref position, ref rotation);
        roomProperties.positionX        = position.x;
        roomProperties.positionY        = position.y;
        roomProperties.positionZ        = position.z;
        roomProperties.rotationX        = rotation.x;
        roomProperties.rotationY        = rotation.y;
        roomProperties.rotationZ        = rotation.z;
        roomProperties.rotationW        = rotation.w;
        roomProperties.dimensionsX      = scale.x;
        roomProperties.dimensionsY      = scale.y;
        roomProperties.dimensionsZ      = scale.z;
        roomProperties.materialLeft     = room.leftWall;
        roomProperties.materialRight    = room.rightWall;
        roomProperties.materialBottom   = room.floor;
        roomProperties.materialTop      = room.ceiling;
        roomProperties.materialFront    = room.frontWall;
        roomProperties.materialBack     = room.backWall;
        roomProperties.reverbGain       = ConvertAmplitudeFromDb(room.reverbGainDb);
        roomProperties.reverbTime       = room.reverbTime;
        roomProperties.reverbBrightness = room.reverbBrightness;
        roomProperties.reflectionScalar = room.reflectivity;
        return(roomProperties);
    }
Example #2
0
 /// Updates the room effects of the environment with given |room| properties.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateAudioRoom(GvrAudioRoom room, bool roomEnabled)
 {
     // Update the enabled rooms list.
     if (roomEnabled)
     {
         if (!enabledRooms.Contains(room))
         {
             enabledRooms.Add(room);
         }
     }
     else
     {
         enabledRooms.Remove(room);
     }
     // Update the current room effects to be applied.
     if (initialized)
     {
         if (enabledRooms.Count > 0)
         {
             GvrAudioRoom   currentRoom    = enabledRooms[enabledRooms.Count - 1];
             RoomProperties roomProperties = GetRoomProperties(currentRoom);
             // Pass the room properties into a pointer.
             IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(roomProperties));
             Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
             SetRoomProperties(roomPropertiesPtr);
             Marshal.FreeHGlobal(roomPropertiesPtr);
         }
         else
         {
             // Set the room properties to null, which will effectively disable the room effects.
             SetRoomProperties(IntPtr.Zero);
         }
     }
 }
Example #3
0
 void Start()
 {
     room = GetComponent <GvrAudioRoom>();
     if (!room)
     {
         Debug.Log(gameObject.name + " doesn't have a AudioRoom on it");
     }
 }
    /// Returns whether the listener is currently inside the given |room| boundaries.
    public static bool IsListenerInsideRoom(GvrAudioRoom room)
    {
        bool isInside = false;

        if (initialized)
        {
            Vector3    relativePosition = listenerTransform.position - room.transform.position;
            Quaternion rotationInverse  = Quaternion.Inverse(room.transform.rotation);

            bounds.size = Vector3.Scale(room.transform.lossyScale, room.size);
            isInside    = bounds.Contains(rotationInverse * relativePosition);
        }
        return(isInside);
    }
 /// Updates the room effects of the environment with given |room| properties.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateAudioRoom(GvrAudioRoom room, bool roomEnabled)
 {
     // Update the enabled rooms list.
     if (roomEnabled)
     {
         if (!enabledRooms.Contains(room))
         {
             enabledRooms.Add(room);
         }
     }
     else
     {
         enabledRooms.Remove(room);
     }
     // Update the current room effects to be applied.
     if (initialized)
     {
         if (enabledRooms.Count > 0)
         {
             GvrAudioRoom currentRoom = enabledRooms[enabledRooms.Count - 1];
             Vector3      position    = currentRoom.transform.position;
             Quaternion   rotation    = currentRoom.transform.rotation;
             Vector3      scale       = Vector3.Scale(currentRoom.transform.lossyScale, currentRoom.size);
             ConvertAudioTransformFromUnity(ref position, ref rotation);
             float reverbGain = ConvertAmplitudeFromDb(currentRoom.reverbGainDb);
             SetRoomProperties(position.x, position.y, position.z, rotation.x, rotation.y, rotation.z,
                               rotation.w, scale.x, scale.y, scale.z, currentRoom.GetSurfaceMaterials(),
                               currentRoom.reflectivity, reverbGain, currentRoom.reverbBrightness,
                               currentRoom.reverbTime);
         }
         else
         {
             // Set room properties to default, which will effectively disable the room effects.
             SetRoomProperties(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, null, 1.0f,
                               0.0f, 0.0f, 1.0f);
         }
     }
 }
Example #6
0
 private static extern void SetRoomProperties (int roomId, float px, float py, float pz, float qx,
                                               float qy, float qz, float qw, float dx, float dy,
                                               float dz,
                                               GvrAudioRoom.SurfaceMaterial[] materialNames,
                                               float reflectionScalar, float reverbGain,
                                               float reverbBrightness, float reverbTime);
Example #7
0
 /// Updates the room effects of the environment with given |room| properties.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateAudioRoom (int id, Transform transform,
                                     GvrAudioRoom.SurfaceMaterial[] materials, float reflectivity,
                                     float reverbGainDb, float reverbBrightness, float reverbTime,
                                     Vector3 size) {
   if (initialized) {
     // Update room transform.
     Vector3 position = transform.position;
     Quaternion rotation = transform.rotation;
     Vector3 scale = Vector3.Scale(size, transform.lossyScale);
     scale = worldScaleInverse * new Vector3(Mathf.Abs(scale.x), Mathf.Abs(scale.y),
                                             Mathf.Abs(scale.z));
     ConvertAudioTransformFromUnity(ref position, ref rotation);
     float reverbGain = ConvertAmplitudeFromDb(reverbGainDb);
     SetRoomProperties(id, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z,
                       rotation.w, scale.x, scale.y, scale.z, materials, reflectivity, reverbGain,
                       reverbBrightness, reverbTime);
   }
 }
Example #8
0
 // Returns room properties of the given |room|.
 private static RoomProperties GetRoomProperties(GvrAudioRoom room) {
   RoomProperties roomProperties;
   Vector3 position = room.transform.position;
   Quaternion rotation = room.transform.rotation;
   Vector3 scale = Vector3.Scale(room.transform.lossyScale, room.size);
   ConvertAudioTransformFromUnity(ref position, ref rotation);
   roomProperties.positionX = position.x;
   roomProperties.positionY = position.y;
   roomProperties.positionZ = position.z;
   roomProperties.rotationX = rotation.x;
   roomProperties.rotationY = rotation.y;
   roomProperties.rotationZ = rotation.z;
   roomProperties.rotationW = rotation.w;
   roomProperties.dimensionsX = scale.x;
   roomProperties.dimensionsY = scale.y;
   roomProperties.dimensionsZ = scale.z;
   roomProperties.materialLeft = room.leftWall;
   roomProperties.materialRight = room.rightWall;
   roomProperties.materialBottom = room.floor;
   roomProperties.materialTop = room.ceiling;
   roomProperties.materialFront = room.frontWall;
   roomProperties.materialBack = room.backWall;
   roomProperties.reverbGain = ConvertAmplitudeFromDb(room.reverbGainDb);
   roomProperties.reverbTime = room.reverbTime;
   roomProperties.reverbBrightness = room.reverbBrightness;
   roomProperties.reflectionScalar = room.reflectivity;
   return roomProperties;
 }
Example #9
0
  /// Returns whether the listener is currently inside the given |room| boundaries.
  public static bool IsListenerInsideRoom(GvrAudioRoom room) {
    bool isInside = false;
    if(initialized) {
      Vector3 relativePosition = listenerTransform.position - room.transform.position;
      Quaternion rotationInverse = Quaternion.Inverse(room.transform.rotation);

      bounds.size = Vector3.Scale(room.transform.lossyScale, room.size);
      isInside = bounds.Contains(rotationInverse * relativePosition);
    }
    return isInside;
  }
Example #10
0
 /// Updates the room effects of the environment with given |room| properties.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateAudioRoom(GvrAudioRoom room, bool roomEnabled) {
   // Update the enabled rooms list.
   if (roomEnabled) {
     if (!enabledRooms.Contains(room)) {
       enabledRooms.Add(room);
     }
   } else {
     enabledRooms.Remove(room);
   }
   // Update the current room effects to be applied.
   if(initialized) {
     if (enabledRooms.Count > 0) {
       GvrAudioRoom currentRoom = enabledRooms[enabledRooms.Count - 1];
       RoomProperties roomProperties = GetRoomProperties(currentRoom);
       // Pass the room properties into a pointer.
       IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(roomProperties));
       Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
       SetRoomProperties(roomPropertiesPtr);
       Marshal.FreeHGlobal(roomPropertiesPtr);
     } else {
       // Set the room properties to null, which will effectively disable the room effects.
       SetRoomProperties(IntPtr.Zero);
     }
   }
 }