Example #1
0
        /// <summary>
        /// Creates a door given its properties.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateDoor(DoorProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            HostedProperty hp   = ConvertToHosted(properties);
            FamilyInstance door = CreateHostedElement(hp, false);

            XYZ facing = door.FacingOrientation * -1;

            facing = VectorManipulator.TransformUVinXYZ(VectorManipulator.RotateVector(facing, baseRotation));
            double angle = Math.Atan2(facing.Y, facing.X);

            if (Math.Abs(angle - DeegreToRadians(properties.Rotation)) > 0.001)
            {
                door.flipFacing();
            }

            if ((door.FacingOrientation.CrossProduct(door.HandOrientation).Z < 0) ^ properties.OpenLeft)
            {
                door.flipHand();
            }

            /*
             * double offset = GetFamilyOffset(properties.Type).U;
             * XYZ translation = door.HandOrientation * offset;
             * ElementTransformUtils.MoveElement(doc, door.Id, translation);
             */

            return(door);
        }
Example #2
0
 /// <summary>
 /// Adds rotated accordingly to the collider rotation normals to the list.
 /// </summary>
 /// <param name="rayDataList">List containing ray data for each of the collider's walls.</param>
 /// <param name="colliderRotation">Rotation of the collider.</param>
 /// <returns></returns>
 private void AddNormals(List <RayData> rayDataList, Quaternion colliderRotation)
 {
     rayDataList[(int)BoxColliderWallsEnum.Right].normal   = VectorManipulator.RotateVector(colliderRotation, Vector3.right);
     rayDataList[(int)BoxColliderWallsEnum.Left].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.left);
     rayDataList[(int)BoxColliderWallsEnum.Up].normal      = VectorManipulator.RotateVector(colliderRotation, Vector3.up);
     rayDataList[(int)BoxColliderWallsEnum.Down].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.down);
     rayDataList[(int)BoxColliderWallsEnum.Forward].normal = VectorManipulator.RotateVector(colliderRotation, Vector3.forward);
     rayDataList[(int)BoxColliderWallsEnum.Back].normal    = VectorManipulator.RotateVector(colliderRotation, Vector3.back);
 }
Example #3
0
 /// <summary>
 /// Rotates offsets of the rays data using provided quaternion.
 /// </summary>
 /// <param name="rayDataList">Offsets to rotate.</param>
 /// <param name="colliderRotation">Rotation info.</param>
 private void RotateOffsets(List <RayData> rayDataList, Quaternion colliderRotation)
 {
     foreach (var singleRayData in rayDataList)
     {
         singleRayData.WidthOffset  = VectorManipulator.RotateVector(colliderRotation, singleRayData.WidthOffset);
         singleRayData.HeightOffset =
             VectorManipulator.RotateVector(colliderRotation, singleRayData.HeightOffset);
     }
 }
Example #4
0
        void Update()
        {
            _spawnerTransform = gameObject.transform;
            var offset = _spawnerTransform.localScale * 0.5f; //Scale defines whole width. We need half of it.

            offset       = VectorManipulator.RotateVector(_spawnerTransform.rotation, offset);
            _maxPosition = (_spawnerTransform.position + offset) / _smallestLengthUnit;
            _minPosition = (_spawnerTransform.position - offset) / _smallestLengthUnit;
        }
Example #5
0
        /// <summary>
        /// Create a hosted element on a wall.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateHostedElement(HostedProperty properties, bool correctPosition)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the parameters from properties
            XYZ    point  = GetXYZFromProperties(properties.Coordinate);
            string fsName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

            offset = new UV(UnitUtils.ConvertToInternalUnits(offset.U, UnitTypeId.Meters),
                            UnitUtils.ConvertToInternalUnits(offset.V, UnitTypeId.Meters));

            FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsName);

            Wall wall = FindWall(point, baseLevel);

            // get the normal wall vector
            LocationCurve wallCurve      = wall.Location as LocationCurve;
            Line          wallLine       = wallCurve.Curve as Line;
            XYZ           wallStartPoint = wallLine.GetEndPoint(0);
            XYZ           wallEndPoint   = wallLine.GetEndPoint(1);
            XYZ           wallNormal     = VectorManipulator.CalculateNormal(wallStartPoint - wallEndPoint);

            // calculates the correct direction of the instance
            XYZ insertionPoint   = VectorManipulator.GetClosesetPointInLine(point, wallLine);
            XYZ correctDirection = (point - insertionPoint).Normalize();

            // calculates instance offset
            double angle = Math.Atan2(correctDirection.Y, correctDirection.X);

            offset = VectorManipulator.RotateVector(offset, angle + baseRotation);
            point += VectorManipulator.TransformUVinXYZ(offset);

            // Creates the element
            FamilyInstance instance = doc.Create.NewFamilyInstance(point, familySymbol, wall, baseLevel,
                                                                   Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            // if the initial orientation and the correct orientation are not equal, flip the instance
            if (!wallNormal.IsAlmostEqualTo(correctDirection) && correctPosition)
            {
                instance.flipFacing();
            }

            return(instance);
        }
