Exemplo n.º 1
0
        public Package CreatePackage(ExportResult res, string baseDir, PackagerParams packagerParams)
        {
            string dirName = packagerParams.Direct ? baseDir : Path.Combine(baseDir, UUID.Random().ToString());

            Directory.CreateDirectory(dirName);

            List <string> objectFiles = new List <string>();

            foreach (var bytes in res.FaceBytes)
            {
                string filePath = Path.Combine(dirName, UUID.Random() + ".js");
                File.WriteAllBytes(filePath, bytes);

                objectFiles.Add(Path.GetFileName(filePath));
            }

            foreach (var img in res.TextureFiles)
            {
                var destImgPath = Path.Combine(dirName, Path.GetFileName(img));
                if (File.Exists(destImgPath))
                {
                    File.Delete(destImgPath);
                }

                File.Move(img, destImgPath);
            }

            List <object> offsetList = new List <object>();

            foreach (var dispInfo in res.BaseObjects)
            {
                offsetList.Add(new
                {
                    positionOffset = new float[] { dispInfo.OffsetPosition.X, dispInfo.OffsetPosition.Y, dispInfo.OffsetPosition.Z },
                    rotationOffset = new float[] { dispInfo.OffsetRotation.X, dispInfo.OffsetRotation.Y, dispInfo.OffsetRotation.Z, dispInfo.OffsetRotation.W },
                    scale          = new float[] { dispInfo.Scale.X, dispInfo.Scale.Y, dispInfo.Scale.Z },
                    isRoot         = dispInfo.IsRootPrim
                });
            }


            var summaryFile = new
            {
                objectName    = res.ObjectName,
                creatorName   = res.CreatorName,
                objectFiles   = objectFiles,
                objectOffsets = offsetList.ToArray()
            };

            string summary = JsonSerializer.SerializeToString(summaryFile);

            byte[] summaryBytes = Encoding.UTF8.GetBytes(summary);
            File.WriteAllBytes(Path.Combine(dirName, "summary.js"), summaryBytes);

            return(new Package {
                Path = dirName
            });
        }
        public ExportResult Export(PrimDisplayData data)
        {
            Dictionary <UUID, TrackedTexture> materialTracker = new Dictionary <UUID, TrackedTexture>();
            List <string> fileRecord = new List <string>();
            string        tempPath   = Path.GetTempPath();

            ExportResult result = ExportSingle(data, materialTracker, UUID.Random(), "png", fileRecord, tempPath);

            result.TextureFiles = fileRecord;

            return(result);
        }
        private ExportResult ExportSingle(PrimDisplayData data, Dictionary <UUID, TrackedTexture> materialTracker, UUID index,
                                          string materialType, List <string> textureFileRecord, string tempPath)
        {
            ExportResult result = new ExportResult();

            List <OpenMetaverse.Primitive.TextureEntryFace> materials;
            string jsonString = this.SerializeCombinedFaces(index, data, out materials, materialTracker, materialType, textureFileRecord, tempPath);

            result.FaceBytes = new List <byte[]>();
            result.FaceBytes.Add(Encoding.UTF8.GetBytes(jsonString));

            result.BaseObjects.Add(data);

            return(result);
        }
        public ExportResult Export(GroupDisplayData datas)
        {
            ExportResult result = new ExportResult();
            Dictionary <UUID, TrackedTexture> materialTracker = new Dictionary <UUID, TrackedTexture>();
            string tempPath = Path.GetTempPath();

            foreach (var data in datas.Prims)
            {
                result.Combine(ExportSingle(data, materialTracker, UUID.Random(), "png", result.TextureFiles, tempPath));
            }

            result.ObjectName  = datas.ObjectName;
            result.CreatorName = datas.CreatorName;

            return(result);
        }
Exemplo n.º 5
0
        private static ExportResult PackageResult(string objectName, string creatorName, BabylonOutputs outputs, List <object> prims)
        {
            ExportResult result = new ExportResult();

            result.ObjectName  = objectName;
            result.CreatorName = creatorName;

            var babylonFile = new
            {
                materials      = outputs.Materials.Values,
                multiMaterials = outputs.MultiMaterials.Values,
                meshes         = prims
            };

            result.FaceBytes.Add(Encoding.UTF8.GetBytes(JsonSerializer.SerializeToString(babylonFile)));
            result.TextureFiles = outputs.TextureFiles;

            return(result);
        }
Exemplo n.º 6
0
        public Package CreatePackage(ExportResult res, string baseDir, PackagerParams packagerParams)
        {
            string dirName = packagerParams.Direct ? baseDir : Path.Combine(baseDir, UUID.Random().ToString());

            Directory.CreateDirectory(dirName);

            //write the object
            File.WriteAllBytes(Path.Combine(dirName, "object.babylon"), res.FaceBytes[0]);

            //write the manifest
            var manifest = new
            {
                version               = 1,
                enableSceneOffline    = true,
                enableTexturesOffline = true
            };

            using (FileStream stream = File.OpenWrite(Path.Combine(dirName, "object.babylon.manifest")))
            {
                JsonSerializer.SerializeToStream(manifest, stream);
            }

            //textures..
            foreach (var img in res.TextureFiles)
            {
                var destImgPath = Path.Combine(dirName, Path.GetFileName(img));
                if (File.Exists(destImgPath))
                {
                    File.Delete(destImgPath);
                }

                File.Move(img, destImgPath);
            }

            return(new Package {
                Path = dirName
            });
        }
