Example #1
0
		public static string GetSQLCreateTable(ModelRoot model, Table table)
		{
			StringBuilder sb = new StringBuilder();
			string tableName = Globals.GetTableDatabaseName(model, table);
			sb.AppendLine("if not exists(select * from sysobjects where name = '" + tableName + "' and xtype = 'U')");
			sb.AppendLine("CREATE TABLE [dbo].[" + tableName + "] (");

			bool firstLoop = true;
			foreach (Reference columnRef in table.Columns)
			{
				Column column = (Column)columnRef.Object;
				if (!firstLoop) sb.AppendLine(",");
				else firstLoop = false;
				sb.Append(AppendColumnDefinition(column, true, true));
			}
			AppendModifiedAudit(model, table, sb);
			AppendCreateAudit(model, table, sb);
			AppendTimestamp(model, table, sb);
			sb.AppendLine();
			sb.AppendLine(") ON [PRIMARY]");
			sb.AppendLine();

			return sb.ToString();

		}
			public static string GetBody(Table table, ModelRoot model)
			{
				try
				{
					List<Column> allColumns = new List<Column>();
					foreach (Column dc in table.GetColumnsFullHierarchy())
					{
						if (!(dc.DataType == System.Data.SqlDbType.Binary ||
							dc.DataType == System.Data.SqlDbType.Image ||
							dc.DataType == System.Data.SqlDbType.NText ||
							dc.DataType == System.Data.SqlDbType.Text ||
							dc.DataType == System.Data.SqlDbType.Timestamp ||
							dc.DataType == System.Data.SqlDbType.Udt ||
							dc.DataType == System.Data.SqlDbType.VarBinary ||
							dc.DataType == System.Data.SqlDbType.Variant ||
						dc.DataType == System.Data.SqlDbType.Money))
						{
							allColumns.Add(dc);
						}
					}

					if (allColumns.Count != 0)
					{
						return BuildStoredProcedure(table, model, allColumns);
					}

					return "";

				}
				catch (Exception ex)
				{
					throw new Exception(table.DatabaseName + ": Failed on generation of paging select statement", ex);
				}
			}
		public SQLSelectBusinessObjectByForeignKeyTemplate(ModelRoot model, Relation currentRelation, Table realTable)
		{
			_model = model;
			_currentRelation = currentRelation;
			_childTable = (Table)_currentRelation.ChildTableRef.Object;
			if (realTable.IsInheritedFrom(_childTable)) _childTable = realTable;
			_parentTable = (Table)_currentRelation.ParentTableRef.Object;
		}
