public void BakeIntoMesh(DocumentInstance document, UndoMultiAction undoMultiAction)
        {
            var mesh = Parent as Component_Mesh;

            if (mesh != null)
            {
                bool meshWasEnabled = mesh.Enabled;
                try
                {
                    //disable mesh
                    mesh.Enabled = false;

                    //convert mesh geometries
                    bool needUndoForNextActions = true;
                    ConvertProceduralMeshGeometries(document, mesh, needUndoForNextActions ? undoMultiAction : null, ref needUndoForNextActions);

                    var undoMultiAction2 = needUndoForNextActions ? undoMultiAction : null;
                    OnBakeIntoMesh(document, undoMultiAction2);
                    BakeIntoMeshEvent?.Invoke(this, document, undoMultiAction2);
                }
                finally
                {
                    //enable mesh
                    mesh.Enabled = meshWasEnabled;
                }
            }
        }
Exemple #2
0
        public virtual void Generate(DocumentInstance document)
        {
            var scene = FindParent <Component_Scene>();

            if (scene == null)
            {
                return;
            }

            TemplateData templateData = null;

            GetTemplateData?.Invoke(this, ref templateData);
            if (templateData == null)
            {
                templateData = GetTemplateDataDefault();
            }

            var randomizer = new Random(Seed);

            var terrain        = scene.GetComponent <Component_Terrain>(true);
            var groupOfObjects = scene.GetComponent <Component_GroupOfObjects>(true);

            //disable components before update
            if (terrain != null)
            {
                terrain.Enabled = false;
            }
            if (groupOfObjects != null)
            {
                groupOfObjects.Enabled = false;
            }

            //update terrain

            if (terrain == null)
            {
                terrain      = scene.CreateComponent <Component_Terrain>(enabled: false);
                terrain.Name = "Terrain";
            }

            terrain.HorizontalSize = Size;
            //terrain.Position = new Vector3( -terrain.HorizontalSize.Value / 2, -terrain.HorizontalSize.Value / 2, 0 );
            terrain.Material = templateData.TerrainMaterial;

            var heightRange   = HeightRange.Value;
            var heightmapSize = terrain.GetHeightmapSizeInteger();

            //update terrain heights
            {
                var globalScale = 3.0;

                var functions = new (Radian angle, double scale)[] {
Exemple #3
0
        private ICollection <UDSDocument> UpdateDocumentsByType(Database db, Guid udsId, Document model, UDSRelations existingRels, UDSDocumentType docType, Action <Guid> detachAction)
        {
            string deleteAllSQL  = string.Format(@"delete from {0}.{1} where {2}=@0 and DocumentType=@1", _builder.DbSchema, _builder.UDSDocumentsTableName, UDSTableBuilder.UDSFK);
            string deleteItemSQL = string.Format(@"delete from {0}.{1} where {2}=@0 and DocumentType=@1 and {3}=@2", _builder.DbSchema, _builder.UDSDocumentsTableName,
                                                 UDSTableBuilder.UDSFK, UDSTableBuilder.UDSDocumentsFK);

            List <UDSDocument> documents = new List <UDSDocument>();

            if (model != null && model.Instances != null)
            {
                //situazione db
                IEnumerable <Guid> existings = existingRels.Documents.Where(p => p.DocumentType == (short)docType).Select(p => p.IdDocument);

                //elimino gli elementi per l'aggiornamento
                db.Execute(deleteAllSQL, udsId, docType);

                //elementi da aggiungere
                DocumentInstance instance     = model.Instances.First();
                Guid             idDocument   = Guid.Parse(instance.StoredChainId);
                string           documentName = instance.DocumentName;
                if (string.IsNullOrEmpty(documentName) && docType == UDSDocumentType.Document)
                {
                    documentName = existingRels.Documents.SingleOrDefault(f => f.IdDocument == idDocument)?.DocumentName;
                }
                UDSDocument doc = new UDSDocument()
                {
                    UDSDocumentId = Guid.NewGuid(),
                    UDSId         = udsId,
                    IdDocument    = idDocument,
                    DocumentName  = !model.AllowMultiFile ? documentName : existingRels.Documents.FirstOrDefault(f => f.DocumentType == (short)docType)?.DocumentName,
                    DocumentType  = (short)docType
                };

                doc.Insert(db, _builder.DbSchema, _builder.UDSDocumentsTableName);
                doc.DocumentLabel = model.Label;
                documents.Add(doc);
            }
            else
            {
                db.Execute(deleteAllSQL, udsId, docType);
                //elimina le relazioni tipo Document
                Guid?chainId = existingRels.Documents.Where(p => p.DocumentType == (short)docType).Select(s => s.IdDocument).FirstOrDefault();
                if (chainId.HasValue && chainId.Value != Guid.Empty)
                {
                    detachAction(chainId.Value);
                }
            }
            return(documents);
        }
Exemple #4
0
        public DocumentInstance GetByRefers(long RefersToId, string RefersToTypeName)
        {
            using (var context = new EWUSDbContext())
            {
                DocumentInstance documentInstance = new DocumentInstance();
                documentInstance = context.DocumentInstances.Where(x => x.RefersTo.Id == RefersToId && x.RefersTo.TypeName == RefersToTypeName)
                                   .Include(x => x.DocumentItems)
                                   .FirstOrDefault();

                if (documentInstance != null)
                {
                    return(documentInstance);
                }
                return(null);
            }
        }
Exemple #5
0
        public object GetById(long Id)
        {
            using (var context = new EWUSDbContext())
            {
                DocumentInstance documentInstance = new DocumentInstance();
                documentInstance = context.DocumentInstances.Where(x => x.Id == Id)
                                   .Include(x => x.DocumentItems)
                                   .FirstOrDefault();

                if (documentInstance != null)
                {
                    return(documentInstance);
                }
                return(null);
            }
        }
Exemple #6
0
        protected override void OnBakeIntoMesh(DocumentInstance document, UndoMultiAction undoMultiAction)
        {
            base.OnBakeIntoMesh(document, undoMultiAction);

            var mesh       = (Component_Mesh)Parent;
            var geometries = mesh.GetComponents <Component_MeshGeometry>();
            int aa         = 0;

            foreach (var geometry in geometries)
            {
                var positions = geometry.VerticesExtractChannel <Vector3F>(VertexElementSemantic.Position);
                if (positions != null)
                {
                    aa = aa + 1;
                    if (DataN == 0 || DataN == aa)
                    {
                        var vertexStructure = geometry.VertexStructure.Value;
                        vertexStructure.GetInfo(out var vertexSize, out _);

                        var oldValue    = geometry.Vertices;
                        var vertices    = geometry.Vertices.Value;
                        var vertexCount = vertices.Length / vertexSize;

                        var newPositions = new Vector3F[positions.Length];
                        for (int n = 0; n < positions.Length; n++)
                        {
                            ProcessVertex(aa, ref positions[n], out newPositions[n]);
                        }

                        var newVertices = (byte[])vertices.Clone();
                        if (geometry.VerticesWriteChannel(VertexElementSemantic.Position, newPositions, newVertices))
                        {
                            //update property
                            geometry.Vertices = newVertices;

                            //undo
                            if (undoMultiAction != null)
                            {
                                var property   = (Metadata.Property)geometry.MetadataGetMemberBySignature("property:Vertices");
                                var undoAction = new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item(geometry, property, oldValue));
                                undoMultiAction.AddAction(undoAction);
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void OnFlyoutShow()
        {
            _flyoutVisible = true;

            Photo selectedPhoto = _gallery.SelectedPhoto;
            int   width         = Number.ParseInt(selectedPhoto.width_m);
            int   height        = Number.ParseInt(selectedPhoto.height_m);

            DocumentInstance flyoutDocument = Gadget.Flyout.Document;

            flyoutDocument.Body.Style.Width  = (width + 8) + "px";
            flyoutDocument.Body.Style.Height = (height + 8) + "px";

            ImageElement photoImage = (ImageElement)flyoutDocument.GetElementById("photoImage");

            photoImage.Width  = width;
            photoImage.Height = height;
            photoImage.Src    = selectedPhoto.url_m;
        }
Exemple #8
0
        private ICollection <UDSDocument> AddDocumentsByType(Database db, Guid udsId, Document model, UDSDocumentType docType)
        {
            IList <UDSDocument> documents = new List <UDSDocument>();

            if (model != null && model.Instances != null)
            {
                DocumentInstance instance = model.Instances.First();
                UDSDocument      doc      = new UDSDocument()
                {
                    UDSDocumentId = Guid.NewGuid(),
                    UDSId         = udsId,
                    DocumentName  = !model.AllowMultiFile ? instance.DocumentName : string.Empty,
                    IdDocument    = Guid.Parse(instance.StoredChainId),
                    DocumentType  = (short)docType,
                    DocumentLabel = model.Label
                };

                doc.Insert(db, _builder.DbSchema, _builder.UDSDocumentsTableName);
                documents.Add(doc);
            }
            return(documents);
        }
        public static void Detach(Component_ObjectInSpace objectToDetach, DocumentInstance documentforUndoRedo = null, UndoMultiAction undoMultiAction = null)
        {
            const string transformOffsetName = "Attach Transform Offset";

            var objectInSpace = objectToDetach;
            //var objectToTransform = CalculateObjectToTransform( objectInSpace );
            //if( objectToTransform != null )
            //	objectInSpace = objectToTransform;

            var transformOffset = objectInSpace.GetComponent(transformOffsetName) as Component_TransformOffset;

            if (transformOffset != null)
            {
                //change Transform
                {
                    //undo action
                    if (undoMultiAction != null)
                    {
                        var property = (Metadata.Property)objectInSpace.MetadataGetMemberBySignature("property:Transform");
                        var undoItem = new UndoActionPropertiesChange.Item(objectInSpace, property, objectInSpace.Transform, new object[0]);
                        undoMultiAction.AddAction(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem }));
                    }

                    //remove reference
                    objectInSpace.Transform = new Reference <Transform>(objectInSpace.Transform, "");
                }

                //delete
                if (undoMultiAction != null)
                {
                    undoMultiAction.AddAction(new UndoActionComponentCreateDelete(documentforUndoRedo, new Component[] { transformOffset }, false));
                }
                else
                {
                    transformOffset.Dispose();
                }
            }
        }
Exemple #10
0
 public static jQuery Select(string selector, DocumentInstance context)
 {
     return(null);
 }
Exemple #11
0
 public static jQuery Element(DocumentInstance document)
 {
     return null;
 }
Exemple #12
0
 public jQuery(string selector, DocumentInstance context)
 {
 }
Exemple #13
0
 private void InternalSaveAs(string fileName, bool saveCopyAs)
 {
     DocumentInstance.SaveAs(fileName, saveCopyAs);
 }
Exemple #14
0
 /// <summary>
 /// Sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent. If the request is synchronous, this method doesn't return until the response has arrived.
 /// </summary>
 /// <param name="data"></param>
 public virtual void Send(DocumentInstance data)
 {
 }
Exemple #15
0
 public static jQuery Html(string html, DocumentInstance ownerDocument)
 {
     return(null);
 }
 protected virtual void OnBakeIntoMesh(DocumentInstance document, UndoMultiAction undoMultiAction)
 {
 }
        static void ConvertProceduralMeshGeometries(DocumentInstance document, Component_Mesh mesh, UndoMultiAction undoMultiAction, ref bool needUndoForNextActions)
        {
            //needUndoForNextActions = true;

            var meshGeometries = mesh.GetComponents <Component_MeshGeometry>();

            if (meshGeometries.Any(g => g is Component_MeshGeometry_Procedural))
            {
                //!!!!?
                bool hasOrdinary = meshGeometries.Any(g => !(g is Component_MeshGeometry_Procedural));
                if (!hasOrdinary)
                {
                    needUndoForNextActions = false;                     //??? Если были и обычные geometry и procedural? Как правильно needUndoForNextActions? Пока так: undo не нужен только если все procedural
                }
                //!!!!right? !needUndoForNextActions
                if (undoMultiAction != null && !needUndoForNextActions)
                {
                    //add structure update to undo
                    var property = (Metadata.Property)mesh.MetadataGetMemberBySignature("property:" + nameof(Component_Mesh.Structure));
                    undoMultiAction.AddAction(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item(mesh, property, mesh.Structure?.Clone())));
                }

                for (int i = 0; i < meshGeometries.Length; i++)
                {
                    var meshGeometry = meshGeometries[i];

                    //convert to usual Component_MeshGeometry
                    if (meshGeometry is Component_MeshGeometry_Procedural meshGeometryProcedural)
                    {
                        VertexElement[]               vertexStructure = null;
                        byte[]                        vertices        = null;
                        int[]                         indices         = null;
                        Component_Material            material        = null;
                        Component_Mesh.StructureClass structure       = null;
                        meshGeometryProcedural.GetProceduralGeneratedData(ref vertexStructure, ref vertices, ref indices, ref material, ref structure);

                        var insertIndex = meshGeometryProcedural.Parent.Components.IndexOf(meshGeometryProcedural);

                        var meshGeometryNew = mesh.CreateComponent <Component_MeshGeometry>(insertIndex);
                        meshGeometryNew.Name            = meshGeometry.Name;
                        meshGeometryNew.VertexStructure = vertexStructure;
                        meshGeometryNew.Vertices        = vertices;
                        meshGeometryNew.Indices         = indices;

                        meshGeometryNew.Material = meshGeometryProcedural.Material;

                        //concut structures. If the geometry is procedural it is not in a structure yet.
                        mesh.Structure = Component_Mesh.StructureClass.Concat(mesh.Structure, structure, i);

                        //delete old mesh geometry
                        if (undoMultiAction != null)
                        {
                            undoMultiAction.AddAction(new UndoActionComponentCreateDelete(document, new Component[] { meshGeometry }, create: false));
                        }
                        else
                        {
                            meshGeometry.Dispose();
                        }

                        //add created geometry to undo
                        if (undoMultiAction != null)
                        {
                            undoMultiAction.AddAction(new UndoActionComponentCreateDelete(document, new Component[] { meshGeometryNew }, create: true));
                        }
                    }
                }
            }
        }
Exemple #18
0
 private bool InternalUpdate2(bool acceptErrorsAndContinue)
 {
     return(DocumentInstance.Update2(acceptErrorsAndContinue));
 }
Exemple #19
0
 private void InternalSave()
 {
     DocumentInstance.Save();
 }
Exemple #20
0
 private void InternalUpdate()
 {
     DocumentInstance.Update();
 }
Exemple #21
0
 private void InternalSetThumbnailSaveOption(ThumbnailSaveOptionEnum saveOption, string imageFullFileName)
 {
     DocumentInstance.SetThumbnailSaveOption(saveOption, imageFullFileName);
 }
Exemple #22
0
 private void InternalSetMissingAddInBehavior(string clientId, CommandTypesEnum disabledCommandTypesEnum, Object disabledCommands)
 {
     DocumentInstance.SetMissingAddInBehavior(clientId, disabledCommandTypesEnum, disabledCommands);
 }
Exemple #23
0
 public jQuery(string selector, DocumentInstance context)
 {
 }
Exemple #24
0
 private void InternalRevertReservedForWriteByMe()
 {
     DocumentInstance.RevertReservedForWriteByMe();
 }
Exemple #25
0
 public static jQuery Element(DocumentInstance document)
 {
     return(null);
 }
Exemple #26
0
 public static jQueryObject FromHtml(string html, DocumentInstance document)
 {
     return(null);
 }
 /// <summary>
 ///     The get tile.
 /// </summary>
 /// <param name="tileCoord">
 ///     The tile coord.
 /// </param>
 /// <param name="zoom">
 ///     The zoom.
 /// </param>
 /// <param name="ownerDocument">
 ///     The owner document.
 /// </param>
 /// <returns>
 ///     The <see cref="Node" />.
 /// </returns>
 public extern Node GetTile(Point tileCoord, int zoom, DocumentInstance ownerDocument);
Exemple #28
0
        //??? Для объединенного MeshInSpace transform выбирать как у первого MeshInSpace или лучше считать средний transform?
        //??? MeshInSpace.ReplaceMeterial,ReplaceMeterialSelectively ? отбрасывать или выбирать первый. Как с geometry?
        static Component_MeshInSpace MergeMeshInSpaces(Component_MeshInSpace[] meshInSpaces, DocumentInstance document, UndoMultiAction undo)
        {
            if (meshInSpaces.Length < 2)
            {
                return(null);
            }

            var newTransform       = meshInSpaces[0].Transform.Value;
            var newMatrixInverse   = newTransform.ToMatrix4().GetInverse();
            var newRotationInverse = newTransform.Rotation.GetInverse();

            Component_Mesh.StructureClass newStructure = null;
            var newGeometries = new List <Component_MeshGeometry>();

            for (int i = 0; i < meshInSpaces.Length; i++)
            {
                var m = meshInSpaces[i].Mesh.Value;
                if (m == null)
                {
                    continue;
                }
                var oldTransform    = meshInSpaces[i].Transform.Value;
                var transformMatrix = newMatrixInverse * oldTransform.ToMatrix4();
                var rotation        = newRotationInverse * oldTransform.Rotation;

                var geometries = m.GetComponents <Component_MeshGeometry>();
                newStructure = Component_Mesh.StructureClass.Concat(newStructure, m.ExtractStructure().Structure, newGeometries.Count);
                foreach (var g in geometries)
                {
                    if (g is Component_MeshGeometry_Procedural meshGeometryProcedural)
                    {
                        VertexElement[]               vertexStructure = null;
                        byte[]                        vertices        = null;
                        int[]                         indices         = null;
                        Component_Material            material        = null;
                        Component_Mesh.StructureClass structure       = null;
                        meshGeometryProcedural.GetProceduralGeneratedData(ref vertexStructure, ref vertices, ref indices, ref material, ref structure);

                        var newMeshGeometry = new Component_MeshGeometry();
                        newMeshGeometry.Name            = meshGeometryProcedural.Name;
                        newMeshGeometry.VertexStructure = vertexStructure;
                        newMeshGeometry.Vertices        = vertices;
                        newMeshGeometry.Indices         = indices;

                        newMeshGeometry.Material = meshGeometryProcedural.Material;
                        //newMeshGeometry.Material = material;

                        TransformVertices(newMeshGeometry.Vertices.Value, new MeshData.MeshGeometryFormat(newMeshGeometry.VertexStructure), transformMatrix, rotation);
                        newGeometries.Add(newMeshGeometry);
                    }
                    else
                    {
                        //??? Проверять CloneSupport?
                        var newMeshGeometry = (Component_MeshGeometry)g.Clone();
                        if (newMeshGeometry.Vertices.Value != null)
                        {
                            newMeshGeometry.Vertices = (byte[])newMeshGeometry.Vertices.Value.Clone();
                            TransformVertices(newMeshGeometry.Vertices.Value, new MeshData.MeshGeometryFormat(newMeshGeometry.VertexStructure), transformMatrix, rotation);
                        }
                        newGeometries.Add(newMeshGeometry);
                    }
                }
            }

            //changes

            var parent = meshInSpaces[0].Parent;

            undo.AddAction(new UndoActionComponentCreateDelete(document, meshInSpaces, create: false));
            Component_MeshInSpace newMeshInSpace = parent.CreateComponent <Component_MeshInSpace>();
            bool wasEnabled = newMeshInSpace.Enabled;

            try
            {
                newMeshInSpace.Enabled   = false;
                newMeshInSpace.Name      = CommonFunctions.GetUniqueFriendlyName(newMeshInSpace);
                newMeshInSpace.Transform = newTransform;

                var newMesh = newMeshInSpace.CreateComponent <Component_Mesh>();
                newMesh.Name        = CommonFunctions.GetUniqueFriendlyName(newMesh);
                newMesh.Structure   = newStructure;
                newMeshInSpace.Mesh = ReferenceUtility.MakeReference <Component_Mesh>(null, ReferenceUtility.CalculateRootReference(newMesh));

                foreach (var g in newGeometries)
                {
                    newMesh.AddComponent(g);
                    CommonFunctions.EnsureNameIsUnique(g);
                }
            }
            finally
            {
                newMeshInSpace.Enabled = wasEnabled;
            }

            undo.AddAction(new UndoActionComponentCreateDelete(document, new[] { newMeshInSpace }, create: true));
            return(newMeshInSpace);
        }
        public static Component_TransformOffset Attach(Component_ObjectInSpace attachTo, Component_ObjectInSpace objectToAttach, DocumentInstance documentforUndoRedo = null, UndoMultiAction undoMultiAction = null)
        {
            var objectToTransform = CalculateObjectToTransform(objectToAttach);

            if (objectToTransform != null)
            {
                objectToAttach = objectToTransform;
            }

            //create _TransformOffset
            Component_TransformOffset transformOffset;

            {
                const string transformOffsetName = "Attach Transform Offset";

                transformOffset        = objectToAttach.CreateComponent <Component_TransformOffset>(enabled: false);
                transformOffset.Name   = transformOffsetName;
                transformOffset.Source = ReferenceUtility.MakeReference <Transform>(null, ReferenceUtility.CalculateThisReference(transformOffset, attachTo, "Transform"));

                try
                {
                    var f      = attachTo.Transform.Value;
                    var s      = objectToAttach.Transform.Value;
                    var offset = f.ToMatrix4().GetInverse() * s.ToMatrix4();
                    offset.Decompose(out Vector3 pos, out Quaternion rot, out Vector3 scl);

                    transformOffset.PositionOffset = pos;
                    transformOffset.RotationOffset = rot;
                    transformOffset.ScaleOffset    = scl;
                    //transformOffset.Matrix = offset;

                    //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse();
                    //var f = first.Transform.Value;
                    //var s = second.Transform.Value;
                    //var offset = new Mat4( s.Rotation.ToMat3(), s.Position ) * new Mat4( f.Rotation.ToMat3(), f.Position ).GetInverse();
                    ////var offset = second.Transform.Value.ToMat4() * first.Transform.Value.ToMat4().GetInverse();
                    //offset.Decompose( out Vec3 pos, out Quat rot, out Vec3 scl );

                    //transformOffset.PositionOffset = pos / f.Scale;// / s.Scale;
                    //transformOffset.RotationOffset = rot;

                    //transformOffset.ScaleOffset = s.Scale / f.Scale;
                    ////transformOffset.ScaleOffset = scl;
                }
                catch { }

                transformOffset.Enabled = true;

                if (undoMultiAction != null)
                {
                    undoMultiAction.AddAction(new UndoActionComponentCreateDelete(documentforUndoRedo, new Component[] { transformOffset }, true));
                }
            }

            //change Transform
            {
                //undo action
                if (undoMultiAction != null)
                {
                    var property = (Metadata.Property)objectToAttach.MetadataGetMemberBySignature("property:Transform");
                    var undoItem = new UndoActionPropertiesChange.Item(objectToAttach, property, objectToAttach.Transform, new object[0]);
                    undoMultiAction.AddAction(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem }));
                }

                //configure reference
                objectToAttach.Transform = ReferenceUtility.MakeReference <Transform>(null, ReferenceUtility.CalculateThisReference(objectToAttach, transformOffset, "Result"));
            }

            return(transformOffset);
        }
Exemple #30
0
 /// <summary>
 /// Sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent. If the request is synchronous, this method doesn't return until the response has arrived.
 /// </summary>
 /// <param name="data"></param>
 public virtual extern void Send(DocumentInstance data);
Exemple #31
0
 public static jQueryObject Select([SyntaxValidation("cssSelector")] string selector, DocumentInstance document)
 {
     return(null);
 }
Exemple #32
0
 private void InternalSave2(bool saveDependents, Object documentsToSave)
 {
     DocumentInstance.Save2(saveDependents, documentsToSave);
 }
Exemple #33
0
        //Component_MeshInSpace contains only one Component_Mesh.
        static void MergeGeometries(Component_Mesh mesh, DocumentInstance document, UndoMultiAction undo)
        {
            Component_MeshGeometry[] geometries = mesh.GetComponents <Component_MeshGeometry>();
            if (geometries == null || geometries.Length < 2)
            {
                return;
            }

            Reference <Component_Material> material = geometries[0].Material;
            //for( int i = 1; i < geometries.Length; i++ )
            //{
            //	if( !( material.Value == null && geometries[ i ].Material.Value == null || material.Equals( geometries[ i ].Material ) ) )
            //	{
            //		//??? Если разные Material какой вариант лучше: 1) Брать из первого geometry с вопросом в MessageBox; 2) Disable в меню для Action. 3) Соединять те, которые с одинаковым материалом.
            //		if( EditorMessageBox.ShowQuestion( "Mesh geometries have different materials. Merge them using a material from the first geometry?", MessageBoxButtons.OKCancel ) == DialogResult.Cancel )
            //		{
            //			return;
            //		}
            //	}
            //}

            var extracted = mesh.ExtractStructure();

            var newIndices         = new List <int>();
            var newVertices        = new List <byte>();
            var newVertexStructure = extracted.MeshGeometries[0].VertexStructure;
            var newVertexFormat    = new MeshData.MeshGeometryFormat(newVertexStructure);

            for (int geomIndex = 0; geomIndex < extracted.MeshGeometries.Length; geomIndex++)
            {
                var g = extracted.MeshGeometries[geomIndex];


                if (g.Vertices == null || g.Indices == null)
                {
                    continue;
                }
                int indexOffset = newVertices.Count / newVertexFormat.vertexSize;

                for (int i = 0; i < g.Indices.Length; i++)
                {
                    newIndices.Add(g.Indices[i] + indexOffset);
                }

                if (!CommonFunctions.IsSameVertexStructure(newVertexStructure, g.VertexStructure))
                {
                    g.Vertices = MeshData.ConvertToFormat(new MeshData.MeshGeometryFormat(g.VertexStructure), g.Vertices, newVertexFormat);
                }

                newVertices.AddRange(g.Vertices);

                foreach (var face in extracted.Structure.Faces)
                {
                    for (int i = 0; i < face.Triangles.Length; i++)
                    {
                        if (face.Triangles[i].RawGeometry == geomIndex)
                        {
                            face.Triangles[i].RawGeometry = 0;
                            face.Triangles[i].RawVertex  += indexOffset;
                        }
                    }
                }
            }

            // changes in the mesh

            if (undo != null)
            {
                //add structure update to undo
                var property = (Metadata.Property)mesh.MetadataGetMemberBySignature("property:" + nameof(Component_Mesh.Structure));
                undo.AddAction(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item(mesh, property, mesh.Structure?.Clone())));
            }

            bool meshWasEnabled = mesh.Enabled;

            mesh.Enabled = false;
            try
            {
                var newGeometry = mesh.CreateComponent <Component_MeshGeometry>();
                newGeometry.Material = material;

                newGeometry.Vertices        = newVertices.ToArray();
                newGeometry.Indices         = newIndices.ToArray();
                newGeometry.VertexStructure = newVertexStructure;

                //add created geometry to undo
                undo?.AddAction(new UndoActionComponentCreateDelete(document, new Component[] { newGeometry }, create: true));

                mesh.Structure = extracted.Structure;

                //delete old mesh geometry
                undo?.AddAction(new UndoActionComponentCreateDelete(document, geometries, create: false));

                newGeometry.Name = CommonFunctions.GetUniqueFriendlyName(newGeometry);
            }
            finally
            {
                mesh.Enabled = meshWasEnabled;
            }
        }
Exemple #34
0
 public static jQuery Html(string html, DocumentInstance ownerDocument)
 {
     return null;
 }
Exemple #35
0
        public static void BoolActionExecute(Component_MeshInSpace firstMeshInSpace, Component_MeshInSpace secondMeshInSpace, UndoMultiAction undo, DocumentInstance document, BoolActionEnum boolAction)
        {
            //the first operand of the union operation must be a single geometry, otherwise duplicate parts will be made.
            if (boolAction == BoolActionEnum.Union && 1 < firstMeshInSpace.Mesh.Value.GetComponents <Component_MeshGeometry>().Length)
            {
                MergeGeometries(firstMeshInSpace.Mesh, document, undo);
            }
            bool needUndoForNextActions = true;

            CommonFunctions.ConvertProceduralMeshGeometries(document, firstMeshInSpace.Mesh, undo, ref needUndoForNextActions);

            List <(Vector3F[] positions, int[] indices)> data1List = GetData(firstMeshInSpace);

            (Vector3F[] positions, int[] indices)data2 = MergeData(GetData(secondMeshInSpace));

            //convert the second mesh in space, to the transform of first mesh in space
            var matrix = firstMeshInSpace.Transform.Value.ToMatrix4().GetInverse() * secondMeshInSpace.Transform.Value.ToMatrix4();

            Net3dBool.Vector3[] vertices2 = new Net3dBool.Vector3[data2.positions.Length];
            for (int i = 0; i < data2.positions.Length; i++)
            {
                vertices2[i] = ToNet3DBoolVector3((matrix * data2.positions[i]).ToVector3F());
            }
            var operand2 = new Net3dBool.Solid(vertices2, data2.indices);

            var geometries         = firstMeshInSpace.Mesh.Value.GetComponents <Component_MeshGeometry>();
            var resultGeometries   = new List <(Vector3F[] positions, int[] indices, MeshData.MeshGeometryFormat format)>();
            var geometriesToDelete = new List <Component_MeshGeometry>();

            for (int geomIndex = 0; geomIndex < data1List.Count; geomIndex++)
            {
                var data1 = data1List[geomIndex];
                Net3dBool.Vector3[] vertices1 = data1.positions.Select(ToNet3DBoolVector3).ToArray();

                var modeller = new Net3dBool.BooleanModeller(new Net3dBool.Solid(vertices1, data1.indices), operand2);                     //Большую часть времени на вычисления занимает эта сторка

                Net3dBool.Solid result = null;
                switch (boolAction)
                {
                case BoolActionEnum.Union: result = modeller.GetUnion(); break;

                case BoolActionEnum.Intersect: result = modeller.GetIntersection(); break;

                case BoolActionEnum.Subtract: result = modeller.GetDifference(); break;

                default: return;
                }

                var newVertices = result.getVertices().Select(ToVector3F).ToArray();
                if (0 < newVertices.Length)
                {
                    resultGeometries.Add((newVertices, result.getIndices(), new MeshData.MeshGeometryFormat(geometries[geomIndex].VertexStructure)));
                }
                else
                {
                    geometriesToDelete.Add(geometries[geomIndex]);
                }
            }

            foreach (var g in resultGeometries)
            {
                if (!CheckValid(g.positions, g.indices))
                {
                    throw new Exception();
                }
            }

            //delete empty mesh geometry //
            if (0 < geometriesToDelete.Count)
            {
                undo?.AddAction(new UndoActionComponentCreateDelete(document, geometriesToDelete.ToArray(), create: false));
            }

            var meshData = MeshData.BuildFromRaw(resultGeometries);

            meshData?.Save(firstMeshInSpace.Mesh.Value, needUndoForNextActions ? undo : null, null);               //??? No selection?
            firstMeshInSpace.Mesh.Value?.RebuildStructure();
        }
Exemple #36
0
 public static jQuery Select(string selector, DocumentInstance context)
 {
     return null;
 }