Example #1
0
 /// <inheritdoc />
 public void RigidBodyMovePosition(MWVector3 position)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.MovePosition(_sceneRoot.TransformPoint(position.ToVector3()));
     });
 }
Example #2
0
 /// <inheritdoc />
 public void RigidBodyAddForce(MWVector3 force)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.AddForce(_sceneRoot.TransformDirection(force.ToVector3()));
     });
 }
Example #3
0
 /// <inheritdoc />
 public void RigidBodyAddForceAtPosition(MWVector3 force, MWVector3 position)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.AddForceAtPosition(_sceneRoot.TransformDirection(force.ToVector3()), _sceneRoot.TransformPoint(position.ToVector3()));
     });
 }
Example #4
0
 /// <inheritdoc />
 public void RigidBodyAddRelativeTorque(MWVector3 relativeTorque)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.AddRelativeTorque(_sceneRoot.TransformDirection(relativeTorque.ToVector3()));
     });
 }
/*FIXME
 *              /// <inheritdoc />
 *              public void RigidBodyMovePosition(MWVector3 position)
 *              {
 *                      _updateActions.Enqueue(
 *                              (rigidBody) =>
 *                              {
 *                                      rigidBody.MovePosition(_sceneRoot.ToGlobal(position.ToVector3()));
 *                              });
 *              }
 *
 *              /// <inheritdoc />
 *              public void RigidBodyMoveRotation(MWQuaternion rotation)
 *              {
 *                      _updateActions.Enqueue(
 *                              (rigidBody) =>
 *                              {
 *                                      rigidBody.MoveRotation(_sceneRoot.rotation * rotation.ToQuaternion());
 *                              });
 *              }
 */
        /// <inheritdoc />
        public void RigidBodyAddForce(MWVector3 force)
        {
            _updateActions.Enqueue(
                (rigidBody) =>
            {
                rigidBody.AddCentralForce(_sceneRoot.ToGlobal(force.ToVector3()));
            });
        }
 /// <inheritdoc />
 public void RigidBodyAddTorque(MWVector3 torque)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.AddTorque(_sceneRoot.ToGlobal(torque.ToVector3()));
     });
 }
 /// <inheritdoc />
 public void RigidBodyAddForceAtPosition(MWVector3 force, MWVector3 position)
 {
     _updateActions.Enqueue(
         (rigidBody) =>
     {
         rigidBody.AddForce(_sceneRoot.ToGlobal(position.ToVector3()), _sceneRoot.ToGlobal(force.ToVector3()));
     });
 }
Example #8
0
        public static void AddColliderToPrimitive(this GameObject _this, PrimitiveDefinition prim)
        {
            MWVector3 dims = prim.Dimensions;

            switch (prim.Shape)
            {
            case PrimitiveShape.Sphere:
                var sphereCollider = _this.AddComponent <SphereCollider>();
                sphereCollider.radius = prim.Radius.GetValueOrDefault(0.5f);
                break;

            case PrimitiveShape.Box:
                dims = dims ?? new MWVector3(1, 1, 1);
                var boxCollider = _this.AddComponent <BoxCollider>();
                boxCollider.size = dims.ToVector3();
                break;

            case PrimitiveShape.Capsule:
                dims = dims ?? new MWVector3(0, 1, 0);
                var capsuleCollider = _this.AddComponent <CapsuleCollider>();
                capsuleCollider.radius    = prim.Radius.GetValueOrDefault(0.5f);
                capsuleCollider.height    = dims.LargestComponentValue() + 2 * capsuleCollider.radius;
                capsuleCollider.direction = dims.LargestComponentIndex();
                break;

            case PrimitiveShape.Cylinder:
                dims = dims ?? new MWVector3(0, 1, 0);
                var cylinderCollider = _this.AddComponent <CapsuleCollider>();
                cylinderCollider.radius    = prim.Radius.GetValueOrDefault(0.5f);
                cylinderCollider.height    = dims.LargestComponentValue() + cylinderCollider.radius;
                cylinderCollider.direction = dims.LargestComponentIndex();
                break;

            case PrimitiveShape.Plane:
                dims = dims ?? new MWVector3(1, 0, 1);
                var planeCollider = _this.AddComponent <BoxCollider>();
                planeCollider.size = new Vector3(dims.X, 0.01f, dims.Z);
                break;
            }
        }
Example #9
0
        /// <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
            }
        }