| 1 | using UnityEngine; |
| 2 | using System; |
| 3 | using System.Runtime.InteropServices; |
| 4 | using AOT; |
| 5 | using Oculus.Avatar; |
| 6 | |
| 7 | //This needs to be the csharp equivalent of ovrAvatarCapabilities in OVR_Avatar.h |
| 8 | [Flags] |
| 9 | public enum ovrAvatarCapabilities |
| 10 | { |
| 11 | Body = 1 << 0, |
| 12 | Hands = 1 << 1, |
| 13 | Base = 1 << 2, |
| 14 | BodyTilt = 1 << 4, |
| 15 | Expressive = 1 << 5, |
| 16 | All = -1 |
| 17 | }; |
| 18 | |
| 19 | // This needs to be the csharp equivalent of ovrAvatarMessageType in OVR_Avatar.h |
| 20 | public enum ovrAvatarMessageType { |
| 21 | AvatarSpecification, |
| 22 | AssetLoaded, |
| 23 | Count |
| 24 | }; |
| 25 | |
| 26 | // This needs to be the csharp equivalent of ovrAvatarMessage_AvatarSpecification in OVR_Avatar.h |
| 27 | public struct ovrAvatarMessage_AvatarSpecification { |
| 28 | public IntPtr avatarSpec; //ovrAvatarSpecification*, opaque pointer |
| 29 | public UInt64 oculusUserID; |
| 30 | }; |
| 31 | |
| 32 | // This needs to be the csharp equivalent of ovrAvatarMessage_AssetLoaded in OVR_Avatar.h |
| 33 | public struct ovrAvatarMessage_AssetLoaded { |
| 34 | public UInt64 assetID; |
| 35 | public IntPtr asset; //ovrAvatarAsset*, opaque pointer |
| 36 | }; |
| 37 | |
| 38 | // This needs to be the csharp equivalent of ovrAvatarAssetType in OVR_Avatar.h |
| 39 | public enum ovrAvatarAssetType { |
| 40 | Mesh, |
| 41 | Texture, |
| 42 | Pose, |
| 43 | Material, |
| 44 | CombinedMesh, |
| 45 | PBSMaterial, |
| 46 | Count |
| 47 | }; |
| 48 | |
| 49 | // This needs to be the csharp equivalent of ovrAvatarMeshVertex in OVR_Avatar.h |
| 50 | public struct ovrAvatarMeshVertex |
| 51 | { |
| 52 | public float x; |
| 53 | public float y; |
| 54 | public float z; |
| 55 | public float nx; |
| 56 | public float ny; |
| 57 | public float nz; |
| 58 | public float tx; |
| 59 | public float ty; |
| 60 | public float tz; |
| 61 | public float tw; |
| 62 | public float u; |
| 63 | public float v; |
| 64 | |
| 65 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] |
| 66 | public byte[] blendIndices; ///< Indices into the bind pose |
| 67 | |
| 68 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] |
| 69 | public float[] blendWeights; ///< Blend weights for each component in the bind pose |
| 70 | }; |
| 71 | |
| 72 | // This needs to be the csharp equivalent of ovrAvatarMeshVertex in OVR_Avatar.h |
| 73 | public struct ovrAvatarMeshVertexV2 |
| 74 | { |
| 75 | public float x; |
| 76 | public float y; |
| 77 | public float z; |
| 78 | public float nx; |
| 79 | public float ny; |
| 80 | public float nz; |
| 81 | public float tx; |
| 82 | public float ty; |
| 83 | public float tz; |
| 84 | public float tw; |
| 85 | public float u; |
| 86 | public float v; |
| 87 | public float r; |
| 88 | public float g; |
| 89 | public float b; |
| 90 | public float a; |
| 91 | |
| 92 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] |
| 93 | public byte[] blendIndices; ///< Indices into the bind pose |
| 94 | |
| 95 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] |
| 96 | public float[] blendWeights; ///< Blend weights for each component in the bind pose |
| 97 | }; |
| 98 | |
| 99 | // This needs to be the csharp equivalent of ovrAvatarMeshVertex in OVR_Avatar.h |
| 100 | public struct ovrAvatarBlendVertex |
| 101 | { |
| 102 | public float x; |
| 103 | public float y; |
| 104 | public float z; |
| 105 | public float nx; |
| 106 | public float ny; |
| 107 | public float nz; |
| 108 | public float tx; |
| 109 | public float ty; |
| 110 | public float tz; |
| 111 | }; |
| 112 | |
| 113 | // This needs to be the csharp equivalent of ovrAvatarMeshAssetData in OVR_Avatar.h |
| 114 | public struct ovrAvatarMeshAssetData |
| 115 | { |
| 116 | public UInt32 vertexCount; |
| 117 | public IntPtr vertexBuffer; //const ovrAvatarMeshVertex* |
| 118 | public UInt32 indexCount; |
| 119 | public IntPtr indexBuffer; //const uint16t* |
| 120 | public ovrAvatarSkinnedMeshPose skinnedBindPose; |
| 121 | }; |
| 122 | |
| 123 | /// Mesh Asset Data V2 |
| 124 | /// |
| 125 | public struct ovrAvatarMeshAssetDataV2 |
| 126 | { |
| 127 | public UInt32 vertexCount; |
| 128 | public IntPtr vertexBuffer; //const ovrAvatarMeshVertexV2* |
| 129 | public UInt32 indexCount; |
| 130 | public IntPtr indexBuffer; //const uint16t* |
| 131 | public ovrAvatarSkinnedMeshPose skinnedBindPose; |
| 132 | }; |
| 133 | |
| 134 | // This needs to be the csharp equivalent of ovrAvatarTextureFormat in OVR_Avatar.h |
| 135 | public enum ovrAvatarTextureFormat { |
| 136 | RGB24, |
| 137 | DXT1, |
| 138 | DXT5, |
| 139 | ASTC_RGB_6x6, |
| 140 | ASTC_RGB_6x6_MIPMAPS, |
| 141 | Count |
| 142 | }; |
| 143 | |
| 144 | // This needs to be the csharp equivalent of ovrAvatarTextureAssetData in OVR_Avatar.h |
| 145 | public struct ovrAvatarTextureAssetData { |
| 146 | public ovrAvatarTextureFormat format; |
| 147 | public UInt32 sizeX; |
| 148 | public UInt32 sizeY; |
| 149 | public UInt32 mipCount; |
| 150 | public UInt64 textureDataSize; |
| 151 | public IntPtr textureData; // const uint8_t* |
| 152 | }; |
| 153 | |
| 154 | // This needs to be the csharp equivalent of ovrAvatarRenderPartType in OVR_Avatar.h |
| 155 | public enum ovrAvatarRenderPartType |
| 156 | { |
| 157 | SkinnedMeshRender, |
| 158 | SkinnedMeshRenderPBS, |
| 159 | ProjectorRender, |
| 160 | SkinnedMeshRenderPBS_V2, |
| 161 | Count |
| 162 | }; |
| 163 | |
| 164 | /// Avatar Logging Level |
| 165 | /// Matches the Android Log Levels |
| 166 | public enum ovrAvatarLogLevel |
| 167 | { |
| 168 | Unknown, |
| 169 | Default, |
| 170 | Verbose, |
| 171 | Debug, |
| 172 | Info, |
| 173 | Warn, |
| 174 | Error, |
| 175 | Fatal, |
| 176 | Silent |
| 177 | }; |
| 178 | |
| 179 | // This needs to be the csharp equivalent of ovrAvatarTransform in OVR_Avatar.h |
| 180 | public struct ovrAvatarTransform |
| 181 | { |
| 182 | public Vector3 position; |
| 183 | public Quaternion orientation; |
| 184 | public Vector3 scale; |
| 185 | }; |
| 186 | |
| 187 | // This needs to be the csharp equivalent of ovrAvatarButton in OVR_Avatar.h |
| 188 | [Flags] |
| 189 | public enum ovrAvatarButton |
| 190 | { |
| 191 | One = 0x0001, |
| 192 | Two = 0x0002, |
| 193 | Three = 0x0004, |
| 194 | Joystick = 0x0008, |
| 195 | } |
| 196 | |
| 197 | // This needs to be the csharp equivalent of ovrAvatarTouch in OVR_Avatar.h |
| 198 | [Flags] |
| 199 | public enum ovrAvatarTouch |
| 200 | { |
| 201 | One = 0x0001, |
| 202 | Two = 0x0002, |
| 203 | Joystick = 0x0004, |
| 204 | ThumbRest = 0x0008, |
| 205 | Index = 0x0010, |
| 206 | Pointing = 0x0040, |
| 207 | ThumbUp = 0x0080, |
| 208 | } |
| 209 | |
| 210 | // This needs to be the csharp equivalent of ovrAvatarHandInputState in OVR_Avatar.h |
| 211 | public struct ovrAvatarHandInputState |
| 212 | { |
| 213 | public ovrAvatarTransform transform; |
| 214 | public ovrAvatarButton buttonMask; |
| 215 | public ovrAvatarTouch touchMask; |
| 216 | public float joystickX; |
| 217 | public float joystickY; |
| 218 | public float indexTrigger; |
| 219 | public float handTrigger; |
| 220 | [MarshalAs(UnmanagedType.I1)] |
| 221 | public bool isActive; |
| 222 | }; |
| 223 | |
| 224 | // This needs to be the csharp equivalent of ovrAvatarComponent in OVR_Avatar.h |
| 225 | public struct ovrAvatarComponent |
| 226 | { |
| 227 | public ovrAvatarTransform transform; |
| 228 | public UInt32 renderPartCount; |
| 229 | public IntPtr renderParts; //const ovrAvatarRenderPart* const* |
| 230 | |
| 231 | [MarshalAs(UnmanagedType.LPStr)] |
| 232 | public string name; |
| 233 | }; |
| 234 | |
| 235 | struct ovrAvatarComponent_Offsets |
| 236 | { |
| 237 | public static long transform = Marshal.OffsetOf(typeof(ovrAvatarComponent), "transform").ToInt64(); |
| 238 | public static Int32 renderPartCount = Marshal.OffsetOf(typeof(ovrAvatarComponent), "renderPartCount").ToInt32(); |
| 239 | public static Int32 renderParts = Marshal.OffsetOf(typeof(ovrAvatarComponent), "renderParts").ToInt32(); |
| 240 | public static Int32 name = Marshal.OffsetOf(typeof(ovrAvatarComponent), "name").ToInt32(); |
| 241 | }; |
| 242 | |
| 243 | // This needs to be the csharp equivalent of ovrAvatarBodyComponent in OVR_Avatar.h |
| 244 | public struct ovrAvatarBaseComponent |
| 245 | { |
| 246 | public Vector3 basePosition; |
| 247 | public IntPtr renderComponent; //const ovrAvatarComponent* |
| 248 | }; |
| 249 | |
| 250 | // This needs to be the csharp equivalent of ovrAvatarBodyComponent in OVR_Avatar.h |
| 251 | public struct ovrAvatarBodyComponent { |
| 252 | public ovrAvatarTransform leftEyeTransform; |
| 253 | public ovrAvatarTransform rightEyeTransform; |
| 254 | public ovrAvatarTransform centerEyeTransform; |
| 255 | public IntPtr renderComponent; //const ovrAvatarComponent* |
| 256 | }; |
| 257 | |
| 258 | public struct ovrAvatarBodyComponent_Offsets |
| 259 | { |
| 260 | public static long leftEyeTransform = Marshal.OffsetOf(typeof(ovrAvatarBodyComponent), "leftEyeTransform").ToInt64(); |
| 261 | public static long rightEyeTransform = Marshal.OffsetOf(typeof(ovrAvatarBodyComponent), "rightEyeTransform").ToInt64(); |
| 262 | public static long centerEyeTransform = Marshal.OffsetOf(typeof(ovrAvatarBodyComponent), "centerEyeTransform").ToInt64(); |
| 263 | public static long renderComponent = Marshal.OffsetOf(typeof(ovrAvatarBodyComponent), "renderComponent").ToInt64(); |
| 264 | }; |
| 265 | |
| 266 | // This needs to be the csharp equivalent of ovrAvatarControllerComponent in OVR_Avatar.h |
| 267 | public struct ovrAvatarControllerComponent |
| 268 | { |
| 269 | public ovrAvatarHandInputState inputState; |
| 270 | public IntPtr renderComponent; //const ovrAvatarComponent* |
| 271 | }; |
| 272 | |
| 273 | // This needs to be the csharp equivalent of ovrAvatarHandComponent in OVR_Avatar.h |
| 274 | public struct ovrAvatarHandComponent { |
| 275 | public ovrAvatarHandInputState inputState; |
| 276 | public IntPtr renderComponent; //const ovrAvatarComponent* |
| 277 | }; |
| 278 | |
| 279 | // This needs to be the csharp equivalent of ovrAvatarMaterialLayerBlendMode in OVR_Avatar.h |
| 280 | public enum ovrAvatarMaterialLayerBlendMode{ |
| 281 | Add, |
| 282 | Multiply, |
| 283 | Count |
| 284 | }; |
| 285 | |
| 286 | // This needs to be the csharp equivalent of ovrAvatarMaterialLayerSampleMode in OVR_Avatar.h |
| 287 | public enum ovrAvatarMaterialLayerSampleMode{ |
| 288 | Color, |
| 289 | Texture, |
| 290 | TextureSingleChannel, |
| 291 | Parallax, |
| 292 | Count |
| 293 | }; |
| 294 | |
| 295 | // This needs to be the csharp equivalent of ovrAvatarMaterialLayerMaskType in OVR_Avatar.h |
| 296 | public enum ovrAvatarMaterialMaskType{ |
| 297 | None, |
| 298 | Positional, |
| 299 | ViewReflection, |
| 300 | Fresnel, |
| 301 | Pulse, |
| 302 | Count |
| 303 | }; |
| 304 | |
| 305 | // This needs to be the csharp equivalent of Controller Types from OVR_Avatar.h |
| 306 | public enum ovrAvatarControllerType |
| 307 | { |
| 308 | Touch, |
| 309 | Malibu, |
| 310 | Go, |
| 311 | Quest, |
| 312 | |
| 313 | Count, |
| 314 | }; |
| 315 | |
| 316 | public enum ovrAvatarAssetLevelOfDetail |
| 317 | { |
| 318 | Lowest = 1, |
| 319 | Medium = 3, |
| 320 | Highest = 5, |
| 321 | }; |
| 322 | |
| 323 | public enum ovrAvatarLookAndFeelVersion |
| 324 | { |
| 325 | Unknown = -1, |
| 326 | One = 0, |
| 327 | Two = 1, |
| 328 | }; |
| 329 | |
| 330 | // This needs to be the csharp equivalent of ovrAvatarMaterialLayerState in OVR_Avatar.h |
| 331 | public struct ovrAvatarMaterialLayerState{ |
| 332 | public ovrAvatarMaterialLayerBlendMode blendMode; |
| 333 | public ovrAvatarMaterialLayerSampleMode sampleMode; |
| 334 | public ovrAvatarMaterialMaskType maskType; |
| 335 | public Vector4 layerColor; |
| 336 | public Vector4 sampleParameters; |
| 337 | public UInt64 sampleTexture; |
| 338 | public Vector4 sampleScaleOffset; |
| 339 | public Vector4 maskParameters; |
| 340 | public Vector4 maskAxis; |
| 341 | |
| 342 | static bool VectorEquals(Vector4 a, Vector4 b) |
| 343 | { |
| 344 | return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; |
| 345 | } |
| 346 | |
| 347 | public override bool Equals(object obj) |
| 348 | { |
| 349 | if (!(obj is ovrAvatarMaterialLayerState)) |
| 350 | { |
| 351 | return false; |
| 352 | } |
| 353 | ovrAvatarMaterialLayerState other = (ovrAvatarMaterialLayerState)obj; |
| 354 | if (blendMode != other.blendMode) return false; |
| 355 | if (sampleMode != other.sampleMode) return false; |
| 356 | if (maskType != other.maskType) return false; |
| 357 | if (!VectorEquals(layerColor, other.layerColor)) return false; |
| 358 | if (!VectorEquals(sampleParameters, other.sampleParameters)) return false; |
| 359 | if (sampleTexture != other.sampleTexture) return false; |
| 360 | if (!VectorEquals(sampleScaleOffset, other.sampleScaleOffset)) return false; |
| 361 | if (!VectorEquals(maskParameters, other.maskParameters)) return false; |
| 362 | if (!VectorEquals(maskAxis, other.maskAxis)) return false; |
| 363 | return true; |
| 364 | } |
| 365 | public override int GetHashCode() |
| 366 | { |
| 367 | return blendMode.GetHashCode() ^ |
| 368 | sampleMode.GetHashCode() ^ |
| 369 | maskType.GetHashCode() ^ |
| 370 | layerColor.GetHashCode() ^ |
| 371 | sampleParameters.GetHashCode() ^ |
| 372 | sampleTexture.GetHashCode() ^ |
| 373 | sampleScaleOffset.GetHashCode() ^ |
| 374 | maskParameters.GetHashCode() ^ |
| 375 | maskAxis.GetHashCode(); |
| 376 | } |
| 377 | }; |
| 378 | |
| 379 | // This needs to be the csharp equivalent of ovrAvatarMaterialState in OVR_Avatar.h |
| 380 | public struct ovrAvatarMaterialState |
| 381 | { |
| 382 | public Vector4 baseColor; |
| 383 | public ovrAvatarMaterialMaskType baseMaskType; |
| 384 | public Vector4 baseMaskParameters; |
| 385 | public Vector4 baseMaskAxis; |
| 386 | public ovrAvatarMaterialLayerSampleMode sampleMode; |
| 387 | public UInt64 alphaMaskTextureID; |
| 388 | public Vector4 alphaMaskScaleOffset; |
| 389 | public UInt64 normalMapTextureID; |
| 390 | public Vector4 normalMapScaleOffset; |
| 391 | public UInt64 parallaxMapTextureID; |
| 392 | public Vector4 parallaxMapScaleOffset; |
| 393 | public UInt64 roughnessMapTextureID; |
| 394 | public Vector4 roughnessMapScaleOffset; |
| 395 | public UInt32 layerCount; |
| 396 | |
| 397 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] |
| 398 | public ovrAvatarMaterialLayerState[] layers; |
| 399 | |
| 400 | static bool VectorEquals(Vector4 a, Vector4 b) |
| 401 | { |
| 402 | return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; |
| 403 | } |
| 404 | |
| 405 | public override bool Equals(object obj) |
| 406 | { |
| 407 | if (!(obj is ovrAvatarMaterialState)) |
| 408 | { |
| 409 | return false; |
| 410 | } |
| 411 | ovrAvatarMaterialState other = (ovrAvatarMaterialState)obj; |
| 412 | if (!VectorEquals(baseColor, other.baseColor)) return false; |
| 413 | if (baseMaskType != other.baseMaskType) return false; |
| 414 | if (!VectorEquals(baseMaskParameters, other.baseMaskParameters)) return false; |
| 415 | if (!VectorEquals(baseMaskAxis, other.baseMaskAxis)) return false; |
| 416 | if (sampleMode != other.sampleMode) return false; |
| 417 | if (alphaMaskTextureID != other.alphaMaskTextureID) return false; |
| 418 | if (!VectorEquals(alphaMaskScaleOffset, other.alphaMaskScaleOffset)) return false; |
| 419 | if (normalMapTextureID != other.normalMapTextureID) return false; |
| 420 | if (!VectorEquals(normalMapScaleOffset, other.normalMapScaleOffset)) return false; |
| 421 | if (parallaxMapTextureID != other.parallaxMapTextureID) return false; |
| 422 | if (!VectorEquals(parallaxMapScaleOffset, other.parallaxMapScaleOffset)) return false; |
| 423 | if (roughnessMapTextureID != other.roughnessMapTextureID) return false; |
| 424 | if (!VectorEquals(roughnessMapScaleOffset, other.roughnessMapScaleOffset)) return false; |
| 425 | if (layerCount != other.layerCount) return false; |
| 426 | for (int i = 0; i < layerCount; ++i) |
| 427 | { |
| 428 | if (!layers[i].Equals(other.layers[i])) return false; |
| 429 | } |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | public override int GetHashCode() |
| 434 | { |
| 435 | int hash = 0; |
| 436 | hash ^= baseColor.GetHashCode(); |
| 437 | hash ^= baseMaskType.GetHashCode(); |
| 438 | hash ^= baseMaskParameters.GetHashCode(); |
| 439 | hash ^= baseMaskAxis.GetHashCode(); |
| 440 | hash ^= sampleMode.GetHashCode(); |
| 441 | hash ^= alphaMaskTextureID.GetHashCode(); |
| 442 | hash ^= alphaMaskScaleOffset.GetHashCode(); |
| 443 | hash ^= normalMapTextureID.GetHashCode(); |
| 444 | hash ^= normalMapScaleOffset.GetHashCode(); |
| 445 | hash ^= parallaxMapTextureID.GetHashCode(); |
| 446 | hash ^= parallaxMapScaleOffset.GetHashCode(); |
| 447 | hash ^= roughnessMapTextureID.GetHashCode(); |
| 448 | hash ^= roughnessMapScaleOffset.GetHashCode(); |
| 449 | hash ^= layerCount.GetHashCode(); |
| 450 | for (int i = 0; i < layerCount; ++i) |
| 451 | { |
| 452 | hash ^= layers[i].GetHashCode(); |
| 453 | } |
| 454 | return hash; |
| 455 | } |
| 456 | }; |
| 457 | |
| 458 | public struct ovrAvatarExpressiveParameters |
| 459 | { |
| 460 | public Vector4 irisColor; |
| 461 | public Vector4 scleraColor; |
| 462 | public Vector4 lashColor; |
| 463 | public Vector4 browColor; |
| 464 | public Vector4 lipColor; |
| 465 | public Vector4 teethColor; |
| 466 | public Vector4 gumColor; |
| 467 | public float browLashIntensity; |
| 468 | public float lipSmoothness; |
| 469 | |
| 470 | static bool VectorEquals(Vector4 a, Vector4 b) |
| 471 | { |
| 472 | return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; |
| 473 | } |
| 474 | public override bool Equals(object obj) |
| 475 | { |
| 476 | if (!(obj is ovrAvatarExpressiveParameters)) |
| 477 | { |
| 478 | return false; |
| 479 | } |
| 480 | ovrAvatarExpressiveParameters other = (ovrAvatarExpressiveParameters)obj; |
| 481 | if (!VectorEquals(irisColor, other.irisColor)) return false; |
| 482 | if (!VectorEquals(scleraColor, other.scleraColor)) return false; |
| 483 | if (!VectorEquals(lashColor, other.lashColor)) return false; |
| 484 | if (!VectorEquals(browColor, other.browColor)) return false; |
| 485 | if (!VectorEquals(lipColor, other.lipColor)) return false; |
| 486 | if (!VectorEquals(teethColor, other.teethColor)) return false; |
| 487 | if (!VectorEquals(gumColor, other.gumColor)) return false; |
| 488 | if (browLashIntensity != other.browLashIntensity) return false; |
| 489 | if (lipSmoothness != other.lipSmoothness) return false; |
| 490 | |
| 491 | return true; |
| 492 | } |
| 493 | public override int GetHashCode() |
| 494 | { |
| 495 | return irisColor.GetHashCode() ^ |
| 496 | scleraColor.GetHashCode() ^ |
| 497 | lashColor.GetHashCode() ^ |
| 498 | browColor.GetHashCode() ^ |
| 499 | lipColor.GetHashCode() ^ |
| 500 | teethColor.GetHashCode() ^ |
| 501 | gumColor.GetHashCode() ^ |
| 502 | browLashIntensity.GetHashCode() ^ |
| 503 | lipSmoothness.GetHashCode(); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | public struct ovrAvatarPBSMaterialState |
| 508 | { |
| 509 | public Vector4 baseColor; ///< Underlying base color for the material |
| 510 | public UInt64 albedoTextureID; ///< Texture id for the albedo map |
| 511 | public Vector4 albedoMultiplier; ///< Multiplier for albedo texture sample |
| 512 | public UInt64 metallicnessTextureID; ///< Texture id for the metal map |
| 513 | public float glossinessScale; ///< Glossiness factor |
| 514 | public UInt64 normalTextureID; ///< Texture id for the normal map |
| 515 | public UInt64 heightTextureID; ///< Texture id for the height map |
| 516 | public UInt64 occlusionTextureID; ///< Texture id for the occlusion map |
| 517 | public UInt64 emissionTextureID; ///< Texture id for the emission map |
| 518 | public Vector4 emissionMultiplier; ///< Multiplier for emission texture sample |
| 519 | public UInt64 detailMaskTextureID; ///< Texture id for the detail mask map |
| 520 | public UInt64 detailAlbedoTextureID; ///< Texture id for the detail albedo map |
| 521 | public UInt64 detailNormalTextureID; ///< Texture id for the detail normal map |
| 522 | static bool VectorEquals(Vector4 a, Vector4 b) |
| 523 | { |
| 524 | return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; |
| 525 | } |
| 526 | |
| 527 | public override bool Equals(object obj) |
| 528 | { |
| 529 | if (!(obj is ovrAvatarPBSMaterialState)) |
| 530 | { |
| 531 | return false; |
| 532 | } |
| 533 | ovrAvatarPBSMaterialState other = (ovrAvatarPBSMaterialState)obj; |
| 534 | if (!VectorEquals(baseColor, other.baseColor)) return false; |
| 535 | if (albedoTextureID != other.albedoTextureID) return false; |
| 536 | if (!VectorEquals(albedoMultiplier, other.albedoMultiplier)) return false; |
| 537 | if (metallicnessTextureID != other.metallicnessTextureID) return false; |
| 538 | if (glossinessScale != other.glossinessScale) return false; |
| 539 | if (normalTextureID != other.normalTextureID) return false; |
| 540 | if (heightTextureID != other.heightTextureID) return false; |
| 541 | if (occlusionTextureID != other.occlusionTextureID) return false; |
| 542 | if (emissionTextureID != other.emissionTextureID) return false; |
| 543 | if (!VectorEquals(emissionMultiplier, other.emissionMultiplier)) return false; |
| 544 | if (detailMaskTextureID != other.detailMaskTextureID) return false; |
| 545 | if (detailAlbedoTextureID != other.detailAlbedoTextureID) return false; |
| 546 | if (detailNormalTextureID != other.detailNormalTextureID) return false; |
| 547 | return true; |
| 548 | } |
| 549 | public override int GetHashCode() |
| 550 | { |
| 551 | return baseColor.GetHashCode() ^ |
| 552 | albedoTextureID.GetHashCode() ^ |
| 553 | albedoMultiplier.GetHashCode() ^ |
| 554 | metallicnessTextureID.GetHashCode() ^ |
| 555 | glossinessScale.GetHashCode() ^ |
| 556 | normalTextureID.GetHashCode() ^ |
| 557 | heightTextureID.GetHashCode() ^ |
| 558 | occlusionTextureID.GetHashCode() ^ |
| 559 | emissionTextureID.GetHashCode() ^ |
| 560 | emissionMultiplier.GetHashCode() ^ |
| 561 | detailMaskTextureID.GetHashCode() ^ |
| 562 | detailAlbedoTextureID.GetHashCode() ^ |
| 563 | detailNormalTextureID.GetHashCode(); |
| 564 | } |
| 565 | }; |
| 566 | |
| 567 | public class OvrAvatarAssetMaterial : OvrAvatarAsset |
| 568 | { |
| 569 | public OvrAvatarAssetMaterial(UInt64 id, IntPtr mat) |
| 570 | { |
| 571 | assetID = id; |
| 572 | material = CAPI.ovrAvatarAsset_GetMaterialState(mat); |
| 573 | } |
| 574 | |
| 575 | public ovrAvatarMaterialState material; |
| 576 | } |
| 577 | // This needs to be the csharp equivalent of ovrAvatarSkinnedMeshPose in OVR_Avatar.h |
| 578 | public struct ovrAvatarSkinnedMeshPose |
| 579 | { |
| 580 | public UInt32 jointCount; |
| 581 | |
| 582 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] |
| 583 | public ovrAvatarTransform[] jointTransform; |
| 584 | |
| 585 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] |
| 586 | public int[] jointParents; |
| 587 | |
| 588 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] |
| 589 | public IntPtr[] jointNames; //const char * jointNames[64]; |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | [Flags] |
| 594 | public enum ovrAvatarVisibilityFlags |
| 595 | { |
| 596 | FirstPerson = 1 << 0, |
| 597 | ThirdPerson = 1 << 1, |
| 598 | SelfOccluding = 1 << 2, |
| 599 | }; |
| 600 | |
| 601 | // This needs to be the csharp equivalent of ovrAvatarRenderPart_SkinnedMeshRender in OVR_Avatar.h |
| 602 | public struct ovrAvatarRenderPart_SkinnedMeshRender |
| 603 | { |
| 604 | public ovrAvatarTransform localTransform; |
| 605 | public ovrAvatarVisibilityFlags visibilityMask; |
| 606 | public UInt64 meshAssetID; |
| 607 | public ovrAvatarMaterialState materialState; |
| 608 | public ovrAvatarSkinnedMeshPose skinnedPose; |
| 609 | }; |
| 610 | |
| 611 | // This needs to be the csharp equivalent of ovrAvatarRenderPart_SkinnedMeshRenderPBS in OVR_Avatar.h |
| 612 | public struct ovrAvatarRenderPart_SkinnedMeshRenderPBS |
| 613 | { |
| 614 | public ovrAvatarTransform localTransform; |
| 615 | public ovrAvatarVisibilityFlags visibilityMask; |
| 616 | public UInt64 meshAssetID; |
| 617 | public UInt64 albedoTextureAssetID; |
| 618 | public UInt64 surfaceTextureAssetID; |
| 619 | public ovrAvatarSkinnedMeshPose skinnedPose; |
| 620 | }; |
| 621 | |
| 622 | // This needs to be the csharp equivalent of ovrAvatarRenderPart_ProjectorRender in OVR_Avatar.h |
| 623 | public struct ovrAvatarRenderPart_ProjectorRender |
| 624 | { |
| 625 | public ovrAvatarTransform localTransform; |
| 626 | public UInt32 componentIndex; |
| 627 | public UInt32 renderPartIndex; |
| 628 | public ovrAvatarMaterialState materialState; |
| 629 | }; |
| 630 | |
| 631 | // This needs to be the csharp equivalent of ovrAvatarRenderPart_SkinnedMeshRenderPBS_V2 in OVR_Avatar.h |
| 632 | public struct ovrAvatarRenderPart_SkinnedMeshRenderPBS_V2 |
| 633 | { |
| 634 | public ovrAvatarTransform localTransform; |
| 635 | public ovrAvatarVisibilityFlags visibilityMask; |
| 636 | public UInt64 meshAssetID; |
| 637 | public ovrAvatarPBSMaterialState materialState; |
| 638 | public ovrAvatarSkinnedMeshPose skinnedPose; |
| 639 | }; |
| 640 | |
| 641 | // This needs to be the csharp equivalent of ovrAvatarHandGesture in OVR_Avatar.h |
| 642 | public enum ovrAvatarHandGesture { |
| 643 | Default, |
| 644 | GripSphere, |
| 645 | GripCube, |
| 646 | Count |
| 647 | }; |
| 648 | |
| 649 | public enum ovrAvatarBodyPartType |
| 650 | { |
| 651 | Body, |
| 652 | Clothing, |
| 653 | Eyewear, |
| 654 | Hair, |
| 655 | Beard, |
| 656 | Count |
| 657 | }; |
| 658 | |
| 659 | // This needs to be the csharp equivalent of ovrAvatarBlendShapeParams in OVR_Avatar.h |
| 660 | public struct ovrAvatarBlendShapeParams |
| 661 | { |
| 662 | public UInt32 blendShapeParamCount; |
| 663 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] |
| 664 | public float[] blendShapeParams; |
| 665 | }; |
| 666 | |
| 667 | struct ovrAvatarBlendShapeParams_Offsets |
| 668 | { |
| 669 | public static Int32 blendShapeParamCount = Marshal.OffsetOf(typeof(ovrAvatarBlendShapeParams), "blendShapeParamCount").ToInt32(); |
| 670 | public static long blendShapeParams = Marshal.OffsetOf(typeof(ovrAvatarBlendShapeParams), "blendShapeParams").ToInt64(); |
| 671 | }; |
| 672 | |
| 673 | // This needs to be the csharp equivalent of ovrAvatarVisemes in OVR_Avatar.h |
| 674 | public struct ovrAvatarVisemes |
| 675 | { |
| 676 | public UInt32 visemeParamCount; |
| 677 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] |
| 678 | public float[] visemeParams; |
| 679 | }; |
| 680 | |
| 681 | struct ovrAvatarVisemes_Offsets |
| 682 | { |
| 683 | public static Int32 visemeParamCount = Marshal.OffsetOf(typeof(ovrAvatarVisemes), "visemeParamCount").ToInt32(); |
| 684 | public static long visemeParams = Marshal.OffsetOf(typeof(ovrAvatarVisemes), "visemeParams").ToInt64(); |
| 685 | }; |
| 686 | |
| 687 | // This needs to be the csharp equivalent of ovrAvatarGazeTargetType in OVR_AvatarInternal.h |
| 688 | public enum ovrAvatarGazeTargetType { |
| 689 | AvatarHead = 0, |
| 690 | AvatarHand, |
| 691 | Object, |
| 692 | ObjectStatic, |
| 693 | Count, |
| 694 | }; |
| 695 | |
| 696 | // This needs to be the csharp equivalent of ovrAvatarGazeTarget in OVR_AvatarInternal.h |
| 697 | public struct ovrAvatarGazeTarget |
| 698 | { |
| 699 | public UInt32 id; |
| 700 | public Vector3 worldPosition; |
| 701 | public ovrAvatarGazeTargetType type; |
| 702 | }; |
| 703 | |
| 704 | struct ovrAvatarGazeTarget_Offsets |
| 705 | { |
| 706 | public static Int32 id = Marshal.OffsetOf(typeof(ovrAvatarGazeTarget), "id").ToInt32(); |
| 707 | public static long worldPosition = Marshal.OffsetOf(typeof(ovrAvatarGazeTarget), "worldPosition").ToInt64(); |
| 708 | public static long type = Marshal.OffsetOf(typeof(ovrAvatarGazeTarget), "type").ToInt32(); |
| 709 | }; |
| 710 | |
| 711 | public struct ovrAvatarGazeTargets |
| 712 | { |
| 713 | public UInt32 targetCount; |
| 714 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] |
| 715 | public ovrAvatarGazeTarget[] targets; |
| 716 | }; |
| 717 | |
| 718 | struct ovrAvatarGazeTargets_Offsets |
| 719 | { |
| 720 | public static Int32 targetCount = Marshal.OffsetOf(typeof(ovrAvatarGazeTargets), "targetCount").ToInt32(); |
| 721 | public static long targets = Marshal.OffsetOf(typeof(ovrAvatarGazeTargets), "targets").ToInt64(); |
| 722 | }; |
| 723 | |
| 724 | // This needs to be the csharp equivalent of ovrAvatarLightType in OVR_AvatarInternal.h |
| 725 | public enum ovrAvatarLightType { |
| 726 | Point = 0, |
| 727 | Direction, |
| 728 | Spot, |
| 729 | Count, |
| 730 | }; |
| 731 | |
| 732 | // This needs to be the csharp equivalent of ovrAvatarLight in OVR_AvatarInternal.h |
| 733 | public struct ovrAvatarLight |
| 734 | { |
| 735 | public UInt32 id; |
| 736 | public ovrAvatarLightType type; |
| 737 | public float intensity; |
| 738 | public Vector3 worldDirection; |
| 739 | public Vector3 worldPosition; |
| 740 | public float range; |
| 741 | public float spotAngleDeg; |
| 742 | }; |
| 743 | |
| 744 | struct ovrAvatarLight_Offsets |
| 745 | { |
| 746 | public static long id = Marshal.OffsetOf(typeof(ovrAvatarLight), "id").ToInt64(); |
| 747 | public static long type = Marshal.OffsetOf(typeof(ovrAvatarLight), "type").ToInt64(); |
| 748 | public static long intensity = Marshal.OffsetOf(typeof(ovrAvatarLight), "intensity").ToInt64(); |
| 749 | public static long worldDirection = Marshal.OffsetOf(typeof(ovrAvatarLight), "worldDirection").ToInt64(); |
| 750 | public static long worldPosition = Marshal.OffsetOf(typeof(ovrAvatarLight), "worldPosition").ToInt64(); |
| 751 | public static long range = Marshal.OffsetOf(typeof(ovrAvatarLight), "range").ToInt64(); |
| 752 | public static long spotAngleDeg = Marshal.OffsetOf(typeof(ovrAvatarLight), "spotAngleDeg").ToInt64(); |
| 753 | }; |
| 754 | |
| 755 | public struct ovrAvatarLights |
| 756 | { |
| 757 | public float ambientIntensity; |
| 758 | public UInt32 lightCount; |
| 759 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] |
| 760 | public ovrAvatarLight[] lights; |
| 761 | }; |
| 762 | |
| 763 | struct ovrAvatarLights_Offsets |
| 764 | { |
| 765 | public static long ambientIntensity = Marshal.OffsetOf(typeof(ovrAvatarLights), "ambientIntensity").ToInt64(); |
| 766 | public static long lightCount = Marshal.OffsetOf(typeof(ovrAvatarLights), "lightCount").ToInt64(); |
| 767 | public static long lights = Marshal.OffsetOf(typeof(ovrAvatarLights), "lights").ToInt64(); |
| 768 | }; |
| 769 | |
| 770 | // Debug Render |
| 771 | [Flags] |
| 772 | public enum ovrAvatarDebugContext : uint |
| 773 | { |
| 774 | None = 0, |
| 775 | GazeTarget = 0x01, |
| 776 | Any = 0xffffffff |
| 777 | }; |
| 778 | |
| 779 | public struct ovrAvatarDebugLine |
| 780 | { |
| 781 | public Vector3 startPoint; |
| 782 | public Vector3 endPoint; |
| 783 | public Vector3 color; |
| 784 | public ovrAvatarDebugContext context; |
| 785 | public IntPtr text; |
| 786 | }; |
| 787 | public struct ovrAvatarDebugTransform |
| 788 | { |
| 789 | public ovrAvatarTransform transform; |
| 790 | public ovrAvatarDebugContext context; |
| 791 | public IntPtr text; |
| 792 | }; |
| 793 | |
| 794 | namespace Oculus.Avatar |
| 795 | { |
| 796 | public class CAPI |
| 797 | { |
| 798 | #if UNITY_ANDROID && !UNITY_EDITOR |
| 799 | #if AVATAR_XPLAT |
| 800 | private const string LibFile = "ovravatar"; |
| 801 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 802 | public static extern void ovrAvatar_Initialize(string appID); |
| 803 | #else |
| 804 | private const string LibFile = "ovravatarloader"; |
| 805 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 806 | public static extern void ovrAvatar_InitializeAndroidUnity(string appID); |
| 807 | #endif |
| 808 | #else |
| 809 | private const string LibFile = "libovravatar"; |
| 810 | |
| 811 | public static readonly System.Version AvatarSDKVersion = new System.Version(1, 36, 0); |
| 812 | |
| 813 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 814 | public static extern void ovrAvatar_Initialize(string appID); |
| 815 | #endif |
| 816 | |
| 817 | static IntPtr nativeVisemeData = IntPtr.Zero; |
| 818 | static IntPtr nativeGazeTargetsData = IntPtr.Zero; |
| 819 | static IntPtr nativeAvatarLightsData = IntPtr.Zero; |
| 820 | static IntPtr DebugLineCountData = IntPtr.Zero; |
| 821 | static float[] scratchBufferFloat = new float[16]; |
| 822 | static GameObject debugLineGo; |
| 823 | public static void Initialize() |
| 824 | { |
| 825 | nativeVisemeData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ovrAvatarVisemes))); |
| 826 | nativeGazeTargetsData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ovrAvatarGazeTargets))); |
| 827 | nativeAvatarLightsData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ovrAvatarLights))); |
| 828 | DebugLineCountData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(uint))); |
| 829 | |
| 830 | debugLineGo = new GameObject(); |
| 831 | debugLineGo.name = "AvatarSDKDebugDrawHelper"; |
| 832 | } |
| 833 | |
| 834 | public static void Shutdown() |
| 835 | { |
| 836 | Marshal.FreeHGlobal(nativeVisemeData); |
| 837 | Marshal.FreeHGlobal(nativeGazeTargetsData); |
| 838 | Marshal.FreeHGlobal(nativeAvatarLightsData); |
| 839 | Marshal.FreeHGlobal(DebugLineCountData); |
| 840 | |
| 841 | debugLineGo = null; |
| 842 | } |
| 843 | |
| 844 | |
| 845 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 846 | public static extern void ovrAvatar_Shutdown(); |
| 847 | |
| 848 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 849 | public static extern IntPtr ovrAvatarMessage_Pop(); |
| 850 | |
| 851 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 852 | public static extern ovrAvatarMessageType ovrAvatarMessage_GetType(IntPtr msg); |
| 853 | |
| 854 | public static ovrAvatarMessage_AvatarSpecification ovrAvatarMessage_GetAvatarSpecification( |
| 855 | IntPtr msg) |
| 856 | { |
| 857 | IntPtr ptr = ovrAvatarMessage_GetAvatarSpecification_Native(msg); |
| 858 | return (ovrAvatarMessage_AvatarSpecification)Marshal.PtrToStructure( |
| 859 | ptr, typeof(ovrAvatarMessage_AvatarSpecification)); |
| 860 | } |
| 861 | |
| 862 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 863 | "ovrAvatarMessage_GetAvatarSpecification")] |
| 864 | private static extern IntPtr ovrAvatarMessage_GetAvatarSpecification_Native(IntPtr msg); |
| 865 | |
| 866 | public static ovrAvatarMessage_AssetLoaded ovrAvatarMessage_GetAssetLoaded( |
| 867 | IntPtr msg) |
| 868 | { |
| 869 | IntPtr ptr = ovrAvatarMessage_GetAssetLoaded_Native(msg); |
| 870 | return (ovrAvatarMessage_AssetLoaded)Marshal.PtrToStructure( |
| 871 | ptr, typeof(ovrAvatarMessage_AssetLoaded)); |
| 872 | } |
| 873 | |
| 874 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 875 | "ovrAvatarMessage_GetAssetLoaded")] |
| 876 | private static extern IntPtr ovrAvatarMessage_GetAssetLoaded_Native(IntPtr msg); |
| 877 | |
| 878 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 879 | public static extern void ovrAvatarMessage_Free(IntPtr msg); |
| 880 | |
| 881 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 882 | public static extern IntPtr ovrAvatarSpecificationRequest_Create(UInt64 userID); |
| 883 | |
| 884 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 885 | public static extern void ovrAvatarSpecificationRequest_Destroy(IntPtr specificationRequest); |
| 886 | |
| 887 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 888 | public static extern void ovrAvatarSpecificationRequest_SetCombineMeshes(IntPtr specificationRequest, bool useCombinedMesh); |
| 889 | |
| 890 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 891 | public static extern void ovrAvatarSpecificationRequest_SetLookAndFeelVersion(IntPtr specificationRequest, ovrAvatarLookAndFeelVersion version); |
| 892 | |
| 893 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 894 | public static extern void ovrAvatarSpecificationRequest_SetLevelOfDetail(IntPtr specificationRequest, ovrAvatarAssetLevelOfDetail lod); |
| 895 | |
| 896 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 897 | public static extern void ovrAvatar_RequestAvatarSpecification(UInt64 userID); |
| 898 | |
| 899 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 900 | public static extern void ovrAvatar_RequestAvatarSpecificationFromSpecRequest(IntPtr specificationRequest); |
| 901 | |
| 902 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 903 | public static extern void ovrAvatarSpecificationRequest_SetFallbackLookAndFeelVersion(IntPtr specificationRequest, ovrAvatarLookAndFeelVersion version); |
| 904 | |
| 905 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 906 | public static extern void ovrAvatarSpecificationRequest_SetExpressiveFlag(IntPtr specificationRequest, bool enable); |
| 907 | |
| 908 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 909 | public static extern IntPtr ovrAvatar_Create(IntPtr avatarSpecification, |
| 910 | ovrAvatarCapabilities capabilities); |
| 911 | |
| 912 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 913 | public static extern void ovrAvatar_Destroy(IntPtr avatar); |
| 914 | |
| 915 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 916 | public static extern void ovrAvatarPose_UpdateBody( |
| 917 | IntPtr avatar, ovrAvatarTransform headPose); |
| 918 | |
| 919 | public static void ovrAvatarPose_UpdateVoiceVisualization( |
| 920 | IntPtr avatar, float[] pcmData) |
| 921 | { |
| 922 | ovrAvatarPose_UpdateVoiceVisualization_Native( |
| 923 | avatar, (UInt32)pcmData.Length, pcmData); |
| 924 | } |
| 925 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 926 | "ovrAvatarPose_UpdateVoiceVisualization")] |
| 927 | private static extern void ovrAvatarPose_UpdateVoiceVisualization_Native( |
| 928 | IntPtr avatar, UInt32 pcmDataSize, [In] float[] pcmData); |
| 929 | |
| 930 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 931 | public static extern void ovrAvatarPose_UpdateHands( |
| 932 | IntPtr avatar, |
| 933 | ovrAvatarHandInputState inputStateLeft, |
| 934 | ovrAvatarHandInputState inputStateRight); |
| 935 | |
| 936 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 937 | public static extern void ovrAvatarPose_UpdateHandsWithType( |
| 938 | IntPtr avatar, |
| 939 | ovrAvatarHandInputState inputStateLeft, |
| 940 | ovrAvatarHandInputState inputStateRight, |
| 941 | ovrAvatarControllerType type); |
| 942 | |
| 943 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 944 | public static extern void ovrAvatarPose_Finalize(IntPtr avatar, float elapsedSeconds); |
| 945 | |
| 946 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 947 | public static extern void ovrAvatar_SetLeftControllerVisibility(IntPtr avatar, bool show); |
| 948 | |
| 949 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 950 | public static extern void ovrAvatar_SetRightControllerVisibility(IntPtr avatar, bool show); |
| 951 | |
| 952 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 953 | public static extern void ovrAvatar_SetLeftHandVisibility(IntPtr avatar, bool show); |
| 954 | |
| 955 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 956 | public static extern void ovrAvatar_SetRightHandVisibility(IntPtr avatar, bool show); |
| 957 | |
| 958 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 959 | public static extern UInt32 ovrAvatarComponent_Count(IntPtr avatar); |
| 960 | |
| 961 | public static void ovrAvatarComponent_Get(IntPtr avatar, UInt32 index, bool includeName, ref ovrAvatarComponent component) |
| 962 | { |
| 963 | IntPtr ptr = ovrAvatarComponent_Get_Native(avatar, index); |
| 964 | ovrAvatarComponent_Get(ptr, includeName, ref component); |
| 965 | } |
| 966 | |
| 967 | public static void ovrAvatarComponent_Get(IntPtr componentPtr, bool includeName, ref ovrAvatarComponent component) |
| 968 | { |
| 969 | Marshal.Copy(new IntPtr(componentPtr.ToInt64() + ovrAvatarComponent_Offsets.transform), scratchBufferFloat, 0, 10); |
| 970 | OvrAvatar.ConvertTransform(scratchBufferFloat, ref component.transform); |
| 971 | |
| 972 | component.renderPartCount = (UInt32)Marshal.ReadInt32(componentPtr, ovrAvatarComponent_Offsets.renderPartCount); |
| 973 | component.renderParts = Marshal.ReadIntPtr(componentPtr, ovrAvatarComponent_Offsets.renderParts); |
| 974 | |
| 975 | if (includeName) |
| 976 | { |
| 977 | IntPtr namePtr = Marshal.ReadIntPtr(componentPtr, ovrAvatarComponent_Offsets.name); |
| 978 | component.name = Marshal.PtrToStringAnsi(namePtr); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 983 | "ovrAvatarComponent_Get")] |
| 984 | public static extern IntPtr ovrAvatarComponent_Get_Native(IntPtr avatar, UInt32 index); |
| 985 | |
| 986 | public static bool ovrAvatarPose_GetBaseComponent(IntPtr avatar, ref ovrAvatarBaseComponent component) |
| 987 | { |
| 988 | IntPtr ptr = ovrAvatarPose_GetBaseComponent_Native(avatar); |
| 989 | if (ptr == IntPtr.Zero) |
| 990 | { |
| 991 | return false; |
| 992 | } |
| 993 | |
| 994 | int renderComponentOffset = Marshal.SizeOf(typeof(ovrAvatarBaseComponent)) - Marshal.SizeOf(typeof(IntPtr)); |
| 995 | component.renderComponent = Marshal.ReadIntPtr(ptr, renderComponentOffset); |
| 996 | return true; |
| 997 | } |
| 998 | |
| 999 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint ="ovrAvatarPose_GetBaseComponent")] |
| 1000 | private static extern IntPtr ovrAvatarPose_GetBaseComponent_Native(IntPtr avatar); |
| 1001 | |
| 1002 | public static IntPtr MarshalRenderComponent<T>(IntPtr ptr) where T : struct |
| 1003 | { |
| 1004 | return Marshal.ReadIntPtr(new IntPtr(ptr.ToInt64() + Marshal.OffsetOf(typeof(T), "renderComponent").ToInt64())); |
| 1005 | } |
| 1006 | public static bool ovrAvatarPose_GetBodyComponent(IntPtr avatar, ref ovrAvatarBodyComponent component) |
| 1007 | { |
| 1008 | IntPtr ptr = ovrAvatarPose_GetBodyComponent_Native(avatar); |
| 1009 | |
| 1010 | if (ptr == IntPtr.Zero) |
| 1011 | { |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | Marshal.Copy(new IntPtr(ptr.ToInt64() + ovrAvatarBodyComponent_Offsets.leftEyeTransform), scratchBufferFloat, 0, 10); |
| 1016 | OvrAvatar.ConvertTransform(scratchBufferFloat, ref component.leftEyeTransform); |
| 1017 | |
| 1018 | Marshal.Copy(new IntPtr(ptr.ToInt64() + ovrAvatarBodyComponent_Offsets.rightEyeTransform), scratchBufferFloat, 0, 10); |
| 1019 | OvrAvatar.ConvertTransform(scratchBufferFloat, ref component.rightEyeTransform); |
| 1020 | |
| 1021 | Marshal.Copy(new IntPtr(ptr.ToInt64() + ovrAvatarBodyComponent_Offsets.centerEyeTransform), scratchBufferFloat, 0, 10); |
| 1022 | OvrAvatar.ConvertTransform(scratchBufferFloat, ref component.centerEyeTransform); |
| 1023 | |
| 1024 | component.renderComponent = MarshalRenderComponent<ovrAvatarBodyComponent>(ptr); |
| 1025 | return true; |
| 1026 | } |
| 1027 | |
| 1028 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint ="ovrAvatarPose_GetBodyComponent")] |
| 1029 | private static extern IntPtr ovrAvatarPose_GetBodyComponent_Native(IntPtr avatar); |
| 1030 | |
| 1031 | public static bool ovrAvatarPose_GetLeftControllerComponent(IntPtr avatar, ref ovrAvatarControllerComponent component) |
| 1032 | { |
| 1033 | IntPtr ptr = ovrAvatarPose_GetLeftControllerComponent_Native(avatar); |
| 1034 | if (ptr == IntPtr.Zero) |
| 1035 | { |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | int renderComponentOffset = Marshal.SizeOf(typeof(ovrAvatarControllerComponent)) - Marshal.SizeOf(typeof(IntPtr)); |
| 1040 | component.renderComponent = Marshal.ReadIntPtr(ptr, renderComponentOffset); |
| 1041 | return true; |
| 1042 | } |
| 1043 | |
| 1044 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1045 | "ovrAvatarPose_GetLeftControllerComponent")] |
| 1046 | private static extern IntPtr ovrAvatarPose_GetLeftControllerComponent_Native(IntPtr avatar); |
| 1047 | |
| 1048 | public static bool ovrAvatarPose_GetRightControllerComponent(IntPtr avatar, ref ovrAvatarControllerComponent component) |
| 1049 | { |
| 1050 | IntPtr ptr = ovrAvatarPose_GetRightControllerComponent_Native(avatar); |
| 1051 | |
| 1052 | if (ptr == IntPtr.Zero) |
| 1053 | { |
| 1054 | return false; |
| 1055 | } |
| 1056 | |
| 1057 | int renderComponentOffset = Marshal.SizeOf(typeof(ovrAvatarControllerComponent)) - Marshal.SizeOf(typeof(IntPtr)); |
| 1058 | component.renderComponent = Marshal.ReadIntPtr(ptr, renderComponentOffset); |
| 1059 | return true; |
| 1060 | } |
| 1061 | |
| 1062 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1063 | "ovrAvatarPose_GetRightControllerComponent")] |
| 1064 | private static extern IntPtr ovrAvatarPose_GetRightControllerComponent_Native(IntPtr avatar); |
| 1065 | |
| 1066 | public static bool ovrAvatarPose_GetLeftHandComponent(IntPtr avatar, ref ovrAvatarHandComponent component) |
| 1067 | { |
| 1068 | IntPtr ptr = ovrAvatarPose_GetLeftHandComponent_Native(avatar); |
| 1069 | if (ptr == IntPtr.Zero) |
| 1070 | { |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | int renderComponentOffset = Marshal.SizeOf(typeof(ovrAvatarHandComponent)) - Marshal.SizeOf(typeof(IntPtr)); |
| 1075 | component.renderComponent = Marshal.ReadIntPtr(ptr, renderComponentOffset); |
| 1076 | return true; |
| 1077 | } |
| 1078 | |
| 1079 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1080 | "ovrAvatarPose_GetLeftHandComponent")] |
| 1081 | private static extern IntPtr ovrAvatarPose_GetLeftHandComponent_Native(IntPtr avatar); |
| 1082 | |
| 1083 | public static bool ovrAvatarPose_GetRightHandComponent(IntPtr avatar, ref ovrAvatarHandComponent component) |
| 1084 | { |
| 1085 | IntPtr ptr = ovrAvatarPose_GetRightHandComponent_Native(avatar); |
| 1086 | if (ptr == IntPtr.Zero) |
| 1087 | { |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | int renderComponentOffset = Marshal.SizeOf(typeof(ovrAvatarHandComponent)) - Marshal.SizeOf(typeof(IntPtr)); |
| 1092 | component.renderComponent = Marshal.ReadIntPtr(ptr, renderComponentOffset); |
| 1093 | return true; |
| 1094 | } |
| 1095 | |
| 1096 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1097 | "ovrAvatarPose_GetRightHandComponent")] |
| 1098 | private static extern IntPtr ovrAvatarPose_GetRightHandComponent_Native(IntPtr avatar); |
| 1099 | |
| 1100 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1101 | public static extern void ovrAvatarAsset_BeginLoading(UInt64 assetID); |
| 1102 | |
| 1103 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1104 | public static extern bool ovrAvatarAsset_BeginLoadingLOD(UInt64 assetId, ovrAvatarAssetLevelOfDetail lod); |
| 1105 | |
| 1106 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1107 | public static extern ovrAvatarAssetType ovrAvatarAsset_GetType(IntPtr assetHandle); |
| 1108 | |
| 1109 | public static ovrAvatarMeshAssetData ovrAvatarAsset_GetMeshData( |
| 1110 | IntPtr assetPtr) |
| 1111 | { |
| 1112 | IntPtr ptr = ovrAvatarAsset_GetMeshData_Native(assetPtr); |
| 1113 | return (ovrAvatarMeshAssetData)Marshal.PtrToStructure( |
| 1114 | ptr, typeof(ovrAvatarMeshAssetData)); |
| 1115 | } |
| 1116 | |
| 1117 | public static ovrAvatarMeshAssetDataV2 ovrAvatarAsset_GetCombinedMeshData( |
| 1118 | IntPtr assetPtr) |
| 1119 | { |
| 1120 | IntPtr ptr = ovrAvatarAsset_GetCombinedMeshData_Native(assetPtr); |
| 1121 | return (ovrAvatarMeshAssetDataV2)Marshal.PtrToStructure( |
| 1122 | ptr, typeof(ovrAvatarMeshAssetDataV2)); |
| 1123 | } |
| 1124 | |
| 1125 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarAsset_GetCombinedMeshData")] |
| 1126 | private static extern IntPtr ovrAvatarAsset_GetCombinedMeshData_Native(IntPtr assetPtr); |
| 1127 | |
| 1128 | |
| 1129 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarAsset_GetMeshData")] |
| 1130 | private static extern IntPtr ovrAvatarAsset_GetMeshData_Native(IntPtr assetPtr); |
| 1131 | |
| 1132 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1133 | public static extern UInt32 ovrAvatarAsset_GetMeshBlendShapeCount(IntPtr assetPtr); |
| 1134 | |
| 1135 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1136 | public static extern IntPtr ovrAvatarAsset_GetMeshBlendShapeName(IntPtr assetPtr, UInt32 index); |
| 1137 | |
| 1138 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1139 | public static extern UInt32 ovrAvatarAsset_GetSubmeshCount(IntPtr assetPtr); |
| 1140 | |
| 1141 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1142 | public static extern UInt32 ovrAvatarAsset_GetSubmeshLastIndex(IntPtr assetPtr, UInt32 index); |
| 1143 | |
| 1144 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1145 | public static extern IntPtr ovrAvatarAsset_GetMeshBlendShapeVertices(IntPtr assetPtr); |
| 1146 | |
| 1147 | |
| 1148 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1149 | public static extern IntPtr ovrAvatarAsset_GetAvatar(IntPtr assetHandle); |
| 1150 | |
| 1151 | public static UInt64[] ovrAvatarAsset_GetCombinedMeshIDs(IntPtr assetHandle) |
| 1152 | { |
| 1153 | UInt32 count = 0; |
| 1154 | System.IntPtr countPtr = Marshal.AllocHGlobal(Marshal.SizeOf(count)); |
| 1155 | IntPtr idBuffer = ovrAvatarAsset_GetCombinedMeshIDs_Native(assetHandle, countPtr); |
| 1156 | count = (UInt32)Marshal.PtrToStructure(countPtr, typeof(UInt32)); |
| 1157 | UInt64[] meshIDs = new UInt64[count]; |
| 1158 | |
| 1159 | for (int i = 0; i < count; i++) |
| 1160 | { |
| 1161 | meshIDs[i] = (UInt64)Marshal.ReadInt64(idBuffer, i * Marshal.SizeOf(typeof(UInt64))); |
| 1162 | } |
| 1163 | |
| 1164 | Marshal.FreeHGlobal(countPtr); |
| 1165 | |
| 1166 | return meshIDs; |
| 1167 | } |
| 1168 | |
| 1169 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarAsset_GetCombinedMeshIDs")] |
| 1170 | public static extern IntPtr ovrAvatarAsset_GetCombinedMeshIDs_Native(IntPtr assetHandle, IntPtr count); |
| 1171 | |
| 1172 | public static void ovrAvatar_GetCombinedMeshAlphaData(IntPtr avatar, ref UInt64 textureID, ref Vector4 offset) |
| 1173 | { |
| 1174 | System.IntPtr textureIDPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UInt64))); |
| 1175 | System.IntPtr offsetPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Vector4))); |
| 1176 | |
| 1177 | ovrAvatar_GetCombinedMeshAlphaData_Native(avatar, textureIDPtr, offsetPtr); |
| 1178 | |
| 1179 | textureID = (UInt64)Marshal.PtrToStructure(textureIDPtr, typeof(UInt64)); |
| 1180 | offset = (Vector4)Marshal.PtrToStructure(offsetPtr, typeof(Vector4)); |
| 1181 | |
| 1182 | Marshal.FreeHGlobal(textureIDPtr); |
| 1183 | Marshal.FreeHGlobal(offsetPtr); |
| 1184 | } |
| 1185 | |
| 1186 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_GetCombinedMeshAlphaData")] |
| 1187 | public static extern IntPtr ovrAvatar_GetCombinedMeshAlphaData_Native(IntPtr avatar, IntPtr textureIDPtr, IntPtr offsetPtr); |
| 1188 | |
| 1189 | public static ovrAvatarTextureAssetData ovrAvatarAsset_GetTextureData( |
| 1190 | IntPtr assetPtr) |
| 1191 | { |
| 1192 | IntPtr ptr = ovrAvatarAsset_GetTextureData_Native(assetPtr); |
| 1193 | return (ovrAvatarTextureAssetData)Marshal.PtrToStructure( |
| 1194 | ptr, typeof(ovrAvatarTextureAssetData)); |
| 1195 | } |
| 1196 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1197 | "ovrAvatarAsset_GetTextureData")] |
| 1198 | private static extern IntPtr ovrAvatarAsset_GetTextureData_Native(IntPtr assetPtr); |
| 1199 | |
| 1200 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = |
| 1201 | "ovrAvatarAsset_GetMaterialData")] |
| 1202 | private static extern IntPtr ovrAvatarAsset_GetMaterialData_Native(IntPtr assetPtr); |
| 1203 | public static ovrAvatarMaterialState ovrAvatarAsset_GetMaterialState(IntPtr assetPtr) |
| 1204 | { |
| 1205 | IntPtr ptr = ovrAvatarAsset_GetMaterialData_Native(assetPtr); |
| 1206 | return (ovrAvatarMaterialState)Marshal.PtrToStructure(ptr, typeof(ovrAvatarMaterialState)); |
| 1207 | } |
| 1208 | |
| 1209 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1210 | public static extern ovrAvatarRenderPartType ovrAvatarRenderPart_GetType(IntPtr renderPart); |
| 1211 | |
| 1212 | public static ovrAvatarRenderPart_SkinnedMeshRender ovrAvatarRenderPart_GetSkinnedMeshRender(IntPtr renderPart) |
| 1213 | { |
| 1214 | IntPtr ptr = ovrAvatarRenderPart_GetSkinnedMeshRender_Native(renderPart); |
| 1215 | return (ovrAvatarRenderPart_SkinnedMeshRender)Marshal.PtrToStructure( |
| 1216 | ptr, typeof(ovrAvatarRenderPart_SkinnedMeshRender)); |
| 1217 | } |
| 1218 | |
| 1219 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarRenderPart_GetSkinnedMeshRender")] |
| 1220 | private static extern IntPtr ovrAvatarRenderPart_GetSkinnedMeshRender_Native(IntPtr renderPart); |
| 1221 | |
| 1222 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1223 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRender_GetTransform(IntPtr renderPart); |
| 1224 | |
| 1225 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1226 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRenderPBS_GetTransform(IntPtr renderPart); |
| 1227 | |
| 1228 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1229 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRenderPBSV2_GetTransform(IntPtr renderPart); |
| 1230 | |
| 1231 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1232 | public static extern ovrAvatarVisibilityFlags ovrAvatarSkinnedMeshRender_GetVisibilityMask(IntPtr renderPart); |
| 1233 | |
| 1234 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1235 | public static extern bool ovrAvatarSkinnedMeshRender_MaterialStateChanged(IntPtr renderPart); |
| 1236 | |
| 1237 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1238 | public static extern bool ovrAvatarSkinnedMeshRenderPBSV2_MaterialStateChanged(IntPtr renderPart); |
| 1239 | |
| 1240 | |
| 1241 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1242 | public static extern ovrAvatarVisibilityFlags ovrAvatarSkinnedMeshRenderPBS_GetVisibilityMask(IntPtr renderPart); |
| 1243 | |
| 1244 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1245 | public static extern ovrAvatarVisibilityFlags ovrAvatarSkinnedMeshRenderPBSV2_GetVisibilityMask(IntPtr renderPart); |
| 1246 | |
| 1247 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1248 | public static extern ovrAvatarMaterialState ovrAvatarSkinnedMeshRender_GetMaterialState(IntPtr renderPart); |
| 1249 | |
| 1250 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1251 | public static extern ovrAvatarPBSMaterialState ovrAvatarSkinnedMeshRenderPBSV2_GetPBSMaterialState(IntPtr renderPart); |
| 1252 | |
| 1253 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1254 | public static extern ovrAvatarExpressiveParameters ovrAvatar_GetExpressiveParameters(IntPtr avatar); |
| 1255 | |
| 1256 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1257 | public static extern UInt64 ovrAvatarSkinnedMeshRender_GetDirtyJoints(IntPtr renderPart); |
| 1258 | |
| 1259 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1260 | public static extern UInt64 ovrAvatarSkinnedMeshRenderPBS_GetDirtyJoints(IntPtr renderPart); |
| 1261 | |
| 1262 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1263 | public static extern UInt64 ovrAvatarSkinnedMeshRenderPBSV2_GetDirtyJoints(IntPtr renderPart); |
| 1264 | |
| 1265 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1266 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRender_GetJointTransform(IntPtr renderPart, UInt32 jointIndex); |
| 1267 | |
| 1268 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1269 | public static extern void ovrAvatar_SetActionUnitOnsetSpeed(IntPtr avatar, float onsetSpeed); |
| 1270 | |
| 1271 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1272 | public static extern void ovrAvatar_SetActionUnitFalloffSpeed(IntPtr avatar, float falloffSpeed); |
| 1273 | |
| 1274 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1275 | public static extern void ovrAvatar_SetVisemeMultiplier(IntPtr avatar, float visemeMultiplier); |
| 1276 | |
| 1277 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1278 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRenderPBS_GetJointTransform(IntPtr renderPart, UInt32 jointIndex); |
| 1279 | |
| 1280 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1281 | public static extern ovrAvatarTransform ovrAvatarSkinnedMeshRenderPBSV2_GetJointTransform(IntPtr renderPart, UInt32 jointIndex); |
| 1282 | |
| 1283 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1284 | public static extern UInt64 ovrAvatarSkinnedMeshRenderPBS_GetAlbedoTextureAssetID(IntPtr renderPart); |
| 1285 | |
| 1286 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1287 | public static extern UInt64 ovrAvatarSkinnedMeshRenderPBS_GetSurfaceTextureAssetID(IntPtr renderPart); |
| 1288 | |
| 1289 | public static ovrAvatarRenderPart_SkinnedMeshRenderPBS ovrAvatarRenderPart_GetSkinnedMeshRenderPBS(IntPtr renderPart) |
| 1290 | { |
| 1291 | IntPtr ptr = ovrAvatarRenderPart_GetSkinnedMeshRenderPBS_Native(renderPart); |
| 1292 | return (ovrAvatarRenderPart_SkinnedMeshRenderPBS)Marshal.PtrToStructure( |
| 1293 | ptr, typeof(ovrAvatarRenderPart_SkinnedMeshRenderPBS)); |
| 1294 | } |
| 1295 | |
| 1296 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarRenderPart_GetSkinnedMeshRenderPBS")] |
| 1297 | private static extern IntPtr ovrAvatarRenderPart_GetSkinnedMeshRenderPBS_Native(IntPtr renderPart); |
| 1298 | |
| 1299 | public static ovrAvatarRenderPart_SkinnedMeshRenderPBS_V2 ovrAvatarRenderPart_GetSkinnedMeshRenderPBSV2(IntPtr renderPart) |
| 1300 | { |
| 1301 | IntPtr ptr = ovrAvatarRenderPart_GetSkinnedMeshRenderPBSV2_Native(renderPart); |
| 1302 | return (ovrAvatarRenderPart_SkinnedMeshRenderPBS_V2)Marshal.PtrToStructure( |
| 1303 | ptr, typeof(ovrAvatarRenderPart_SkinnedMeshRenderPBS_V2)); |
| 1304 | } |
| 1305 | |
| 1306 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarRenderPart_GetSkinnedMeshRenderPBSV2")] |
| 1307 | private static extern IntPtr ovrAvatarRenderPart_GetSkinnedMeshRenderPBSV2_Native(IntPtr renderPart); |
| 1308 | |
| 1309 | public static void ovrAvatarSkinnedMeshRender_GetBlendShapeParams(IntPtr renderPart, ref ovrAvatarBlendShapeParams blendParams) |
| 1310 | { |
| 1311 | IntPtr ptr = ovrAvatarSkinnedMeshRender_GetBlendShapeParams_Native(renderPart); |
| 1312 | blendParams.blendShapeParamCount = (UInt32)Marshal.ReadInt32(ptr); |
| 1313 | Marshal.Copy(new IntPtr(ptr.ToInt64() + ovrAvatarBlendShapeParams_Offsets.blendShapeParams), blendParams.blendShapeParams, 0, (int)blendParams.blendShapeParamCount); |
| 1314 | } |
| 1315 | |
| 1316 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarSkinnedMeshRender_GetBlendShapeParams")] |
| 1317 | private static extern IntPtr ovrAvatarSkinnedMeshRender_GetBlendShapeParams_Native(IntPtr renderPart); |
| 1318 | |
| 1319 | public static ovrAvatarRenderPart_ProjectorRender ovrAvatarRenderPart_GetProjectorRender(IntPtr renderPart) |
| 1320 | { |
| 1321 | IntPtr ptr = ovrAvatarRenderPart_GetProjectorRender_Native(renderPart); |
| 1322 | return (ovrAvatarRenderPart_ProjectorRender)Marshal.PtrToStructure( |
| 1323 | ptr, typeof(ovrAvatarRenderPart_ProjectorRender)); |
| 1324 | } |
| 1325 | |
| 1326 | public static ovrAvatarPBSMaterialState[] ovrAvatar_GetBodyPBSMaterialStates(IntPtr renderPart) |
| 1327 | { |
| 1328 | System.IntPtr countPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UInt32))); |
| 1329 | IntPtr ptrState = ovrAvatar_GetBodyPBSMaterialStates_Native(renderPart, countPtr); |
| 1330 | UInt32 count = (UInt32)Marshal.ReadInt32(countPtr); |
| 1331 | |
| 1332 | ovrAvatarPBSMaterialState[] states = new ovrAvatarPBSMaterialState[count]; |
| 1333 | |
| 1334 | for (int i = 0; i < states.Length; i++) |
| 1335 | { |
| 1336 | IntPtr nextItem = new IntPtr(ptrState.ToInt64() + i * Marshal.SizeOf(typeof(ovrAvatarPBSMaterialState))); |
| 1337 | states[i] = (ovrAvatarPBSMaterialState)Marshal.PtrToStructure(nextItem, typeof(ovrAvatarPBSMaterialState)); |
| 1338 | } |
| 1339 | |
| 1340 | Marshal.FreeHGlobal(countPtr); |
| 1341 | |
| 1342 | return states; |
| 1343 | } |
| 1344 | |
| 1345 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_GetBodyPBSMaterialStates")] |
| 1346 | private static extern IntPtr ovrAvatar_GetBodyPBSMaterialStates_Native(IntPtr avatar, IntPtr count); |
| 1347 | |
| 1348 | |
| 1349 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatarRenderPart_GetProjectorRender")] |
| 1350 | private static extern IntPtr ovrAvatarRenderPart_GetProjectorRender_Native(IntPtr renderPart); |
| 1351 | |
| 1352 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1353 | public static extern UInt32 ovrAvatar_GetReferencedAssetCount(IntPtr avatar); |
| 1354 | |
| 1355 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1356 | public static extern UInt64 ovrAvatar_GetReferencedAsset(IntPtr avatar, UInt32 index); |
| 1357 | |
| 1358 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1359 | public static extern void ovrAvatar_SetLeftHandGesture(IntPtr avatar, ovrAvatarHandGesture gesture); |
| 1360 | |
| 1361 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1362 | public static extern void ovrAvatar_SetRightHandGesture(IntPtr avatar, ovrAvatarHandGesture gesture); |
| 1363 | |
| 1364 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1365 | public static extern void ovrAvatar_SetLeftHandCustomGesture(IntPtr avatar, UInt32 jointCount, [In] ovrAvatarTransform[] customJointTransforms); |
| 1366 | |
| 1367 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1368 | public static extern void ovrAvatar_SetRightHandCustomGesture(IntPtr avatar, UInt32 jointCount, [In] ovrAvatarTransform[] customJointTransforms); |
| 1369 | |
| 1370 | //Native calls for efficient packet updates |
| 1371 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1372 | public static extern void ovrAvatar_UpdatePoseFromPacket(IntPtr avatar, IntPtr packet, float secondsFromStart); |
| 1373 | |
| 1374 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1375 | public static extern void ovrAvatarPacket_BeginRecording(IntPtr avatar); |
| 1376 | |
| 1377 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1378 | public static extern IntPtr ovrAvatarPacket_EndRecording(IntPtr avatar); |
| 1379 | |
| 1380 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1381 | public static extern UInt32 ovrAvatarPacket_GetSize(IntPtr packet); |
| 1382 | |
| 1383 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1384 | public static extern float ovrAvatarPacket_GetDurationSeconds(IntPtr packet); |
| 1385 | |
| 1386 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1387 | public static extern void ovrAvatarPacket_Free(IntPtr packet); |
| 1388 | |
| 1389 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1390 | public static extern bool ovrAvatarPacket_Write(IntPtr packet, UInt32 bufferSize, [Out] byte[] buffer); |
| 1391 | |
| 1392 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1393 | public static extern IntPtr ovrAvatarPacket_Read(UInt32 bufferSize, [In] byte[] buffer); |
| 1394 | |
| 1395 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1396 | private static extern void ovrAvatar_SetInternalForceASTCTextures(bool value); |
| 1397 | |
| 1398 | // Renaming the outward facing method to remove Internal from name |
| 1399 | public static void ovrAvatar_SetForceASTCTextures(bool value) |
| 1400 | { |
| 1401 | ovrAvatar_SetInternalForceASTCTextures(value); |
| 1402 | } |
| 1403 | |
| 1404 | public static void ovrAvatar_OverrideExpressiveLogic(IntPtr avatar, ovrAvatarBlendShapeParams blendParams) |
| 1405 | { |
| 1406 | IntPtr statePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ovrAvatarBlendShapeParams))); |
| 1407 | Marshal.StructureToPtr(blendParams, statePtr, false); |
| 1408 | ovrAvatar_OverrideExpressiveLogic_Native(avatar, statePtr); |
| 1409 | Marshal.FreeHGlobal(statePtr); |
| 1410 | } |
| 1411 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_OverrideExpressiveLogic")] |
| 1412 | private static extern void ovrAvatar_OverrideExpressiveLogic_Native(IntPtr avatar, IntPtr state); |
| 1413 | |
| 1414 | public static void ovrAvatar_SetVisemes(IntPtr avatar, ovrAvatarVisemes visemes) |
| 1415 | { |
| 1416 | Marshal.WriteInt32(nativeVisemeData, (Int32)visemes.visemeParamCount); |
| 1417 | Marshal.Copy(visemes.visemeParams, 0, new IntPtr(nativeVisemeData.ToInt64() + ovrAvatarVisemes_Offsets.visemeParams), (int)visemes.visemeParamCount); |
| 1418 | |
| 1419 | ovrAvatar_SetVisemes_Native(avatar, nativeVisemeData); |
| 1420 | } |
| 1421 | |
| 1422 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_SetVisemes")] |
| 1423 | private static extern void ovrAvatar_SetVisemes_Native(IntPtr avatar, IntPtr visemes); |
| 1424 | |
| 1425 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1426 | public static extern void ovrAvatar_UpdateWorldTransform(IntPtr avatar, ovrAvatarTransform transform); |
| 1427 | |
| 1428 | |
| 1429 | public static void ovrAvatar_UpdateGazeTargets(ovrAvatarGazeTargets targets) |
| 1430 | { |
| 1431 | Marshal.WriteInt32(nativeGazeTargetsData, (Int32)targets.targetCount); |
| 1432 | |
| 1433 | var targetOffset = ovrAvatarGazeTargets_Offsets.targets; |
| 1434 | for (uint index = 0; index < targets.targetCount; index++) |
| 1435 | { |
| 1436 | var baseOffset = targetOffset + index * Marshal.SizeOf(typeof(ovrAvatarGazeTarget)); |
| 1437 | |
| 1438 | Marshal.WriteInt32(new IntPtr(nativeGazeTargetsData.ToInt64() + baseOffset + ovrAvatarGazeTarget_Offsets.id), (int)targets.targets[index].id); |
| 1439 | |
| 1440 | scratchBufferFloat[0] = targets.targets[index].worldPosition.x; |
| 1441 | scratchBufferFloat[1] = targets.targets[index].worldPosition.y; |
| 1442 | scratchBufferFloat[2] = targets.targets[index].worldPosition.z; |
| 1443 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeGazeTargetsData.ToInt64() + baseOffset + ovrAvatarGazeTarget_Offsets.worldPosition), 3); |
| 1444 | |
| 1445 | Marshal.WriteInt32(new IntPtr(nativeGazeTargetsData.ToInt64() + baseOffset + ovrAvatarGazeTarget_Offsets.type), (int)targets.targets[index].type); |
| 1446 | } |
| 1447 | |
| 1448 | ovrAvatar_UpdateGazeTargets_Native(nativeGazeTargetsData); |
| 1449 | } |
| 1450 | |
| 1451 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_UpdateGazeTargets")] |
| 1452 | private static extern void ovrAvatar_UpdateGazeTargets_Native(IntPtr targets); |
| 1453 | |
| 1454 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1455 | public static extern void ovrAvatar_RemoveGazeTargets(UInt32 targetCount, UInt32[] ids); |
| 1456 | |
| 1457 | public static void ovrAvatar_UpdateLights(ovrAvatarLights lights) |
| 1458 | { |
| 1459 | scratchBufferFloat[0] = lights.ambientIntensity; |
| 1460 | Marshal.Copy(scratchBufferFloat, 0, nativeAvatarLightsData, 1); |
| 1461 | |
| 1462 | Marshal.WriteInt32(new IntPtr(nativeAvatarLightsData.ToInt64() + Marshal.OffsetOf(typeof(ovrAvatarLights), "lightCount").ToInt64()), (int)lights.lightCount); |
| 1463 | |
| 1464 | var lightsOffset = Marshal.OffsetOf(typeof(ovrAvatarLights), "lights").ToInt64(); |
| 1465 | for (uint index = 0; index < lights.lightCount; index++) |
| 1466 | { |
| 1467 | var baseOffset = lightsOffset + index * Marshal.SizeOf(typeof(ovrAvatarLight)); |
| 1468 | |
| 1469 | Marshal.WriteInt32(new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "id").ToInt64()), (int)lights.lights[index].id); |
| 1470 | Marshal.WriteInt32(new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "type").ToInt64()), (int)lights.lights[index].type); |
| 1471 | |
| 1472 | scratchBufferFloat[0] = lights.lights[index].intensity; |
| 1473 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "intensity").ToInt64()), 1); |
| 1474 | |
| 1475 | scratchBufferFloat[0] = lights.lights[index].worldDirection.x; |
| 1476 | scratchBufferFloat[1] = lights.lights[index].worldDirection.y; |
| 1477 | scratchBufferFloat[2] = lights.lights[index].worldDirection.z; |
| 1478 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "worldDirection").ToInt64()), 3); |
| 1479 | |
| 1480 | scratchBufferFloat[0] = lights.lights[index].worldPosition.x; |
| 1481 | scratchBufferFloat[1] = lights.lights[index].worldPosition.y; |
| 1482 | scratchBufferFloat[2] = lights.lights[index].worldPosition.z; |
| 1483 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "worldPosition").ToInt64()), 3); |
| 1484 | |
| 1485 | scratchBufferFloat[0] = lights.lights[index].range; |
| 1486 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "range").ToInt64()), 1); |
| 1487 | |
| 1488 | scratchBufferFloat[0] = lights.lights[index].spotAngleDeg; |
| 1489 | Marshal.Copy(scratchBufferFloat, 0, new IntPtr(nativeAvatarLightsData.ToInt64() + baseOffset + Marshal.OffsetOf(typeof(ovrAvatarLight), "spotAngleDeg").ToInt64()), 1); |
| 1490 | } |
| 1491 | |
| 1492 | ovrAvatar_UpdateLights_Native(nativeAvatarLightsData); |
| 1493 | } |
| 1494 | |
| 1495 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_UpdateLights")] |
| 1496 | private static extern void ovrAvatar_UpdateLights_Native(IntPtr lights); |
| 1497 | |
| 1498 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1499 | public static extern void ovrAvatar_RemoveLights(UInt32 lightCount, UInt32[] ids); |
| 1500 | |
| 1501 | private static string SDKRuntimePrefix = "[RUNTIME] - "; |
| 1502 | public delegate void LoggingDelegate(IntPtr str); |
| 1503 | |
| 1504 | [MonoPInvokeCallback(typeof(LoggingDelegate))] |
| 1505 | public static void LoggingCallback(IntPtr str) |
| 1506 | { |
| 1507 | string csharpStr = Marshal.PtrToStringAnsi(str); |
| 1508 | AvatarLogger.Log(SDKRuntimePrefix + csharpStr); |
| 1509 | } |
| 1510 | |
| 1511 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1512 | public static extern void ovrAvatar_RegisterLoggingCallback(LoggingDelegate callback); |
| 1513 | |
| 1514 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1515 | public static extern void ovrAvatar_SetLoggingLevel(ovrAvatarLogLevel level); |
| 1516 | |
| 1517 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_GetDebugTransforms")] |
| 1518 | public static extern IntPtr ovrAvatar_GetDebugTransforms_Native(IntPtr count); |
| 1519 | |
| 1520 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrAvatar_GetDebugLines")] |
| 1521 | public static extern IntPtr ovrAvatar_GetDebugLines_Native(IntPtr count); |
| 1522 | |
| 1523 | public static void ovrAvatar_DrawDebugLines() |
| 1524 | { |
| 1525 | IntPtr debugLinePtr = ovrAvatar_GetDebugLines_Native(DebugLineCountData); |
| 1526 | int lineCount = Marshal.ReadInt32(DebugLineCountData); |
| 1527 | |
| 1528 | ovrAvatarDebugLine tempLine = new ovrAvatarDebugLine(); |
| 1529 | for (int i = 0; i < lineCount; i++) |
| 1530 | { |
| 1531 | var offset = i * Marshal.SizeOf(typeof(ovrAvatarDebugLine)); |
| 1532 | Marshal.Copy(new IntPtr(debugLinePtr.ToInt64() + offset), scratchBufferFloat, 0, 9); |
| 1533 | tempLine.startPoint.x = scratchBufferFloat[0]; |
| 1534 | tempLine.startPoint.y = scratchBufferFloat[1]; |
| 1535 | tempLine.startPoint.z = -scratchBufferFloat[2]; |
| 1536 | |
| 1537 | tempLine.endPoint.x = scratchBufferFloat[3]; |
| 1538 | tempLine.endPoint.y = scratchBufferFloat[4]; |
| 1539 | tempLine.endPoint.z = -scratchBufferFloat[5]; |
| 1540 | |
| 1541 | tempLine.color.x = scratchBufferFloat[6]; |
| 1542 | tempLine.color.y = scratchBufferFloat[7]; |
| 1543 | tempLine.color.z = scratchBufferFloat[8]; |
| 1544 | |
| 1545 | tempLine.context = (ovrAvatarDebugContext)Marshal.ReadInt32(new IntPtr(debugLinePtr.ToInt64() + offset + Marshal.OffsetOf(typeof(ovrAvatarDebugLine), "context").ToInt64())); |
| 1546 | tempLine.text = Marshal.ReadIntPtr(new IntPtr(debugLinePtr.ToInt64() + offset + Marshal.OffsetOf(typeof(ovrAvatarDebugLine), "text").ToInt64())); |
| 1547 | |
| 1548 | Debug.DrawLine(tempLine.startPoint, tempLine.endPoint, new Color(tempLine.color.x, tempLine.color.y, tempLine.color.z)); |
| 1549 | |
| 1550 | // TODO: Decide what to do with the text. Can only debug render in OnGUI() |
| 1551 | //if (tempLine.text != IntPtr.Zero) |
| 1552 | //{ |
| 1553 | // string text = Marshal.PtrToStringAnsi(tempLine.text); |
| 1554 | // AvatarLogger.Log(text); |
| 1555 | //} |
| 1556 | } |
| 1557 | |
| 1558 | debugLinePtr = ovrAvatar_GetDebugTransforms_Native(DebugLineCountData); |
| 1559 | lineCount = Marshal.ReadInt32(DebugLineCountData); |
| 1560 | |
| 1561 | ovrAvatarDebugTransform tempTrans = new ovrAvatarDebugTransform(); |
| 1562 | for (int i = 0; i < lineCount; i++) |
| 1563 | { |
| 1564 | var offset = i * Marshal.SizeOf(typeof(ovrAvatarDebugTransform)); |
| 1565 | Marshal.Copy(new IntPtr(debugLinePtr.ToInt64() + offset), scratchBufferFloat, 0, 10); |
| 1566 | |
| 1567 | OvrAvatar.ConvertTransform(scratchBufferFloat, ref tempTrans.transform); |
| 1568 | OvrAvatar.ConvertTransform(tempTrans.transform, debugLineGo.transform); |
| 1569 | |
| 1570 | tempTrans.context = (ovrAvatarDebugContext)Marshal.ReadInt32(new IntPtr(debugLinePtr.ToInt64() + offset + Marshal.OffsetOf(typeof(ovrAvatarDebugTransform), "context").ToInt64())); |
| 1571 | tempTrans.text = Marshal.ReadIntPtr(new IntPtr(debugLinePtr.ToInt64() + offset + Marshal.OffsetOf(typeof(ovrAvatarDebugTransform), "text").ToInt64())); |
| 1572 | |
| 1573 | const float SCALE_FACTOR = 0.1f; |
| 1574 | Vector3 transUp = SCALE_FACTOR * debugLineGo.transform.TransformVector(Vector3.up); |
| 1575 | Vector3 transRight = SCALE_FACTOR * debugLineGo.transform.TransformVector(Vector3.right); |
| 1576 | Vector3 transFwd = SCALE_FACTOR * debugLineGo.transform.TransformVector(Vector3.forward); |
| 1577 | |
| 1578 | Debug.DrawLine(debugLineGo.transform.position, debugLineGo.transform.position + transUp, Color.green); |
| 1579 | Debug.DrawLine(debugLineGo.transform.position, debugLineGo.transform.position + transRight, Color.red); |
| 1580 | Debug.DrawLine(debugLineGo.transform.position, debugLineGo.transform.position + transFwd, Color.blue); |
| 1581 | |
| 1582 | // TODO: Decide what to do with the text. Can only debug render in OnGUI() |
| 1583 | //if (tempTrans.text != IntPtr.Zero) |
| 1584 | //{ |
| 1585 | // string text = Marshal.PtrToStringAnsi(tempTrans.text); |
| 1586 | // AvatarLogger.Log(text); |
| 1587 | //} |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | [DllImport(LibFile, CallingConvention = CallingConvention.Cdecl)] |
| 1592 | public static extern void ovrAvatar_SetDebugDrawContext(UInt32 context); |
| 1593 | |
| 1594 | //OvrPlugin Hooks |
| 1595 | private const string ovrPluginDLL = "OVRPlugin"; |
| 1596 | private static System.Version ovrPluginVersion; |
| 1597 | |
| 1598 | public enum Result |
| 1599 | { |
| 1600 | /// Success |
| 1601 | Success = 0, |
| 1602 | |
| 1603 | /// Failure |
| 1604 | Failure = -1000, |
| 1605 | Failure_InvalidParameter = -1001, |
| 1606 | Failure_NotInitialized = -1002, |
| 1607 | Failure_InvalidOperation = -1003, |
| 1608 | Failure_Unsupported = -1004, |
| 1609 | Failure_NotYetImplemented = -1005, |
| 1610 | Failure_OperationFailed = -1006, |
| 1611 | Failure_InsufficientSize = -1007, |
| 1612 | } |
| 1613 | |
| 1614 | public static bool SendEvent(string name, string param = "", string source = "") |
| 1615 | { |
| 1616 | try |
| 1617 | { |
| 1618 | if (ovrPluginVersion == null) |
| 1619 | { |
| 1620 | string version = ovrp_GetVersion(); |
| 1621 | if (!String.IsNullOrEmpty(version)) |
| 1622 | { |
| 1623 | ovrPluginVersion = new System.Version(version.Split('-')[0]); |
| 1624 | } |
| 1625 | else |
| 1626 | { |
| 1627 | ovrPluginVersion = new System.Version(0, 0, 0); |
| 1628 | } |
| 1629 | } |
| 1630 | if (ovrPluginVersion >= OVRP_1_30_0.version) |
| 1631 | { |
| 1632 | return OVRP_1_30_0.ovrp_SendEvent2(name, param, source.Length == 0 ? "avatar_sdk" : source) == Result.Success; |
| 1633 | } |
| 1634 | else |
| 1635 | { |
| 1636 | return false; |
| 1637 | } |
| 1638 | } |
| 1639 | catch (Exception) |
| 1640 | { |
| 1641 | return false; |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | [DllImport(ovrPluginDLL, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ovrp_GetVersion")] |
| 1646 | private static extern IntPtr _ovrp_GetVersion(); |
| 1647 | public static string ovrp_GetVersion() { return Marshal.PtrToStringAnsi(_ovrp_GetVersion()); } |
| 1648 | |
| 1649 | private static class OVRP_1_30_0 |
| 1650 | { |
| 1651 | public static readonly System.Version version = new System.Version(1, 30, 0); |
| 1652 | [DllImport(ovrPluginDLL, CallingConvention = CallingConvention.Cdecl)] |
| 1653 | public static extern Result ovrp_SendEvent2(string name, string param, string source); |
| 1654 | } |
| 1655 | } |
| 1656 | } |