Example #4
0
 public static string SetExistingConnection(ModelRoot root)
 {
     string connectionString = string.Empty;
     while (string.IsNullOrEmpty(connectionString))
     {
         connectionString = ChooseDatabase();
     }
     using (Transaction tx = root.Store.TransactionManager.BeginTransaction("SetConnectionString", false))
     {
         root.ConnectionString = connectionString;
         tx.Commit();
     }
     return connectionString;
 }
		private static void AppendFullTemplate(StringBuilder sb, Table table, ModelRoot model)
		{
			try
			{
				sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + GetStoredProcedureName(table, model) + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
				sb.AppendLine("	drop procedure [dbo].[" + GetStoredProcedureName(table, model) + "]");
				sb.AppendLine("GO");
				sb.AppendLine();
				sb.AppendLine("SET QUOTED_IDENTIFIER ON");
				sb.AppendLine("GO");
				sb.AppendLine("SET ANSI_NULLS ON");
				sb.AppendLine("GO");
				sb.AppendLine();
				sb.AppendLine("CREATE PROCEDURE [dbo].[" + GetStoredProcedureName(table, model) + "]");
				sb.AppendLine("(");
				sb.AppendLine(BuildParameterList(table, model));
				sb.AppendLine(")");
				sb.AppendLine("AS");
				sb.AppendLine("SET NOCOUNT OFF;");
				sb.AppendLine();
				sb.Append(SQLGeneratedBodyHelper.SQLInsertBusinessObjectBody(table, model));
				sb.AppendLine("GO");
				sb.AppendLine();
				sb.AppendLine("SET QUOTED_IDENTIFIER OFF");
				sb.AppendLine("GO");
				sb.AppendLine("SET ANSI_NULLS ON");
				sb.AppendLine("GO");
				sb.AppendLine();
				if (model.Database.GrantExecUser != string.Empty)
				{
					sb.AppendFormat("GRANT  EXECUTE  ON [dbo].[{0}]  TO [{1}]", GetStoredProcedureName(table, model), model.Database.GrantExecUser).AppendLine();
					sb.AppendLine("GO");
					sb.AppendLine();
				}

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Example #6
0
		public static string GetSQLCreateAuditTable(ModelRoot model, Table table)
		{
			StringBuilder sb = new StringBuilder();
			string tableName = "__AUDIT__" + Globals.GetTableDatabaseName(model, table);
			sb.AppendLine("if not exists(select * from sysobjects where name = '" + tableName + "' and xtype = 'U')");
			sb.AppendLine("CREATE TABLE [dbo].[" + tableName + "] (");
			sb.AppendLine("[__rowid] [INT] NOT NULL IDENTITY,");
			sb.AppendLine("[__action] [INT] NOT NULL,");
			sb.AppendLine("[__insertdate] [DATETIME] CONSTRAINT [DF__" + table.DatabaseName + "__AUDIT] DEFAULT " + (model.UseUTCTime ? "GetUTCDate()" : "GetDate()") + " NOT NULL,");
			
			ColumnCollection columnList = table.GetColumns();
			foreach (Column column in columnList)
			{				
				sb.Append(AppendColumnDefinition(column, false, false, false));
				if (columnList.IndexOf(column) < columnList.Count - 1) sb.Append(",");
				sb.AppendLine();
			}			
			sb.AppendLine(") ON [PRIMARY]");
			sb.AppendLine();
			return sb.ToString();

		}
Example #7
0
 public static string GetOrCreateConnectionString(ModelRoot root, string diagramName)
 {
     string connectionString = root.ConnectionString;
     while(string.IsNullOrEmpty(connectionString))
     {
         var dbName = string.Join("", diagramName.Split(' ')) + "Db";
         var getOrCreateConnectionDlg = new GetOrCreateConnectionForm(dbName);
         if (getOrCreateConnectionDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             switch (getOrCreateConnectionDlg.ConfigurationType)
             {
                 case ConnectionConfigurationType.CreateLocal:
                     try
                     {
                         connectionString = CreateLocalConnection(dbName);
                     }
                     catch (Exception e)
                     {
                         System.Windows.Forms.MessageBox.Show(e.Message + "\nPlease choose a connection.");
                         connectionString = ChooseDatabase();
                     }
                     break;
                 case ConnectionConfigurationType.ChooseDatabase:
                     connectionString = ChooseDatabase();
                     break;
                 case ConnectionConfigurationType.UseCustomConnection:
                     connectionString = getOrCreateConnectionDlg.ConnectionString;
                     break;
             }
         }
     }
     using (Transaction tx = root.Store.TransactionManager.BeginTransaction("SetConnectionString", false))
     {
         root.ConnectionString = connectionString;
         tx.Commit();
     }
     return connectionString;
 }
Example #8
0
 public ObjectGridJSTemplate(ModelRoot model, Table currentTable)
 {
     _model        = model;
     _currentTable = currentTable;
 }
    public DefinedStoredProcedureSelectCommandExtenderTemplate(ModelRoot model, CustomStoredProcedure currentStoredProcedure)
    {
      _model = model;
      _currentStoredProcedure = currentStoredProcedure;
		}
 public SQLSelectStoredProcedureTemplate(ModelRoot model, CustomStoredProcedure currentStoredProcedure)
 {
   _model = model;
   _currentStoredProcedure = currentStoredProcedure;
 }
		private static string BuildParameterList(Table table, ModelRoot model)
		{
			ArrayList items = new ArrayList();
			List<Column> columnList = new List<Column>();
			foreach (Column c in table.GetColumnsFullHierarchy())
				columnList.Add(c);

			for (int ii = 0; ii < columnList.Count; ii++)
			{
				Column dc = columnList[ii];
				//if (dc.Identity != IdentityTypeConstants.Database)
				items.Add(columnList[ii]);
			}

			StringBuilder output = new StringBuilder();
			for (int ii = 0; ii < items.Count; ii++)
			{
				Column dc = (Column)(items[ii]);
				output.Append("	@" + ValidationHelper.MakeDatabaseScriptIdentifier(dc.DatabaseName) + " " + dc.GetSQLDefaultType() + " = default");
				if (ii < items.Count - 1 || (table.AllowCreateAudit) || (table.AllowModifiedAudit))
					output.Append(",");
				output.AppendLine();

			}
			if (table.AllowCreateAudit)
			{
				//Create Date
				output.AppendFormat("	@{0} datetime", model.Database.CreatedDateColumnName);
				output.Append(",");
				output.AppendLine();

				//Create By
				output.AppendFormat("	@{0} varchar (50)", model.Database.CreatedByColumnName);
				if (table.AllowModifiedAudit)
					output.Append(",");
				output.AppendLine();
			}

			if (table.AllowModifiedAudit)
			{
				//Modified By
				output.AppendFormat("	@{0} varchar (50)", model.Database.ModifiedByColumnName);
				output.AppendLine();
			}

			return output.ToString();
		}
		public ObjectListPagesExtenderTemplate(ModelRoot model, Table currentTable)
    {
      _model = model;
      _currentTable = currentTable;
		}
Example #13
0
 public BusinessObjectExtenderTemplate(ModelRoot model, Table currentTable)
 {
     _model        = model;
     _currentTable = currentTable;
 }
Example #14
0
 public CreateSchemaTemplate(ModelRoot model)
 {
     _model = model;
 }
Example #15
0
 public ProxyFactoryExtenderTemplate(ModelRoot model)
 {
     _model = model;
 }
Example #16
0
        private void LoadEntityMeshes(ModelRoot exportedModel, Scene scene, VEntityLump entityLump)
        {
            foreach (var entity in entityLump.GetEntities())
            {
                var modelName = entity.GetProperty <string>("model");
                if (string.IsNullOrEmpty(modelName))
                {
                    // Only worrying about models for now
                    continue;
                    // TODO: Think about adding lights with KHR_lights_punctual
                }

                var modelResource = FileLoader.LoadFile(modelName + "_c");
                if (modelResource == null)
                {
                    continue;
                }

                // TODO: skybox/skydome

                var model    = (VModel)modelResource.DataBlock;
                var skinName = entity.GetProperty <string>("skin");
                if (skinName == "0" || skinName == "default")
                {
                    skinName = null;
                }

                var transform = EntityTransformHelper.CalculateTransformationMatrix(entity);
                // Add meshes and their skeletons
                var meshes = LoadModelMeshes(model, Path.GetFileNameWithoutExtension(modelName));
                for (var i = 0; i < meshes.Length; i++)
                {
                    var meshName = meshes[i].Name;
                    if (skinName != null)
                    {
                        meshName += "." + skinName;
                    }
                    var node = AddMeshNode(exportedModel, scene, model,
                                           meshName, meshes[i].Mesh, model.GetSkeleton(i),
                                           skinName != null ? GetSkinPathFromModel(model, skinName) : null);

                    if (node == null)
                    {
                        continue;
                    }
                    // Swap Rotate upright, scale inches to meters.
                    node.WorldMatrix = transform * TRANSFORMSOURCETOGLTF;
                }
            }

            foreach (var childEntityName in entityLump.GetChildEntityNames())
            {
                if (childEntityName == null)
                {
                    continue;
                }
                var childEntityLumpResource = FileLoader.LoadFile(childEntityName + "_c");
                if (childEntityLumpResource == null)
                {
                    continue;
                }

                var childEntityLump = (VEntityLump)childEntityLumpResource.DataBlock;
                LoadEntityMeshes(exportedModel, scene, childEntityLump);
            }
        }
        public static ModelRoot RawMeshesToGLTF(List <RawMeshContainer> meshes, RawArmature Rig)
        {
            var model = ModelRoot.CreateModel();
            var mat   = model.CreateMaterial("Default");

            mat.WithPBRMetallicRoughness().WithDefault();
            mat.DoubleSided = true;
            List <Skin> skins = new List <Skin>();

            if (Rig != null)
            {
                var skin = model.CreateSkin();
                skin.BindJoints(RIG.ExportNodes(ref model, Rig).Values.ToArray());
                skins.Add(skin);
            }

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            foreach (var mesh in meshes)
            {
                for (int i = 0; i < mesh.vertices.Length; i++)
                {
                    bw.Write(mesh.vertices[i].X);
                    bw.Write(mesh.vertices[i].Y);
                    bw.Write(mesh.vertices[i].Z);
                }
                for (int i = 0; i < mesh.normals.Length; i++)
                {
                    bw.Write(mesh.normals[i].X);
                    bw.Write(mesh.normals[i].Y);
                    bw.Write(mesh.normals[i].Z);
                }
                for (int i = 0; i < mesh.tangents.Length; i++)
                {
                    bw.Write(mesh.tangents[i].X);
                    bw.Write(mesh.tangents[i].Y);
                    bw.Write(mesh.tangents[i].Z);
                    bw.Write(mesh.tangents[i].W);
                }
                for (int i = 0; i < mesh.colors.Length; i++)
                {
                    bw.Write(mesh.colors[i].X);
                    bw.Write(mesh.colors[i].Y);
                    bw.Write(mesh.colors[i].Z);
                    bw.Write(mesh.colors[i].W);
                }
                for (int i = 0; i < mesh.tx0coords.Length; i++)
                {
                    bw.Write(mesh.tx0coords[i].X);
                    bw.Write(mesh.tx0coords[i].Y);
                }
                for (int i = 0; i < mesh.tx1coords.Length; i++)
                {
                    bw.Write(mesh.tx1coords[i].X);
                    bw.Write(mesh.tx1coords[i].Y);
                }

                if (mesh.weightcount > 0)
                {
                    if (Rig != null)
                    {
                        for (int i = 0; i < mesh.vertices.Length; i++)
                        {
                            bw.Write(mesh.boneindices[i, 0]);
                            bw.Write(mesh.boneindices[i, 1]);
                            bw.Write(mesh.boneindices[i, 2]);
                            bw.Write(mesh.boneindices[i, 3]);
                        }
                        for (int i = 0; i < mesh.vertices.Length; i++)
                        {
                            bw.Write(mesh.weights[i, 0]);
                            bw.Write(mesh.weights[i, 1]);
                            bw.Write(mesh.weights[i, 2]);
                            bw.Write(mesh.weights[i, 3]);
                        }
                        if (mesh.weightcount > 4)
                        {
                            for (int i = 0; i < mesh.vertices.Length; i++)
                            {
                                bw.Write(mesh.boneindices[i, 4]);
                                bw.Write(mesh.boneindices[i, 5]);
                                bw.Write(mesh.boneindices[i, 6]);
                                bw.Write(mesh.boneindices[i, 7]);
                            }
                            for (int i = 0; i < mesh.vertices.Length; i++)
                            {
                                bw.Write(mesh.weights[i, 4]);
                                bw.Write(mesh.weights[i, 5]);
                                bw.Write(mesh.weights[i, 6]);
                                bw.Write(mesh.weights[i, 7]);
                            }
                        }
                    }
                }
                for (int i = 0; i < mesh.indices.Length; i += 3)
                {
                    bw.Write(Convert.ToUInt16(mesh.indices[i + 1]));
                    bw.Write(Convert.ToUInt16(mesh.indices[i + 0]));
                    bw.Write(Convert.ToUInt16(mesh.indices[i + 2]));
                }
                if (mesh.extraExist)
                {
                    for (int i = 0; i < mesh.vertices.Length; i++)
                    {
                        bw.Write(mesh.extradata[i].X);
                        bw.Write(mesh.extradata[i].Y);
                        bw.Write(mesh.extradata[i].Z);
                    }
                }
            }
            var buffer         = model.UseBuffer(ms.ToArray());
            int BuffViewoffset = 0;

            foreach (var mesh in meshes)
            {
                var mes  = model.CreateMesh(mesh.name);
                var prim = mes.CreatePrimitive();
                prim.Material = mat;
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.vertices.Length * 12);
                    acc.SetData(buff, 0, mesh.vertices.Length, DimensionType.VEC3, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("POSITION", acc);
                    BuffViewoffset += mesh.vertices.Length * 12;
                }
                if (mesh.normals.Length > 0)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.normals.Length * 12);
                    acc.SetData(buff, 0, mesh.normals.Length, DimensionType.VEC3, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("NORMAL", acc);
                    BuffViewoffset += mesh.normals.Length * 12;
                }
                if (mesh.tangents.Length > 0)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.tangents.Length * 16);
                    acc.SetData(buff, 0, mesh.tangents.Length, DimensionType.VEC4, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("TANGENT", acc);
                    BuffViewoffset += mesh.tangents.Length * 16;
                }
                if (mesh.colors.Length > 0)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.colors.Length * 16);
                    acc.SetData(buff, 0, mesh.colors.Length, DimensionType.VEC4, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("COLOR_0", acc);
                    BuffViewoffset += mesh.colors.Length * 16;
                }
                if (mesh.tx0coords.Length > 0)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.tx0coords.Length * 8);
                    acc.SetData(buff, 0, mesh.tx0coords.Length, DimensionType.VEC2, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("TEXCOORD_0", acc);
                    BuffViewoffset += mesh.tx0coords.Length * 8;
                }
                if (mesh.tx1coords.Length > 0)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.tx1coords.Length * 8);
                    acc.SetData(buff, 0, mesh.tx1coords.Length, DimensionType.VEC2, EncodingType.FLOAT, false);
                    prim.SetVertexAccessor("TEXCOORD_1", acc);
                    BuffViewoffset += mesh.tx1coords.Length * 8;
                }
                if (mesh.weightcount > 0)
                {
                    if (Rig != null)
                    {
                        {
                            var acc  = model.CreateAccessor();
                            var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.vertices.Length * 8);
                            acc.SetData(buff, 0, mesh.vertices.Length, DimensionType.VEC4, EncodingType.UNSIGNED_SHORT, false);
                            prim.SetVertexAccessor("JOINTS_0", acc);
                            BuffViewoffset += mesh.vertices.Length * 8;
                        }
                        {
                            var acc  = model.CreateAccessor();
                            var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.vertices.Length * 16);
                            acc.SetData(buff, 0, mesh.vertices.Length, DimensionType.VEC4, EncodingType.FLOAT, false);
                            prim.SetVertexAccessor("WEIGHTS_0", acc);
                            BuffViewoffset += mesh.vertices.Length * 16;
                        }
                        if (mesh.weightcount > 4)
                        {
                            {
                                var acc  = model.CreateAccessor();
                                var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.vertices.Length * 8);
                                acc.SetData(buff, 0, mesh.vertices.Length, DimensionType.VEC4, EncodingType.UNSIGNED_SHORT, false);
                                prim.SetVertexAccessor("JOINTS_1", acc);
                                BuffViewoffset += mesh.vertices.Length * 8;
                            }
                            {
                                var acc  = model.CreateAccessor();
                                var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.vertices.Length * 16);
                                acc.SetData(buff, 0, mesh.vertices.Length, DimensionType.VEC4, EncodingType.FLOAT, false);
                                prim.SetVertexAccessor("WEIGHTS_1", acc);
                                BuffViewoffset += mesh.vertices.Length * 16;
                            }
                        }
                    }
                }
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.indices.Length * 2);
                    acc.SetData(buff, 0, mesh.indices.Length, DimensionType.SCALAR, EncodingType.UNSIGNED_SHORT, false);
                    prim.SetIndexAccessor(acc);
                    BuffViewoffset += mesh.indices.Length * 2;
                }
                var nod = model.UseScene(0).CreateNode(mesh.name);
                nod.Mesh = mes;
                if (Rig != null && mesh.weightcount > 0)
                {
                    nod.Skin = skins[0];
                }

                if (mesh.extraExist)
                {
                    string[] arr = { "GarmentSupport" };
                    var      obj = new { appNames = mesh.appNames, materialNames = mesh.materialNames, targetNames = arr };
                    mes.Extras = SharpGLTF.IO.JsonContent.Serialize(obj);
                }
                else
                {
                    var obj = new { appNames = mesh.appNames, materialNames = mesh.materialNames };
                    mes.Extras = SharpGLTF.IO.JsonContent.Serialize(obj);
                }
                if (mesh.extraExist)
                {
                    var acc  = model.CreateAccessor();
                    var buff = model.UseBufferView(buffer, BuffViewoffset, mesh.extradata.Length * 12);
                    acc.SetData(buff, 0, mesh.extradata.Length, DimensionType.VEC3, EncodingType.FLOAT, false);
                    var dict = new Dictionary <string, Accessor>();
                    dict.Add("POSITION", acc);
                    prim.SetMorphTargetAccessors(0, dict);
                    BuffViewoffset += mesh.extradata.Length * 12;
                }
            }
            model.UseScene(0).Name = "Scene";
            model.DefaultScene     = model.UseScene(0);
            model.MergeBuffers();
            return(model);
        }
        public bool ExportMultiMeshWithRig(List <Stream> meshStreamS, List <Stream> rigStreamS, FileInfo outfile, bool LodFilter = true, bool isGLBinary = true)
        {
            List <RawArmature> Rigs = new List <RawArmature>();

            rigStreamS = rigStreamS.OrderByDescending(r => r.Length).ToList();  // not so smart hacky method to get bodybase rigs on top/ orderby descending
            for (int r = 0; r < rigStreamS.Count; r++)
            {
                RawArmature Rig = _rig.ProcessRig(rigStreamS[r]);
                Rigs.Add(Rig);
            }
            RawArmature expRig = RIG.CombineRigs(Rigs);

            List <RawMeshContainer> expMeshes = new List <RawMeshContainer>();

            for (int m = 0; m < meshStreamS.Count; m++)
            {
                var cr2w = _wolvenkitFileService.TryReadRED4File(meshStreamS[m]);
                if (cr2w == null || !cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().Any() || !cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().Any())
                {
                    continue;
                }

                MemoryStream ms       = GetMeshBufferStream(meshStreamS[m], cr2w);
                MeshesInfo   meshinfo = GetMeshesinfo(cr2w);

                MeshBones bones = new MeshBones();

                CMesh cmesh = cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().First();

                if (cmesh.BoneNames.Count != 0)    // for rigid meshes
                {
                    bones.Names     = RIG.GetboneNames(cr2w);
                    bones.WorldPosn = GetMeshBonesPosn(cr2w);
                }

                List <RawMeshContainer> Meshes = ContainRawMesh(ms, meshinfo, LodFilter);

                for (int i = 0; i < Meshes.Count; i++)
                {
                    Meshes[i].name = m + "_" + Meshes[i].name;
                    if (cmesh.BoneNames.Count == 0)    // for rigid meshes
                    {
                        Meshes[i].weightcount = 0;
                    }
                }
                UpdateMeshJoints(ref Meshes, expRig, bones);

                expMeshes.AddRange(Meshes);
            }
            ModelRoot model = RawMeshesToGLTF(expMeshes, expRig);

            if (isGLBinary)
            {
                model.SaveGLB(outfile.FullName);
            }
            else
            {
                model.SaveGLTF(outfile.FullName);
            }

            for (int i = 0; i < meshStreamS.Count; i++)
            {
                meshStreamS[i].Dispose();
                meshStreamS[i].Close();
            }
            for (int i = 0; i < rigStreamS.Count; i++)
            {
                rigStreamS[i].Dispose();
                rigStreamS[i].Close();
            }
            return(true);
        }
        public bool ExportMesh(Stream meshStream, FileInfo outfile, bool LodFilter = true, bool isGLBinary = true)
        {
            var cr2w = _wolvenkitFileService.TryReadRED4File(meshStream);

            if (cr2w == null || !cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().Any())
            {
                return(false);
            }

            if (!cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().Any())
            {
                return(WriteFakeMeshToFile());
            }

            MeshBones meshBones = new MeshBones();

            meshBones.boneCount = cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().First().BoneNames.Count;

            if (meshBones.boneCount != 0)    // for rigid meshes
            {
                meshBones.Names     = RIG.GetboneNames(cr2w);
                meshBones.WorldPosn = GetMeshBonesPosn(cr2w);
            }
            RawArmature Rig = GetNonParentedRig(meshBones);

            MemoryStream ms = GetMeshBufferStream(meshStream, cr2w);

            MeshesInfo meshinfo = GetMeshesinfo(cr2w);

            List <RawMeshContainer> expMeshes = ContainRawMesh(ms, meshinfo, LodFilter);

            if (meshBones.boneCount == 0)    // for rigid meshes
            {
                for (int i = 0; i < expMeshes.Count; i++)
                {
                    expMeshes[i].weightcount = 0;
                }
            }
            UpdateMeshJoints(ref expMeshes, Rig, meshBones);

            ModelRoot model = RawMeshesToGLTF(expMeshes, Rig);

            WriteMeshToFile();

            meshStream.Dispose();
            meshStream.Close();

            return(true);

            bool WriteFakeMeshToFile()
            {
                if (WolvenTesting.IsTesting)
                {
                    return(true);
                }
                if (isGLBinary)
                {
                    ModelRoot.CreateModel().SaveGLB(outfile.FullName);
                }
                else
                {
                    ModelRoot.CreateModel().SaveGLTF(outfile.FullName);
                }

                return(true);
            }

            void WriteMeshToFile()
            {
                if (WolvenTesting.IsTesting)
                {
                    return;
                }

                if (isGLBinary)
                {
                    model.SaveGLB(outfile.FullName);
                }
                else
                {
                    model.SaveGLTF(outfile.FullName);
                }
            }
        }
 public IncludeTreeLINQExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
    public DefinedViewSelectCommandExtenderTemplate(ModelRoot model, CustomView currentView)
    {
      _model = model;
      _currentView = currentView;
		}