Example #6
0
        /// <summary>
        /// Creates a piece of furniture.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateFurniture(FurnitureProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the properties
            double rotation = DeegreToRadians(properties.Rotation);
            XYZ    p0       = GetXYZFromProperties(properties.Coordinate.ElementAt(0));
            XYZ    p1       = GetXYZFromProperties(properties.Coordinate.ElementAt(1));
            XYZ    point    = (p0 + p1) / 2;

            string fsFamilyName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

            offset = new UV(UnitUtils.ConvertToInternalUnits(offset.U, UnitTypeId.Meters),
                            UnitUtils.ConvertToInternalUnits(offset.V, UnitTypeId.Meters));

            offset = VectorManipulator.RotateVector(offset, rotation + baseRotation);

            // Creates a point above the furniture to serve as a rotation axis
            XYZ            axisPoint = new XYZ(point.X, point.Y, baseLevel.Elevation + 1);
            Line           axis      = Line.CreateBound(point, axisPoint);
            FamilyInstance furniture;

            try
            {
                FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsFamilyName);
                Autodesk.Revit.DB.Structure.StructuralType structuralType = Autodesk.Revit.DB.Structure.StructuralType.NonStructural;
                furniture = doc.Create.NewFamilyInstance(point, familySymbol, structuralType);
                ElementTransformUtils.RotateElement(doc, furniture.Id, axis, rotation + baseRotation);
                ElementTransformUtils.MoveElement(doc, furniture.Id, VectorManipulator.TransformUVinXYZ(offset));
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao inserir mobiliario \"" + fsFamilyName + "\".", e);
            }
            return(furniture);
        }
Example #7
0
    /// <summary>
    /// Performs player movement.
    /// </summary>
    /// <param name="axes">Axes along which the movement shall be performed. Must be normalized.</param>
    void MovePlayer(Vector3 axes)
    {
        float timeDelta = Time.deltaTime;

        _currentVelocity  = axes;
        _currentVelocity *= _maxVelocity;
        _currentVelocity *= timeDelta;

        //The editor itself applies correction to movement accordingly to player rotation,
        //but the deployed app does not. Apply it manually so the player will walk forward always
        //in the direction they're looking.
        if (_inputController.ControllerDetected)
        {
            _currentVelocity = VectorManipulator.RotateVector(_mainCameraTransform.rotation, _currentVelocity);
        }

        _currentVelocity = _collisionResolver.SolveCollisions(_movingTransform.position, _currentVelocity, _movingTransform.rotation);


        _movingTransform.Translate(_currentVelocity);
    }
Example #8
0
        void Start()
        {
            if (_reactionDistance <= 0.0f)
            {
                throw new Exception("Error: _reaction distance cannot be lesser or equal to 0!");
            }

            _reactionDistanceFactor = 1 / _reactionDistance;
            _normalVector           = VectorManipulator.RotateVector(gameObject.transform.rotation, _normalVector);

            if (_renderer == null)
            {
                throw new Exception("Error: EntityBlockerScript has no renderer attached!");
            }

            if (_blockedEntityTransform == null)
            {
                throw new Exception(
                          "Error: EntityBlockerScript has no blocked entity transform attached. How is it supposed to check for distance?");
            }

            _renderer.material.color = _blockerColor * _smallestColorIntensity;
        }