Exemplo n.º 7
0
 public void Combine(ExportResult other)
 {
     this.FaceBytes.AddRange(other.FaceBytes);
     this.TextureFiles.AddRange(other.TextureFiles);
     this.BaseObjects.AddRange(other.BaseObjects);
 }
        private static ExportResult PackageResult(string objectName, string creatorName, BabylonFlatBufferOutputs outputs, List <Mesh> prims)
        {
            ExportResult result = new ExportResult();

            result.ObjectName  = objectName;
            result.CreatorName = creatorName;

            FlatBufferBuilder builder = new FlatBufferBuilder(2048);

            List <Offset <BabylonFlatBuffers.Material> > materialOffsets = new List <Offset <Material> >();

            foreach (var mat in outputs.Materials.Values)
            {
                var id          = builder.CreateString(mat.Id);
                var name        = builder.CreateString(mat.Name);
                var color       = BabylonFlatBuffers.Material.CreateColorVector(builder, mat.Color);
                var textureName = builder.CreateString(mat.DiffuseTexture.Name);
                var texture     = BabylonFlatBuffers.Texture.CreateTexture(builder, textureName, mat.DiffuseTexture.HasAlpha);

                var outMat = BabylonFlatBuffers.Material.CreateMaterial(builder, id, name, color, mat.ShinyPercent,
                                                                        mat.Alpha, texture);
                materialOffsets.Add(outMat);
            }


            List <Offset <BabylonFlatBuffers.MultiMaterial> > multiMaterialOffsets = new List <Offset <BabylonFlatBuffers.MultiMaterial> >();

            foreach (var mat in outputs.MultiMaterials.Values)
            {
                var id   = builder.CreateString(mat.Id);
                var name = builder.CreateString(mat.Name);

                List <StringOffset> materialIds = new List <StringOffset>();
                foreach (var matId in mat.MaterialsList)
                {
                    materialIds.Add(builder.CreateString(matId));
                }

                var matList = BabylonFlatBuffers.MultiMaterial.CreateMaterialsListVector(builder, materialIds.ToArray());
                var outMat  = BabylonFlatBuffers.MultiMaterial.CreateMultiMaterial(builder, id, name, matList);
                multiMaterialOffsets.Add(outMat);
            }


            List <Offset <BabylonFlatBuffers.Mesh> > meshOffsets = new List <Offset <BabylonFlatBuffers.Mesh> >();

            foreach (var mesh in prims)
            {
                var id                 = builder.CreateString(mesh.Id);
                var name               = builder.CreateString(mesh.Name);
                var parentId           = builder.CreateString(mesh.ParentId);
                var materialId         = builder.CreateString(mesh.MaterialId);
                var position           = BabylonFlatBuffers.Mesh.CreatePositionVector(builder, mesh.Position);
                var rotationQuaternion = BabylonFlatBuffers.Mesh.CreateRotationQuaternionVector(builder,
                                                                                                mesh.RotationQuaternion);
                var scaling   = BabylonFlatBuffers.Mesh.CreateScalingVector(builder, mesh.Scaling);
                var positions = BabylonFlatBuffers.Mesh.CreatePositionsVector(builder, mesh.Positions.ToArray());
                var normals   = BabylonFlatBuffers.Mesh.CreateNormalsVector(builder, mesh.Normals.ToArray());
                var uvs       = BabylonFlatBuffers.Mesh.CreateUvsVector(builder, mesh.UVs.ToArray());
                var indices   = BabylonFlatBuffers.Mesh.CreateIndicesVector(builder, mesh.Indices.ToArray());

                var submeshList = new List <Offset <BabylonFlatBuffers.SubMesh> >();
                foreach (var submesh in mesh.Submeshes)
                {
                    var submeshOff = BabylonFlatBuffers.SubMesh.CreateSubMesh(builder, submesh.MaterialIndex,
                                                                              submesh.VerticesStart, submesh.VerticesCount, submesh.IndexStart, submesh.IndexCount);
                    submeshList.Add(submeshOff);
                }

                var submeshes = BabylonFlatBuffers.Mesh.CreateSubmeshesVector(builder, submeshList.ToArray());

                var outMesh = BabylonFlatBuffers.Mesh.CreateMesh(builder, id, name, parentId, materialId,
                                                                 position, rotationQuaternion, scaling, positions, normals, uvs, indices, submeshes);

                meshOffsets.Add(outMesh);
            }

            var materialsVector      = BabylonFlatBuffers.BabylonFileFlatbuffer.CreateMaterialsVector(builder, materialOffsets.ToArray());
            var multiMaterialsVector = BabylonFlatBuffers.BabylonFileFlatbuffer.CreateMultiMaterialsVector(builder, multiMaterialOffsets.ToArray());
            var meshesVector         = BabylonFlatBuffers.BabylonFileFlatbuffer.CreateMeshesVector(builder,
                                                                                                   meshOffsets.ToArray());

            var offset = BabylonFlatBuffers.BabylonFileFlatbuffer.CreateBabylonFileFlatbuffer(builder, materialsVector,
                                                                                              multiMaterialsVector, meshesVector);


            BabylonFlatBuffers.BabylonFileFlatbuffer.FinishBabylonFileFlatbufferBuffer(builder, offset);
            result.FaceBlob = new Tuple <byte[], int, int>(builder.DataBuffer.Data, builder.DataBuffer.Position, builder.DataBuffer.Length);

            return(result);
        }