Example #22
0
 public SQLStoredProcedureTableAllTemplate(ModelRoot model, Table table, bool useSingleFile)
     : base(model)
 {
     _table         = table;
     _useSingleFile = useSingleFile;
 }
		public static string GetParentStoredProcedureName(Table table, ModelRoot model)
		{
			if (table.ParentTable == null) return "";
			else return "gen_" + Globals.GetPascalName(model, table.ParentTable) + "Insert";
		}
Example #24
0
 public SQLHelperExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
		public SQLSelectBusinessObjectTemplate(ModelRoot model, Table currentTable)
    {
      _model = model;
			_currentTable = currentTable;
		}
Example #26
0
 public BusinessViewExtenderTemplate(ModelRoot model, CustomView currentView)
 {
     _model       = model;
     _currentView = currentView;
 }
		public DomainComponentCollectionExtenderTemplate(ModelRoot model, TableComponent currentComponent)
    {
      _model = model;
      _currentComponent = currentComponent;
		}
 public SQLSelectComponentByModifiedDateTemplate(ModelRoot model, TableComponent currentComponent)
 {
     _model            = model;
     _currentComponent = currentComponent;
 }
 protected bool Equals(ModelRoot other)
 {
     return IntProp == other.IntProp
                     && DateTime.Equals(other.DateTime)
                     && ModelEnum == other.ModelEnum
                     && string.Equals(StrProp, other.StrProp)
                     && Equals(SubModel, other.SubModel);
 }
 public ComplexTypesSPGeneratedTemplate(ModelRoot model, CustomStoredProcedure item)
     : base(model)
 {
     _item = item;
 }
 public ComplexTypesFuncGeneratedTemplate(ModelRoot model, Function item)
     : base(model)
 {
     _item = item;
 }
		public DataServiceJSPageHelperTemplate(ModelRoot model)
    {
      _model = model;      
		}
 public ContextStartupGeneratedTemplate(ModelRoot model)
     : base(model)
 {
 }
		public DomainObjectGeneratedTemplate(ModelRoot model, Table currentTable)
		{
			_model = model;
			_currentTable = currentTable;
		}
 public ContextExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
 public DatasiteOverviewTemplate(ModelRoot model, string templateLocation)
     : base(model)
 {
     _templateLocation = templateLocation;
 }
		public ObjectServiceExtenderTemplate(ModelRoot model, Table table)
		{
			_model = model;
			_currentTable = table;
		}
