예제 #1
0
 public BCoordinateF() : base()
 {
     x           = 0;
     y           = 0;
     z           = 0;
     coordSystem = CoordSystem.WSG86;
     rotSystem   = RotationSystem.WORLD;
     coordAxis   = new CoordAxis(CoordAxis.RightHand_Yup);
 }
예제 #2
0
        // Convert the positions and all the vertices in an ExtendedPrim from one
        //     coordinate space to another. ExtendedPrim.coordSpace gives the current
        //     coordinates and we specify a new one here.
        // This is not a general solution -- it pretty much only works to convert
        //     right-handed,Z-up coordinates (OpenSimulator) to right-handed,Y-up
        //     (OpenGL).
        public static void FixCoordinates(BInstance inst, CoordAxis newCoords)
        {
            if (inst.coordAxis.system != newCoords.system)
            {
                OMV.Matrix4    coordTransform  = OMV.Matrix4.Identity;
                OMV.Quaternion coordTransformQ = OMV.Quaternion.Identity;
                if (inst.coordAxis.getUpDimension == CoordAxis.Zup &&
                    newCoords.getUpDimension == CoordAxis.Yup)
                {
                    // The one thing we know to do is change from Zup to Yup
                    coordTransformQ = OMV.Quaternion.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, -(float)Math.PI / 2f);
                    // Make a clean matrix version.
                    // The libraries tend to create matrices with small numbers (1.119093e-07) for zero.
                    coordTransform = new OMV.Matrix4(
                        1, 0, 0, 0,
                        0, 0, -1, 0,
                        0, 1, 0, 0,
                        0, 0, 0, 1);
                }

                OMV.Vector3    oldPos = inst.Position; // DEBUG DEBUG
                OMV.Quaternion oldRot = inst.Rotation; // DEBUG DEBUG
                // Fix the location in space
                inst.Position = inst.Position * coordTransformQ;
                inst.Rotation = coordTransformQ * inst.Rotation;

                inst.coordAxis = newCoords;
                // ConvOAR.Globals.log.DebugFormat("{0} FixCoordinates. dispID={1}, oldPos={2}, newPos={3}, oldRot={4}, newRot={5}",
                //     _logHeader, inst.handle, oldPos, inst.Position, oldRot, inst.Rotation);

                // Go through all the vertices and change the UV coords if necessary
                List <MeshInfo> meshInfos = CollectMeshesFromDisplayable(inst.Representation);

                meshInfos.ForEach(meshInfo => {
                    if (meshInfo.coordAxis.getUVOrigin != newCoords.getUVOrigin)
                    {
                        for (int ii = 0; ii < meshInfo.vertexs.Count; ii++)
                        {
                            var vert             = meshInfo.vertexs[ii];
                            vert.TexCoord.Y      = 1f - vert.TexCoord.Y;
                            meshInfo.vertexs[ii] = vert;
                        }
                        meshInfo.coordAxis = newCoords;
                    }
                });
            }
            else
            {
                ConvOAR.Globals.log.DebugFormat("FixCoordinates. Not converting coord system. dispID={0}", inst.handle);
            }
        }
