Ejemplo n.º 1
0
        public GameObject ImportVcf(string filename)
        {
            var vcf = VcfParser.ParseVcf(filename);
            var vdf = VdfParser.ParseVdf(vcf.VdfFilename);
            var vtf = VtfParser.ParseVtf(vcf.VtfFilename);

            var carObject = Instantiate(CarPrefab); //ImportGeo(vdf.SOBJGeoName + ".geo", vtf, CarPrefab.gameObject).GetComponent<ArcadeCar>();

            carObject.gameObject.name = vdf.Name + " (" + vcf.VariantName + ")";

            foreach (var hLoc in vdf.HLocs)
            {
                var hlocGo = new GameObject("HLOC");
                hlocGo.transform.parent        = carObject.transform;
                hlocGo.transform.localRotation = Quaternion.LookRotation(hLoc.Forward, hLoc.Up);
                hlocGo.transform.localPosition = hLoc.Position;
            }
            foreach (var vLoc in vdf.VLocs)
            {
                var vlocGo = new GameObject("VLOC");
                vlocGo.transform.parent        = carObject.transform;
                vlocGo.transform.localRotation = Quaternion.LookRotation(vLoc.Forward, vLoc.Up);
                vlocGo.transform.localPosition = vLoc.Position;
            }

            var thirdPerson = new GameObject("ThirdPerson");

            thirdPerson.transform.parent = carObject.transform;
            var firstPerson = new GameObject("FirstPerson");

            firstPerson.transform.parent = carObject.transform;
            firstPerson.SetActive(false);

            ImportCarParts(thirdPerson, vtf, vdf.PartsThirdPerson[0]);
            // ImportCarParts(firstPerson, vtf, vdf.PartsFirstPerson);
            //var destroyed = ImportCarParts(car, vtf, vdf.PartsThirdPerson[3]);
            //destroyed.gameObject.SetActive(false);

            if (vcf.FrontWheelDef != null)
            {
                var frontWheels = CreateWheelPair("Front", 0, carObject.gameObject, vdf, vtf, vcf.FrontWheelDef.Parts);
                carObject.SteerWheels = frontWheels;
                // carObject.BrakeWheels = frontWheels;
            }
            if (vcf.MidWheelDef != null)
            {
                CreateWheelPair("Mid", 2, carObject.gameObject, vdf, vtf, vcf.MidWheelDef.Parts);
            }
            if (vcf.BackWheelDef != null)
            {
                var backWheels = CreateWheelPair("Back", 4, carObject.gameObject, vdf, vtf, vcf.BackWheelDef.Parts);
                carObject.DriveWheels = backWheels;
            }

            return(carObject.gameObject);
        }
Ejemplo n.º 2
0
        public void TestDefaultVCFColumnOrder()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser        = new VcfParser();
                var parsedVariant = parser.Parse(file.TempFilePath).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedVariant.CompareTo(rg.Variant) == 0);
            }
        }
Ejemplo n.º 3
0
        public void AssignHashKey()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new VcfParser();
                var parsedData = parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0].GetHashCode() != 0);
            }
        }
Ejemplo n.º 4
0
        public void OneBaseLenghtInterval()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new VcfParser();
                var parsedData = parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0].Right == rg.Position + 1);
            }
        }
Ejemplo n.º 5
0
        public void FullySetArguments()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser        = new VcfParser(rg.Columns);
                var parsedVariant = parser.Parse(file.TempFilePath).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

                // Assert
                Assert.True(parsedVariant.CompareTo(rg.Variant) == 0);
            }
        }
Ejemplo n.º 6
0
        public void AvoidHeader(int headerCount, byte readOffset)
        {
            // Arrange
            using (var file = new TempFileCreator(new RegionGenerator(), headerLineCount: headerCount))
            {
                // Act
                var parser = new VcfParser()
                {
                    ReadOffset = readOffset
                };
                var parsedData = parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parsedData.Chromosomes.Count == 1);
            }
        }
Ejemplo n.º 7
0
        public void MultiVariantFile()
        {
            // Arrange
            var rg = new RegionGenerator {
                StrandColumn = 12
            };

            using (var file = new TempFileCreator(rg, variantsCount: 10, headerLineCount: 2))
            {
                // Act
                var parser     = new VcfParser();
                var parsedData = parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.Count == 10);
            }
        }
Ejemplo n.º 8
0
        private Vcf <Variant> ParseVCF(string filePath, RegionGenerator rg)
        {
            var parser = new VcfParser(rg.Columns);

            return(parser.Parse(filePath));
        }