Example #38
0
 public DomainObjectExtenderTemplate(ModelRoot model, Table currentTable)
 {
     _model        = model;
     _currentTable = currentTable;
 }
		public BusinessSQLHelperExtenderTemplate(ModelRoot model)
    {
      _model = model;      
		}
Example #40
0
 public LINQGeneratedTemplate(ModelRoot model)
     : base(model)
 {
 }
		public ServiceWebConfigTemplate(ModelRoot model)
		{
			_model = model;
		}
 public ViewEntityExtenderTemplate(ModelRoot model, CustomView table)
     : base(model)
 {
     _currentView = table;
 }
    public BusinessStoredProcedureExtenderTemplate(ModelRoot model, CustomStoredProcedure currentStoredProcedure)
    {
      _model = model;
      _currentStoredProcedure = currentStoredProcedure;
		}
 public SQLSelectViewByAndTemplate(ModelRoot model, CustomView currentView)
 {
     _model       = model;
     _currentView = currentView;
 }
		private static string GetStoredProcedureName(Table table, ModelRoot model)
		{
			return "gen_" + Globals.GetPascalName(model, table) + "Insert";
		}
 private IContentContainer ReadStream(Stream stream)
 {
     return(Read(ModelRoot.Read(stream, _readSettings)));
 }
		public SQLInsertBusinessObjectTemplate(ModelRoot model, Table currentTable)
		{
			_model = model;
			table = currentTable;
		}