예제 #3
0
        public Promise <BScene> ConvertOarToScene(IAssetService assetService, IAssetFetcher assetFetcher)
        {
            Promise <BScene> prom = new Promise <BScene>();

            // Assemble all the parameters that loadoar takes and uses
            Dictionary <string, object> options = new Dictionary <string, object>();

            // options.Add("merge", false);
            options.Add("displacement", ConvOAR.Globals.parms.P <OMV.Vector3>("Displacement"));
            string optRotation = ConvOAR.Globals.parms.P <string>("Rotation");

            if (optRotation != null)
            {
                options.Add("rotation", float.Parse(optRotation, System.Threading.Thread.CurrentThread.CurrentCulture));
            }
            // options.Add("default-user", OMV.UUID.Random());
            // if (optSkipAssets != null) options.Add('skipAssets', true);
            // if (optForceTerrain != null) options.Add("force-terrain", true);
            // if (optNoObjects != null) options.Add("no-objects", true);
            string optSubRegion = ConvOAR.Globals.parms.P <string>("SubRegion");

            if (optSubRegion != null)
            {
                List <float> bounds = optSubRegion.Split(',').Select <string, float>(x => { return(float.Parse(x)); }).ToList();
                options.Add("bounding-origin", new OMV.Vector3(bounds[0], bounds[1], bounds[2]));
                options.Add("bounding-size", new OMV.Vector3(bounds[3] - bounds[0], bounds[4] - bounds[1], bounds[5] - bounds[2]));
            }

            // Create an OpenSimulator region and scene to load the OAR into
            string regionName = "convoar";

            if (String.IsNullOrEmpty(ConvOAR.Globals.parms.P <String>("RegionName")))
            {
                // Try to build the region name from the OAR filesname
                regionName = Path.GetFileNameWithoutExtension(ConvOAR.Globals.parms.P <string>("InputOAR"));
            }
            else
            {
                regionName = ConvOAR.Globals.parms.P <string>("RegionName");
            }
            Scene scene = CreateScene(assetService, regionName);

            // Load the archive into our scene
            ArchiveReadRequest archive = new ArchiveReadRequest(scene, ConvOAR.Globals.parms.P <string>("InputOAR"), Guid.Empty, options);

            archive.DearchiveRegion(false);

            // Convert SOGs from OAR into EntityGroups
            // ConvOAR.Globals.log.Log("Num assets = {0}", assetService.NumAssets);
            LogBProgress("Num SOGs = {0}", scene.GetSceneObjectGroups().Count);

            PrimToMesh mesher = new PrimToMesh();

            // Convert SOGs => BInstances
            Promise <BInstance> .All(
                scene.GetSceneObjectGroups().Select(sog => {
                return(ConvertSogToInstance(sog, assetFetcher, mesher));
            })
                )
            .Done(instances => {
                ConvOAR.Globals.log.DebugFormat("{0} Num instances = {1}", _logHeader, instances.ToList().Count);
                List <BInstance> instanceList = new List <BInstance>();
                instanceList.AddRange(instances);

                // Add the terrain mesh to the scene
                BInstance terrainInstance = null;
                if (ConvOAR.Globals.parms.P <bool>("AddTerrainMesh"))
                {
                    ConvOAR.Globals.log.DebugFormat("{0} Creating terrain for scene", _logHeader);
                    // instanceList.Add(ConvoarTerrain.CreateTerrainMesh(scene, mesher, assetFetcher));
                    terrainInstance = ConvoarTerrain.CreateTerrainMesh(scene, mesher, assetFetcher);
                    CoordAxis.FixCoordinates(terrainInstance, new CoordAxis(CoordAxis.RightHand_Yup | CoordAxis.UVOriginLowerLeft));
                }

                // Twist the OpenSimulator Z-up coordinate system to the OpenGL Y-up
                foreach (var inst in instanceList)
                {
                    CoordAxis.FixCoordinates(inst, new CoordAxis(CoordAxis.RightHand_Yup | CoordAxis.UVOriginLowerLeft));
                }

                // package instances into a BScene
                BScene bScene          = new BScene();
                bScene.instances       = instanceList;
                RegionInfo ri          = scene.RegionInfo;
                bScene.name            = ri.RegionName;
                bScene.terrainInstance = terrainInstance;
                bScene.attributes.Add("RegionName", ri.RegionName);
                bScene.attributes.Add("RegionSizeX", ri.RegionSizeX);
                bScene.attributes.Add("RegionSizeY", ri.RegionSizeY);
                bScene.attributes.Add("RegionSizeZ", ri.RegionSizeZ);
                bScene.attributes.Add("RegionLocX", ri.RegionLocX);
                bScene.attributes.Add("RegionLocY", ri.RegionLocY);
                bScene.attributes.Add("WorldLocX", ri.WorldLocX);
                bScene.attributes.Add("WorldLocY", ri.WorldLocY);
                bScene.attributes.Add("WaterHeight", ri.RegionSettings.WaterHeight);
                bScene.attributes.Add("DefaultLandingPorint", ri.DefaultLandingPoint);

                prom.Resolve(bScene);
            }, e => {
                ConvOAR.Globals.log.ErrorFormat("{0} failed SOG conversion: {1}", _logHeader, e);
                // prom.Reject(new Exception(String.Format("Failed conversion: {0}", e)));
            });

            return(prom);
        }
예제 #4
0
 public bool isHandednessChanging(CoordAxis nextSystem)
 {
     return((system & Handedness) != (nextSystem.system & Handedness));
 }