public override MWAssets.Material GeneratePatch(IMixedRealityExtensionApp app, Material material) { var patch = base.GeneratePatch(app, material); var unityColor = material.GetColor(EmissiveColorProp); patch.EmissiveColor = new ColorPatch() { R = unityColor.r, G = unityColor.g, B = unityColor.b, A = unityColor.a }; patch.EmissiveTextureId = app.AssetManager.GetByObject(material.GetTexture(EmissiveTexProp))?.Id; patch.EmissiveTextureOffset = new Vector2Patch(material.GetTextureOffset(EmissiveTexProp)); patch.EmissiveTextureScale = new Vector2Patch(material.GetTextureScale(EmissiveTexProp)); patch.AlphaCutoff = material.GetFloat("_AlphaCutoff"); patch.AlphaMode = material.renderQueue == (int)RenderQueue.Transparent ? MWAssets.AlphaMode.Blend : material.renderQueue == (int)RenderQueue.AlphaTest ? MWAssets.AlphaMode.Mask : MWAssets.AlphaMode.Opaque; return(patch); }
/// <summary> /// Removes the app from the runtime. /// </summary> /// <param name="app">The app to remove.</param> public void RemoveApp(IMixedRealityExtensionApp app) { var mreApp = (MixedRealityExtensionApp)app; mreApp.Shutdown(); _apps.Remove(mreApp.InstanceId); }
public void ShowDialog(IMixedRealityExtensionApp app, string text, bool acceptInput, Action <bool, string> callback) { queue.Enqueue(new DialogQueueEntry() { text = text, allowInput = acceptInput, callback = callback }); ProcessQueue(); }
/// <inheritdoc /> public virtual MWMaterial GeneratePatch(IMixedRealityExtensionApp app, Material material) { return(new MWMaterial() { Color = new ColorPatch(material.color), MainTextureId = app.AssetCache.GetId(material.mainTexture), MainTextureOffset = new Vector2Patch(material.mainTextureOffset), MainTextureScale = new Vector2Patch(material.mainTextureScale) }); }
/// <inheritdoc /> public virtual MWMaterial GeneratePatch(IMixedRealityExtensionApp app, Material material) { return(new MWMaterial() { Color = new ColorPatch(material.AlbedoColor), MainTextureId = app.AssetManager.GetByObject(material.AlbedoTexture)?.Id, MainTextureOffset = new Vector3Patch(material.Uv1Offset), MainTextureScale = new Vector3Patch(material.Uv1Scale) }); }
private void Start() { #if !ALTSPACE_UNITYCLIENT var font = Resources.GetBuiltinResource <Font>("Arial.ttf"); MREAPI.InitializeAPI( defaultMaterial: Resources.Load <Material>("MreMaterial"), layerApplicator: new MixedRealityExtension.Factories.SimpleLayerApplicator(0, 14, 0, 5), textFactory: new MixedRealityExtension.Factories.MWTextFactory(font, font), logger: new UnityLogger() ); App = MREAPI.AppsAPI.CreateMixedRealityExtensionApp("testing", this); App.SceneRoot = gameObject; App.Startup(Uri, "testing", "SceneEditor"); App.OnConnected += App_OnConnected; App.OnAppStarted += App_OnAppStarted; #endif }
/// <inheritdoc /> public virtual void ApplyMaterialPatch(IMixedRealityExtensionApp app, Material material, MWMaterial patch) { if (patch.Color != null) { _materialColor.FromUnityColor(material.color); _materialColor.ApplyPatch(patch.Color); material.color = _materialColor.ToColor(); } if (patch.MainTextureOffset != null) { _textureOffset.FromUnityVector2(material.mainTextureOffset); _textureOffset.ApplyPatch(patch.MainTextureOffset); material.mainTextureOffset = _textureOffset.ToVector2(); } if (patch.MainTextureScale != null) { _textureScale.FromUnityVector2(material.mainTextureScale); _textureScale.ApplyPatch(patch.MainTextureScale); material.mainTextureScale = _textureScale.ToVector2(); } if (patch.MainTextureId != null) { var textureId = patch.MainTextureId.Value; mainTextureAssignments[material.GetInstanceID()] = textureId; if (patch.MainTextureId == Guid.Empty) { material.mainTexture = null; } else { app.AssetCache.OnCached(textureId, tex => { if (!material || mainTextureAssignments[material.GetInstanceID()] != textureId) { return; } material.mainTexture = (Texture)tex; }); } } }
void Start() { if (!_apiInitialized) { MREAPI.InitializeAPI( defaultMaterial: DefaultPrimMaterial, layerApplicator: new SimpleLayerApplicator(0, 9, 10, 5), behaviorFactory: new BehaviorFactory(), textFactory: new TmpTextFactory() { DefaultFont = DefaultFont, SerifFont = SerifFont, SansSerifFont = SansSerifFont, MonospaceFont = MonospaceFont, CursiveFont = CursiveFont }, libraryFactory: new ResourceFactory(), userInfoProvider: new UserInfoProvider(), dialogFactory: DialogFactory, logger: new MRELogger(), materialPatcher: new VertexMaterialPatcher(), gltfImporterFactory: new VertexShadedGltfImporterFactory() ); _apiInitialized = true; } MREApp = MREAPI.AppsAPI.CreateMixedRealityExtensionApp(AppID, this); if (SceneRoot == null) { SceneRoot = transform; } MREApp.SceneRoot = SceneRoot.gameObject; MREApp.OnConnecting += MREApp_OnConnecting; MREApp.OnConnectFailed += MREApp_OnConnectFailed; MREApp.OnConnected += MREApp_OnConnected; MREApp.OnDisconnected += MREApp_OnDisconnected; MREApp.OnAppStarted += MREApp_OnAppStarted; MREApp.OnAppShutdown += MREApp_OnAppShutdown; if (AutoStart) { EnableApp(); } MREApp.RPC.OnReceive("log", new RPCHandler <TestLogMessage>( (logMessage) => Debug.Log($"Log RPC of type {logMessage.GetType()} called with args [ {logMessage.Message}, {logMessage.TestBoolean} ]") )); // Functional test commands MREApp.RPC.OnReceive("functional-test:test-started", new RPCHandler <string>((testName) => { Debug.Log($"Test started: {testName}."); })); MREApp.RPC.OnReceive("functional-test:test-complete", new RPCHandler <string, bool>((testName, success) => { Debug.Log($"Test complete: {testName}. Success: {success}."); })); MREApp.RPC.OnReceive("functional-test:close-connection", new RPCHandler(() => { MREApp.Shutdown(); })); MREApp.RPC.OnReceive("functional-test:trace-message", new RPCHandler <string, string>((testName, message) => { Debug.Log($"{testName}: {message}"); })); }
public override void ApplyMaterialPatch(IMixedRealityExtensionApp app, Material material, MWAssets.Material patch) { base.ApplyMaterialPatch(app, material, patch); if (patch.EmissiveColor != null) { var color = material.GetColor(EmissiveColorProp); color.r = patch.EmissiveColor.R ?? color.r; color.g = patch.EmissiveColor.G ?? color.g; color.b = patch.EmissiveColor.B ?? color.b; color.a = patch.EmissiveColor.A ?? color.a; material.SetColor(EmissiveColorProp, color); } if (patch.EmissiveTextureOffset != null) { var offset = material.GetTextureOffset(EmissiveTexProp); offset.x = patch.EmissiveTextureOffset.X ?? offset.x; offset.y = patch.EmissiveTextureOffset.Y ?? offset.y; material.SetTextureOffset(EmissiveTexProp, offset); } if (patch.EmissiveTextureScale != null) { var scale = material.GetTextureScale(EmissiveTexProp); scale.x = patch.EmissiveTextureScale.X ?? scale.x; scale.y = patch.EmissiveTextureScale.Y ?? scale.y; material.SetTextureScale(EmissiveTexProp, scale); } if (patch.EmissiveTextureId != null) { var textureId = patch.EmissiveTextureId.Value; emissiveTextureAssignments[material.GetInstanceID()] = textureId; if (textureId == Guid.Empty) { material.SetTexture(EmissiveTexProp, null); } else { app.AssetManager.OnSet(textureId, tex => { if (!material || emissiveTextureAssignments[material.GetInstanceID()] != textureId) { return; } material.SetTexture(EmissiveTexProp, (Texture)tex.Asset); }); } } if (patch.AlphaCutoff != null) { material.SetFloat("_AlphaCutoff", patch.AlphaCutoff.Value); } switch (patch.AlphaMode) { case MWAssets.AlphaMode.Opaque: material.renderQueue = (int)RenderQueue.Geometry; material.SetOverrideTag("RenderMode", "Opaque"); material.SetInt("_ZWrite", 1); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.Zero); material.SetInt("_ShouldCutout", 0); break; case MWAssets.AlphaMode.Mask: material.renderQueue = (int)RenderQueue.AlphaTest; material.SetOverrideTag("RenderMode", "TransparentCutout"); material.SetInt("_ZWrite", 1); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.Zero); material.SetInt("_ShouldCutout", 1); break; case MWAssets.AlphaMode.Blend: material.renderQueue = (int)RenderQueue.Transparent; material.SetOverrideTag("RenderMode", "Transparent"); material.SetInt("_ZWrite", 0); material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); material.SetInt("_ShouldCutout", 0); break; // ignore default case, i.e. null } }
public override bool UsesTexture(IMixedRealityExtensionApp app, Material material, Texture texture) { return(base.UsesTexture(app, material, texture) || material.GetTexture(EmissiveTexProp) == texture); }
public IUserInfo GetUserInfo(IMixedRealityExtensionApp app, Guid userId) { return(null); }
void Start() { if (!_apiInitialized) { var assetCacheGo = new GameObject("MRE Asset Cache"); var assetCache = assetCacheGo.AddComponent <AssetCache>(); assetCache.CacheRootGO = new GameObject("Assets"); assetCache.CacheRootGO.transform.SetParent(assetCacheGo.transform, false); assetCache.CacheRootGO.SetActive(false); MREAPI.InitializeAPI( defaultMaterial: DefaultPrimMaterial, layerApplicator: new SimpleLayerApplicator(0, 9, 10, 5), assetCache: assetCache, textFactory: new TmpTextFactory() { DefaultFont = DefaultFont, SerifFont = SerifFont, SansSerifFont = SansSerifFont, MonospaceFont = MonospaceFont, CursiveFont = CursiveFont }, permissionManager: new SimplePermissionManager(GrantedPermissions), behaviorFactory: new MRTKBehaviorFactory(), dialogFactory: DialogFactory, libraryFactory: new ResourceFactory(), gltfImporterFactory: new VertexShadedGltfImporterFactory(), materialPatcher: new VertexMaterialPatcher(), logger: new MRELogger() ); _apiInitialized = true; } MREApp = MREAPI.AppsAPI.CreateMixedRealityExtensionApp(this, AppID); if (SceneRoot == null) { SceneRoot = transform; } MREApp.SceneRoot = SceneRoot.gameObject; if (AutoStart) { EnableApp(); } MREApp.RPC.OnReceive("log", new RPCHandler <TestLogMessage>( (logMessage) => Debug.Log($"Log RPC of type {logMessage.GetType()} called with args [ {logMessage.Message}, {logMessage.TestBoolean} ]") )); // Functional test commands MREApp.RPC.OnReceive("functional-test:test-started", new RPCHandler <string>((testName) => { Debug.Log($"Test started: {testName}."); })); MREApp.RPC.OnReceive("functional-test:test-complete", new RPCHandler <string, bool>((testName, success) => { Debug.Log($"Test complete: {testName}. Success: {success}."); })); MREApp.RPC.OnReceive("functional-test:close-connection", new RPCHandler(() => { MREApp.Shutdown(); })); MREApp.RPC.OnReceive("functional-test:trace-message", new RPCHandler <string, string>((testName, message) => { Debug.Log($"{testName}: {message}"); })); }
public RPCInterface(IMixedRealityExtensionApp app) => _app = app;
/// <inheritdoc /> public virtual void ApplyMaterialPatch(IMixedRealityExtensionApp app, Material material, MWMaterial patch) { if (patch.Color != null) { _materialColor.FromGodotColor(material.AlbedoColor); _materialColor.ApplyPatch(patch.Color); material.AlbedoColor = _materialColor.ToColor(); } if (patch.MainTextureOffset != null) { _textureOffset.FromGodotVector3(material.Uv1Offset); _textureOffset.ApplyPatch(patch.MainTextureOffset); _textureOffset.Y *= -1; material.Uv1Offset = _textureOffset.ToVector3(); } if (patch.MainTextureScale != null) { _textureScale.FromGodotVector3(material.Uv1Scale); _textureScale.ApplyPatch(patch.MainTextureScale); material.Uv1Scale = _textureScale.ToVector3(); } if (patch.MainTextureId != null) { var textureId = patch.MainTextureId.Value; mainTextureAssignments[material.GetInstanceId()] = textureId; if (patch.MainTextureId == Guid.Empty) { material.AlbedoTexture = null; } else { app.AssetManager.OnSet(textureId, tex => { if (material == null || mainTextureAssignments[material.GetInstanceId()] != textureId) { return; } material.AlbedoTexture = (Texture)tex.Asset; }); } } if (patch.EmissiveColor != null) { material.EmissionEnabled = true; var color = material.Emission; color.r = patch.EmissiveColor.R ?? color.r; color.g = patch.EmissiveColor.G ?? color.g; color.b = patch.EmissiveColor.B ?? color.b; color.a = patch.EmissiveColor.A ?? color.a; material.Emission = color; } if (patch.EmissiveTextureOffset != null) { material.EmissionEnabled = true; var offset = material.Uv2Offset; offset.x = patch.EmissiveTextureOffset.X ?? offset.x; offset.y = patch.EmissiveTextureOffset.Y ?? offset.y; material.Uv2Offset = offset; } if (patch.EmissiveTextureScale != null) { material.EmissionEnabled = true; var scale = material.Uv2Scale; scale.x = patch.EmissiveTextureScale.X ?? scale.x; scale.y = patch.EmissiveTextureScale.Y ?? scale.y; material.Uv2Scale = scale; } if (patch.EmissiveTextureId != null) { material.EmissionEnabled = true; var textureId = patch.EmissiveTextureId.Value; emissiveTextureAssignments[material.GetInstanceId()] = textureId; if (textureId == Guid.Empty) { material.EmissionTexture = null; } else { app.AssetManager.OnSet(textureId, tex => { if (material == null || emissiveTextureAssignments[material.GetInstanceId()] != textureId) { return; } material.EmissionTexture = (Texture)tex.Asset; }); } } if (patch.AlphaCutoff != null) { material.ParamsUseAlphaScissor = true; material.ParamsAlphaScissorThreshold = patch.AlphaCutoff.Value; } switch (patch.AlphaMode) { case MWAssets.AlphaMode.Opaque: material.FlagsTransparent = false; break; case MWAssets.AlphaMode.Mask: material.ParamsUseAlphaScissor = true; material.ParamsAlphaScissorThreshold = 1.0f; break; case MWAssets.AlphaMode.Blend: material.FlagsTransparent = true; material.ParamsUseAlphaScissor = false; break; // ignore default case, i.e. null } }
/// <inheritdoc /> public virtual bool UsesTexture(IMixedRealityExtensionApp app, Material material, Texture texture) { return(material.AlbedoTexture == texture); }
void Start() { if (!_apiInitialized) { MREAPI.InitializeAPI( DefaultPrimMaterial, behaviorFactory: new BehaviorFactory(), textFactory: new MWTextFactory(SerifFont, SansSerifFont), libraryFactory: new ResourceFactory(), assetCache: new AssetCache(new GameObject("MRE Asset Cache")), userInfoProvider: new UserInfoProvider(), logger: new MRELogger()); _apiInitialized = true; } MREApp = MREAPI.AppsAPI.CreateMixedRealityExtensionApp(AppID, this); if (SceneRoot == null) { SceneRoot = transform; } MREApp.SceneRoot = SceneRoot.gameObject; MREApp.OnConnecting += MREApp_OnConnecting; MREApp.OnConnectFailed += MREApp_OnConnectFailed; MREApp.OnConnected += MREApp_OnConnected; MREApp.OnDisconnected += MREApp_OnDisconnected; MREApp.OnAppStarted += MREApp_OnAppStarted; MREApp.OnAppShutdown += MREApp_OnAppShutdown; if (AutoStart) { EnableApp(); } MREApp.RPC.OnReceive("log", new RPCHandler <TestLogMessage>( (logMessage) => Debug.Log($"Log RPC of type {logMessage.GetType()} called with args [ {logMessage.Message}, {logMessage.TestBoolean} ]") )); // Functional test commands MREApp.RPC.OnReceive("functional-test:test-started", new RPCHandler <string>((testName) => { Debug.Log($"Test started: {testName}."); })); MREApp.RPC.OnReceive("functional-test:test-complete", new RPCHandler <string, bool>((testName, success) => { Debug.Log($"Test complete: {testName}. Success: {success}."); })); MREApp.RPC.OnReceive("functional-test:close-connection", new RPCHandler(() => { MREApp.Shutdown(); })); MREApp.RPC.OnReceive("functional-test:trace-message", new RPCHandler <string, string>((testName, message) => { Debug.Log($"{testName}: {message}"); })); }
public override void _Ready() { if (!_apiInitialized) { var assetCacheGo = new Node { Name = "MRE Asset Cache" }; var assetCache = new AssetCache(); assetCacheGo.AddChild(assetCache); assetCache.CacheRootGO = new Node { Name = "Assets" }; assetCacheGo.AddChild(assetCache.CacheRootGO); assetCache.CacheRootGO.SetProcess(false); MREAPI.InitializeAPI( defaultMaterial: DefaultPrimMaterial, layerApplicator: new SimpleLayerApplicator(0, 9, 10, 5), assetCache: assetCache, textFactory: new SimpleTextFactory(), permissionManager: new SimplePermissionManager(GrantedPermissions), behaviorFactory: new BehaviorFactory(), //dialogFactory: DialogFactory, libraryFactory: new ResourceFactory(), //gltfImporterFactory: new VertexShadedGltfImporterFactory(), //materialPatcher: new VertexMaterialPatcher(), logger: new MRELogger() ); _apiInitialized = true; } //FIXME temp MREAPI.AppsAPI.PermissionManager = new MixedRealityExtension.Factories.SimplePermissionManager(GrantedPermissions); MREApp = MREAPI.AppsAPI.CreateMixedRealityExtensionApp(this, EphemeralAppID, AppID); if (SceneRoot == null) { SceneRoot = this; } MREApp.SceneRoot = SceneRoot; if (AutoStart) { EnableApp(); } MREApp.RPC.OnReceive("log", new RPCHandler <TestLogMessage>( (logMessage) => GD.Print($"Log RPC of type {logMessage.GetType()} called with args [ {logMessage.Message}, {logMessage.TestBoolean} ]") )); // Functional test commands MREApp.RPC.OnReceive("functional-test:test-started", new RPCHandler <string>((testName) => { GD.Print($"Test started: {testName}."); })); MREApp.RPC.OnReceive("functional-test:test-complete", new RPCHandler <string, bool>((testName, success) => { GD.Print($"Test complete: {testName}. Success: {success}."); })); MREApp.RPC.OnReceive("functional-test:close-connection", new RPCHandler(() => { MREApp.Shutdown(); })); MREApp.RPC.OnReceive("functional-test:trace-message", new RPCHandler <string, string>((testName, message) => { GD.Print($"{testName}: {message}"); })); }
public IUserInfo GetUserInfo(IMixedRealityExtensionApp app, Guid userId) { return(MREComponent.GetUserInfo(userId)); }