Example #48
0
        public void ExportActiveDesign(Application application, AssemblyDocument assemblyDocument, string filePath, bool glb, bool checkMaterialsChecked, bool checkFaceMaterials, bool checkHiddenChecked, decimal numericToleranceValue,
                                       bool includeSynthChecked)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                exportTolerance         = numericToleranceValue;
                exportHidden            = checkHiddenChecked;
                exportFaceMaterials     = checkFaceMaterials;
                exportMaterials         = checkMaterialsChecked;
                includeSynthData        = includeSynthChecked;
                materialCache           = new Dictionary <string, MaterialBuilder>();
                massPropertiesMap       = new Dictionary <string, MassProperties>();
                jointedComponentUUIDMap = new Dictionary <string, string>();
                allComponentRealNames   = new Dictionary <string, string>();
                warnings = new List <string>();

                progressTotal = 2 + assemblyDocument.AllReferencedDocuments.Count;
                progressBar   = application.CreateProgressBar(false, progressTotal, "Exporting " + assemblyDocument.DisplayName + " to glTF");

                progressBar.Message = "Preparing for export...";

                var sceneBuilder = ExportScene(application, assemblyDocument);

                progressBar.Message = "Exporting joints...";
                progressBar.UpdateProgress();

                var modelRoot = sceneBuilder.ToSchema2();

                if (includeSynthData)
                {
                    // TODO: Figure out a more elegant solution for extras. This is only needed because sharpGLTF (this version anyways) doesn't support writing extras so we need to do it manually.
                    var dictionary = modelRoot.WriteToDictionary("temp");
                    // ReSharper disable once AssignNullToNotNullAttribute
                    var jsonString   = Encoding.ASCII.GetString(dictionary["temp.gltf"].Array);
                    var parsedJToken = (JObject)JToken.ReadFrom(new JsonTextReader(new StringReader(jsonString)));

                    var rootExtras = new JObject();
                    rootExtras.Add("joints", ExportJoints(FindJointsScene(assemblyDocument)));

                    parsedJToken.Add("extras", rootExtras);

                    try
                    {
                        ExportMassProperties((JArray)parsedJToken.GetValue("meshes"));
                    }
                    catch { }

                    ExportJointedCompUUID((JArray)parsedJToken.GetValue("nodes"));

                    try
                    {
                        var asset = (JObject)parsedJToken.GetValue("asset");
                        asset.Property("generator").Value = appName;
                    }
                    catch { }

                    var readSettings = new ReadSettings();
                    readSettings.FileReader = assetFileName => dictionary[assetFileName];
                    modelRoot = ModelRoot.ReadGLTF(new MemoryStream(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(parsedJToken))), readSettings);
                }

                progressBar.Message = "Saving file...";
                progressBar.UpdateProgress();

                if (glb)
                {
                    modelRoot.SaveGLB(filePath);
                }
                else
                {
                    modelRoot.SaveGLTF(filePath);
                }


                Debug.WriteLine("-----gltf export warnings-----");
                foreach (var warning in warnings)
                {
                    Debug.WriteLine(warning);
                }

                Debug.WriteLine("----------");
                progressBar.Close();

                sw.Stop();

                MessageBox.Show("glTF export completed successfully.\nFile saved to: " + filePath);
            }
            catch
            {
                MessageBox.Show("glTF export failed!\nPlease contact [email protected] to report this bug.");
            }
        }
		public SQLSelectComponentByPrimaryKeyTemplate(ModelRoot model, TableComponent currentComponent)
		{
			_model = model;
			_currentComponent = currentComponent;
		}
 public ZeroInstallSQL_UpdateTemplate(ModelRoot model, Table currentTable)
 {
     _model        = model;
     _currentTable = currentTable;
 }