Ejemplo n.º 9
0
        public GameObject ImportVcf(string filename, bool importFirstPerson, out Vdf vdf)
        {
            Vcf vcf = VcfParser.ParseVcf(filename);

            vdf = VdfParser.ParseVdf(vcf.VdfFilename);
            Vtf vtf = VtfParser.ParseVtf(vcf.VtfFilename);

            Car carObject = Object.Instantiate(_carPrefab);

            carObject.Configure(vdf, vcf);
            carObject.gameObject.name = vdf.Name + " (" + vcf.VariantName + ")";

            foreach (VLoc vLoc in vdf.VLocs)
            {
                GameObject vlocGo = new GameObject("VLOC");
                vlocGo.transform.parent        = carObject.transform;
                vlocGo.transform.localRotation = Quaternion.LookRotation(vLoc.Forward, vLoc.Up);
                vlocGo.transform.localPosition = vLoc.Position;
            }

            GameObject chassis = new GameObject("Chassis");

            chassis.transform.parent = carObject.transform;

            GameObject thirdPerson = new GameObject("ThirdPerson");

            thirdPerson.transform.parent = chassis.transform;

            Transform[] weaponMountTransforms = new Transform[vdf.HLocs.Count];
            for (int i = 0; i < vdf.HLocs.Count; ++i)
            {
                HLoc      hloc       = vdf.HLocs[i];
                Transform mountPoint = new GameObject(hloc.Label).transform;
                mountPoint.parent        = thirdPerson.transform;
                mountPoint.localRotation = Quaternion.LookRotation(hloc.Forward, hloc.Up);
                mountPoint.localPosition = hloc.Position;
                weaponMountTransforms[i] = mountPoint;
            }

            Dictionary <string, GameObject> partDict = new Dictionary <string, GameObject>();

            for (int i = 0; i < vdf.PartsThirdPerson.Count; ++i)
            {
                GameObject healthObject = new GameObject("Health " + i);
                healthObject.transform.SetParent(thirdPerson.transform);
                ImportCarParts(partDict, healthObject, vtf, vdf.PartsThirdPerson[i], _noColliderPrefab, false, false, i);
                if (i != 0)
                {
                    healthObject.SetActive(false);
                }
            }

            MeshFilter[] meshFilters = thirdPerson.GetComponentsInChildren <MeshFilter>();
            Bounds       bounds      = new Bounds();

            bounds.SetMinMax(Vector3.one * float.MaxValue, Vector3.one * float.MinValue);
            foreach (MeshFilter meshFilter in meshFilters)
            {
                Vector3 min = Vector3.Min(bounds.min, meshFilter.transform.position + meshFilter.sharedMesh.bounds.min) - thirdPerson.transform.position;
                Vector3 max = Vector3.Max(bounds.max, meshFilter.transform.position + meshFilter.sharedMesh.bounds.max) - thirdPerson.transform.position;
                bounds.SetMinMax(min, max);
            }

            GameObject chassisCollider = new GameObject("ChassisColliders");

            chassisCollider.transform.parent = carObject.transform;
            ImportCarParts(partDict, chassisCollider, vtf, vdf.PartsThirdPerson[0], _carBodyPrefab, true);

            for (int i = 0; i < vcf.Weapons.Count; ++i)
            {
                VcfWeapon weapon     = vcf.Weapons[i];
                int       mountPoint = weapon.MountPoint;
                HLoc      hloc       = vdf.HLocs[mountPoint];
                weapon.RearFacing = hloc.FacingDirection == 2;

                SdfPart[] partsArray;
                switch (hloc.MeshType)
                {
                case HardpointMeshType.Top:
                    partsArray = weapon.Gdf.TopParts;
                    break;

                case HardpointMeshType.Side:
                    partsArray = weapon.Gdf.SideParts;
                    break;

                case HardpointMeshType.Inside:
                    partsArray = weapon.Gdf.InsideParts;
                    break;

                case HardpointMeshType.Turret:
                    partsArray = weapon.Gdf.TurretParts;
                    break;

                default:
                    partsArray = null;
                    break;
                }

                if (partsArray != null)
                {
                    Transform weaponTransform = new GameObject(weapon.Gdf.Name).transform;
                    weaponTransform.SetParent(weaponMountTransforms[i]);
                    weaponTransform.localPosition = Vector3.zero;
                    weaponTransform.localRotation = Quaternion.identity;
                    ImportCarParts(partDict, weaponTransform.gameObject, vtf, partsArray, _noColliderPrefab, false);
                    weapon.Transform = weaponTransform;

                    // Disable depth test for 'inside' weapons, otherwise they are obscured.
                    if (hloc.MeshType == HardpointMeshType.Inside)
                    {
                        MeshRenderer weaponRenderer = weaponTransform.GetComponentInChildren <MeshRenderer>();
                        if (weaponRenderer != null)
                        {
                            weaponRenderer.sharedMaterial.shader = Shader.Find("Custom/CutOutWithoutZ");
                        }
                    }
                }
                else
                {
                    weapon.Transform = chassis.transform;
                }
            }

            // Note: The following is probably how I76 does collision detection. Two large boxes that encapsulate the entire vehicle.
            // Right now this won't work with Open76's raycast suspension, so I'm leaving this off for now. Investigate in the future.
            //var innerBox = chassisCollider.AddComponent<BoxCollider>();
            //innerBox.center = vdf.BoundsInner.center;
            //innerBox.size = vdf.BoundsInner.size;

            //var outerBox = chassisCollider.AddComponent<BoxCollider>();
            //outerBox.center = vdf.BoundsOuter.center;
            //outerBox.size = vdf.BoundsOuter.size;

            RaySusp[] frontWheels = null;
            if (vcf.FrontWheelDef != null)
            {
                frontWheels = CreateWheelPair(partDict, "Front", 0, carObject.gameObject, vdf, vtf, vcf.FrontWheelDef);
                carObject.Movement.FrontWheels = frontWheels;
            }
            if (vcf.MidWheelDef != null)
            {
                CreateWheelPair(partDict, "Mid", 2, carObject.gameObject, vdf, vtf, vcf.MidWheelDef);
            }

            RaySusp[] rearWheels = null;
            if (vcf.BackWheelDef != null)
            {
                rearWheels = CreateWheelPair(partDict, "Back", 4, carObject.gameObject, vdf, vtf, vcf.BackWheelDef);
                carObject.Movement.RearWheels = rearWheels;
            }

            if (importFirstPerson)
            {
                GameObject firstPerson = new GameObject("FirstPerson");
                firstPerson.transform.parent = chassis.transform;
                ImportCarParts(partDict, firstPerson, vtf, vdf.PartsFirstPerson, _noColliderPrefab, false, true, 0, LayerMask.NameToLayer("FirstPerson"));

                carObject.InitPanels();
                firstPerson.SetActive(false);
            }

            carObject.Movement.Initialise(chassis.transform, frontWheels, rearWheels);

            return(carObject.gameObject);
        }