Example #51
0
		public ObjectGridJSTemplate(ModelRoot model, Table currentTable)
		{
			_model = model;
			_currentTable = currentTable;
		}
 public SQLSelectRetrieveRuleTemplate(ModelRoot model, CustomRetrieveRule currentRule)
 {
     _model           = model;
     _currentRule     = currentRule;
     this.ParentTable = (Table)currentRule.ParentTableRef.Object;
 }
		public BusinessViewCollectionGeneratedTemplate(ModelRoot model, CustomView currentView)
		{
			_model = model;
			_currentView = currentView;
		}
Example #54
0
 public static string GetTableDatabaseName(ModelRoot model, Table table)
 {
     return(table.DatabaseName);
 }
		public DefinedSelectCommandExtenderTemplate(ModelRoot model, CustomRetrieveRule currentRule)
    {
      _model = model;
      _currentRule = currentRule;
      this.ParentTable = (Table)currentRule.ParentTableRef.Object;
		}
Example #56
0
        public static SceneBuilder Load(string filePath, ReadSettings settings = null)
        {
            var mdl = ModelRoot.Load(filePath, settings);

            return(mdl.DefaultScene.ToSceneBuilder());
        }
 public BusinessStoredProcedureCollectionGeneratedTemplate(ModelRoot model, CustomStoredProcedure currentStoredProcedure)
 {
   _model = model;
   _currentStoredProcedure = currentStoredProcedure;
 }
Example #58
0
 public HelperGeneratedTemplate(ModelRoot model)
     : base(model)
 {
 }
		public DataServiceGlobalModuleASAXTemplate(ModelRoot model)
    {
      _model = model;      
		}
 public AuditEntityGeneratedTemplate(ModelRoot model, Table currentTable)
     : base(model)
 {
     _model = model;
     _item  = currentTable;
 }