private static Materials.Material CreateMaterialForMesh(MeshPrimitive prim, Gltf model)
        {
            Materials.Material result = null; //new PbrMaterial(AlkaronCoreGame.Core.SceneManager);
            //result.Effect = AlkaronCoreGame.Core.SceneManager.RenderManager.

            return(result);
        }
Example #2
0
        public static Bar Column(Autodesk.DesignScript.Geometry.Line line, Materials.Material material, Sections.Section[] section, [DefaultArgument("Connectivity.Default()")] Connectivity[] connectivity, [DefaultArgument("Eccentricity.Default()")] Eccentricity[] eccentricity, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("true")] bool orientLCS, string identifier = "C")
        {
            // convert class
            Geometry.Edge edge = Geometry.Edge.FromDynamoLine(line);

            // create bar
            var type = BarType.Column;
            Bar bar  = new Bar(edge, type, material, section, eccentricity, connectivity, identifier);

            // set local y-axis
            if (!localY.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                bar.BarPart.LocalY = FemDesign.Geometry.FdVector3d.FromDynamo(localY);
            }

            // else orient coordinate system to GCS
            else
            {
                if (orientLCS)
                {
                    bar.BarPart.OrientCoordinateSystemToGCS();
                }
            }

            // return
            return(bar);
        }
Example #3
0
 /// <summary>
 /// Reinforcement wire.
 /// </summary>
 public Wire(double diameter, Materials.Material reinforcingMaterial, WireProfileType profile)
 {
     this.ReinforcingMaterial     = reinforcingMaterial;
     this.Diameter                = diameter;
     this.ReinforcingMaterialGuid = reinforcingMaterial.Guid;
     this.Profile = profile;
 }
        private static Materials.Material CreateMaterialForMesh(MeshPrimitive prim, Gltf model)
        {
            var mat = AlkaronCoreGame.Core.AssetManager.Load <Materials.Material>("EngineMaterials.BasicEffect.material");

            Materials.Material result = mat; //new PbrMaterial(AlkaronCoreGame.Core.SceneManager);
            //result.Effect = AlkaronCoreGame.Core.SceneManager.RenderManager.

            return(result);
        }
Example #5
0
 /// <summary>
 /// Construct Slab.
 /// </summary>
 private Slab(SlabType type, string name, SlabPart slabPart, Materials.Material material)
 {
     this.EntityCreated();
     this.Name     = name;
     this.Type     = type;
     this.SlabPart = slabPart;
     this.Material = material;
     this.End      = "";
 }
Example #6
0
        public static Slab Plate(string identifier, Materials.Material material, Geometry.Region region, EdgeConnection shellEdgeConnection, ShellEccentricity eccentricity, ShellOrthotropy orthotropy, List <Thickness> thickness)
        {
            Slab._plateInstance++;
            SlabType type     = SlabType.Plate;
            string   name     = identifier + "." + Slab._plateInstance.ToString() + ".1";
            SlabPart slabPart = SlabPart.Define(name, region, thickness, material, shellEdgeConnection, eccentricity, orthotropy);
            Slab     shell    = new Slab(type, name, slabPart, material);

            return(shell);
        }
Example #7
0
        /// <summary>
        /// Construct a truss element. BarType must be specified as Truss.
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="type"></param>
        /// <param name="material"></param>
        /// <param name="section"></param>
        /// <param name="identifier"></param>
        /// <exception cref="System.Exception"></exception>
        public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sections.Section section, string identifier)
        {
            if (type != BarType.Truss)
            {
                throw new System.Exception("Truss is not a valid type");
            }

            this.EntityCreated();
            this.Type       = type;
            this.Identifier = identifier;
            this.BarPart    = new BarPart(edge, this.Type, material, section, this.Identifier);
        }
Example #8
0
        /// <summary>
        /// Construct beam or column with non-uniform section and different start/end conditions
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="type"></param>
        /// <param name="material"></param>
        /// <param name="sections">List of sections, 2 or more items.</param>
        /// <param name="positions">List of parametric (0-1) section positions, 2 or more items.</param>
        /// <param name="eccentricities">List of analytical eccentricities, 2 or more items.</param>
        /// <param name="startConnectivity">Start connectivity</param>
        /// <param name="endConnectivity">End connectivity</param>
        /// <param name="identifier">Identifier</param>
        public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sections.Section[] sections, double[] positions, Eccentricity[] eccentricities, Connectivity startConnectivity, Connectivity endConnectivity, string identifier)
        {
            if (type == BarType.Truss)
            {
                throw new System.Exception("Truss is not a valid type");
            }

            this.EntityCreated();
            this.Type       = type;
            this.Identifier = identifier;
            this.BarPart    = new BarPart(edge, this.Type, material, sections, positions, eccentricities, startConnectivity, endConnectivity, this.Identifier);
        }
Example #9
0
        public static Slab Wall(string identifier, Materials.Material material, Geometry.Region region, EdgeConnection shellEdgeConnection, ShellEccentricity eccentricity, ShellOrthotropy orthotropy, List <Thickness> thickness)
        {
            // check if surface is vertical
            if (Math.Abs(region.CoordinateSystem.LocalZ.Z) > FemDesign.Tolerance.Point3d)
            {
                throw new System.ArgumentException("Wall is not vertical! Create plate instead.");
            }

            Slab._wallInstance++;
            SlabType type     = SlabType.Wall;
            string   name     = identifier + "." + Slab._wallInstance.ToString() + ".1";
            SlabPart slabPart = SlabPart.Define(name, region, thickness, material, shellEdgeConnection, eccentricity, orthotropy);
            Slab     shell    = new Slab(type, name, slabPart, material);

            return(shell);
        }
Example #10
0
        /// <summary>
        /// Construct beam or column with uniform section and uniform start/end conditions
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="type"></param>
        /// <param name="material"></param>
        /// <param name="section">Section, same at start/end</param>
        /// <param name="eccentricity">Analytical eccentricity, same at start. Eccentricity set to 0,0 if null/end</param>
        /// <param name="connectivity">Connectivity, same at start/end. Connectivity set to Rigid if null</param>
        /// <param name="identifier">Identifier</param>
        public Bar(Geometry.Edge edge, BarType type, Materials.Material material, Sections.Section section, Eccentricity eccentricity = null, Connectivity connectivity = null, string identifier = "B")
        {
            if (type == BarType.Truss)
            {
                throw new System.Exception("Truss is not a valid type");
            }

            this.EntityCreated();
            this.Type       = type;
            this.Identifier = identifier;

            if (eccentricity == null)
            {
                eccentricity = Eccentricity.GetDefault();
            }
            if (connectivity == null)
            {
                connectivity = Connectivity.GetDefault();
            }
            this.BarPart = new BarPart(edge, this.Type, material, section, eccentricity, connectivity, this.Identifier);
        }
Example #11
0
        public static Slab PlateVariableThickness(Autodesk.DesignScript.Geometry.Surface surface, List <Thickness> thickness, Materials.Material material, [DefaultArgument("ShellEccentricity.Default()")] ShellEccentricity shellEccentricity, [DefaultArgument("ShellOrthotropy.Default()")] ShellOrthotropy shellOrthotropy, [DefaultArgument("EdgeConnection.Default()")] EdgeConnection shellEdgeConnection, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localX, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localZ, string identifier = "P")
        {
            // create FlatSurface
            Geometry.Region region = Geometry.Region.FromDynamo(surface);

            // check length of thickness
            if (thickness.Count != 3)
            {
                throw new System.ArgumentException("Thickness must contain exactly 3 items.");
            }

            // create shell
            Slab slab = Slab.Plate(identifier, material, region, shellEdgeConnection, shellEccentricity, shellOrthotropy, thickness);

            // set local x-axis
            if (!localX.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalX = FemDesign.Geometry.FdVector3d.FromDynamo(localX);
            }

            // set local z-axis
            if (!localZ.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalZ = FemDesign.Geometry.FdVector3d.FromDynamo(localZ);
            }

            return(slab);
        }
Example #12
0
        public static Slab Plate(Autodesk.DesignScript.Geometry.Surface surface, double thickness, Materials.Material material, [DefaultArgument("ShellEccentricity.Default()")] ShellEccentricity shellEccentricity, [DefaultArgument("ShellOrthotropy.Default()")] ShellOrthotropy shellOrthotropy, [DefaultArgument("EdgeConnection.Default()")] EdgeConnection shellEdgeConnection, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localX, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localZ, string identifier = "P")
        {
            // create FlatSurface
            Geometry.Region region = Geometry.Region.FromDynamo(surface);

            // create Thickness object
            List <Thickness> _thickness = new List <Thickness>();

            _thickness.Add(new Thickness(region.CoordinateSystem.Origin, thickness));

            // create shell
            Slab slab = Slab.Plate(identifier, material, region, shellEdgeConnection, shellEccentricity, shellOrthotropy, _thickness);

            // set local x-axis
            if (!localX.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalX = FemDesign.Geometry.FdVector3d.FromDynamo(localX);
            }

            // set local z-axis
            if (!localZ.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalZ = FemDesign.Geometry.FdVector3d.FromDynamo(localZ);
            }

            return(slab);
        }
Example #13
0
        public static Slab Wall(Autodesk.DesignScript.Geometry.Surface surface, double thickness, Materials.Material material, [DefaultArgument("ShellEccentricity.Default()")] ShellEccentricity shellEccentricity, [DefaultArgument("ShellOrthotropy.Default()")] ShellOrthotropy shellOrthotropy, [DefaultArgument("EdgeConnection.Default()")] EdgeConnection shellEdgeConnection, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localX, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localZ, string identifier = "W")
        {
            // create FlatSurface
            Geometry.Region region = Geometry.Region.FromDynamo(surface);

            // create Thickness object
            List <Thickness> _thickness = new List <Thickness>();

            _thickness.Add(new Thickness(region.CoordinateSystem.Origin, thickness));

            // check if surface is vertical
            if (Math.Abs(region.CoordinateSystem.LocalZ.Z) > FemDesign.Tolerance.Point3d)
            {
                throw new System.ArgumentException("Wall is not vertical! Create plate instead.");
            }

            // create shell
            Slab slab = Slab.Wall(identifier, material, region, shellEdgeConnection, shellEccentricity, shellOrthotropy, _thickness);

            // set local x-axis
            if (!localX.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalX = FemDesign.Geometry.FdVector3d.FromDynamo(localX);
            }

            // set local z-axis
            if (!localZ.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                slab.SlabPart.LocalZ = FemDesign.Geometry.FdVector3d.FromDynamo(localZ);
            }

            return(slab);
        }
Example #14
0
        static void Main()
        {
            // PRACTICAL EXAMPLE: PARAMETRIC STUDY - REACTIONS
            // In this example, we will analyse how different E-modules will result
            // in different reaction forces in the supports holding a concrete plate.

            // This example was last updated 2022-05-03, using the ver. 21.1.0 FEM-Design API.


            // FILE PATH SETUP
            // Set the different paths and folders relevant to the example
            string struxmlPath = "sample_slab.struxml";
            string outFolder   = "output/";

            if (!Directory.Exists(outFolder))
            {
                Directory.CreateDirectory(outFolder);
            }
            string        bscPath  = Path.GetFullPath("pointsupportreactions.bsc");
            List <string> bscPaths = new List <string>();

            bscPaths.Add(bscPath);

            // READ MODEL
            Model model = Model.DeserializeFromFilePath(struxmlPath);

            // READ SLAB TO ANALYSE
            // In this example, the slab is card-coded to no. 5; if you make any personal applications,
            // it is probably better to look for a slab with a certain name, eg. P.1, to avoid confusion.
            Shells.Slab        slab     = model.Entities.Slabs[4];
            Materials.Material material = model.Entities.Slabs[4].Material;
            double             Ecm      = Convert.ToDouble(material.Concrete.Ecm);

            // ITERATION & ANALYSIS PROCESS
            // Iterate over model using different E-modulus for the slab
            for (int i = 1; i < 6; i++)
            {
                // Change E-modulus
                double new_Ecm = Math.Round(0.2 * i * Ecm);
                material.Concrete.Ecm = Convert.ToString(new_Ecm);

                // Save struxml
                string outPathIndividual = Path.GetFullPath(outFolder + "sample_slab_out" + Convert.ToString(new_Ecm) + ".struxml");
                model.SerializeModel(outPathIndividual);

                // Run analysis
                Calculate.Analysis           analysis = new Calculate.Analysis(null, null, null, null, calcCase: true, false, false, false, false, false, false, false, false, false, false, false, false);
                FemDesign.Calculate.FdScript fdScript = FemDesign.Calculate.FdScript.Analysis(outPathIndividual, analysis, bscPaths, "", true);
                Calculate.Application        app      = new Calculate.Application();
                app.RunFdScript(fdScript, false, true, true);

                string pointSupportReactionsPath = Path.Combine(outFolder, "pointsupportreactions.csv");

                // Reading results (This method is only available for some result types as of now, but more will be added)
                var results = Results.ResultsReader.Parse(pointSupportReactionsPath);
                var pointSupportReactions = results.Cast <Results.PointSupportReaction>().ToList();

                // Print results
                Console.WriteLine();
                Console.WriteLine($"Emean: {new_Ecm}");
                Console.WriteLine("Id         | Reaction  ");
                foreach (var reaction in pointSupportReactions)
                {
                    Console.WriteLine($"{reaction.Id,10} | {reaction.Fz,10}");
                }
            }

            // ENDING THE PROGRAM
            Console.WriteLine("\nPress any key to close console.");
            Console.ReadKey();
        }
        private static List <SkeletalMesh> LoadMesh(Package packageToSaveIn, Gltf model, List <byte[]> rawBuffers, Mesh mesh)
        {
            List <SkeletalMesh> meshes = new List <SkeletalMesh>();

            for (int p = 0; p < mesh.Primitives.Length; p++)
            {
                var prim = mesh.Primitives[p];

                if (prim.Mode != MeshPrimitive.ModeEnum.TRIANGLES)
                {
                    throw new NotImplementedException("Modes other than TRIANGLES are not implemented (yet)");
                }

                Accessor positionAccessor = GetAccessorByType("POSITION", model, prim);
                if (positionAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("POSITION accessor must have type VEC3");
                }

                Accessor normalAccessor = GetAccessorByType("NORMAL", model, prim);
                if (normalAccessor != null &&
                    normalAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("NORMAL accessor must have type VEC3");
                }

                Accessor texcoordAccessor = GetAccessorByType("TEXCOORD_0", model, prim);
                if (texcoordAccessor != null &&
                    texcoordAccessor.Type != Accessor.TypeEnum.VEC2)
                {
                    throw new InvalidDataException("TEXCOORD accessor must have type VEC2");
                }

                Accessor tangentAccessor = GetAccessorByType("TANGENT", model, prim);
                if (tangentAccessor != null &&
                    tangentAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("TANGENT accessor must have type VEC4");
                }

                Accessor weightsAccessor = GetAccessorByType("WEIGHTS_0", model, prim);
                if (weightsAccessor != null &&
                    weightsAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("WEIGHTS_0 accessor must have type VEC4");
                }

                Accessor jointsAccessor = GetAccessorByType("JOINTS_0", model, prim);
                if (jointsAccessor != null &&
                    jointsAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("JOINTS_0 accessor must have type VEC4");
                }

                SkinnedTangentVertex[] vertices           = new SkinnedTangentVertex[positionAccessor.Count];
                BufferView             positionBufferView = model.BufferViews[positionAccessor.BufferView.Value];
                BufferView             normalsBufferView  = null;
                if (normalAccessor != null)
                {
                    normalsBufferView = model.BufferViews[normalAccessor.BufferView.Value];
                }
                BufferView texCoordBufferView = null;
                if (texcoordAccessor != null)
                {
                    texCoordBufferView = model.BufferViews[texcoordAccessor.BufferView.Value];
                }
                BufferView tangentBufferView = null;
                if (tangentAccessor != null)
                {
                    tangentBufferView = model.BufferViews[tangentAccessor.BufferView.Value];
                }
                BufferView weightsBufferView = null;
                if (weightsAccessor != null)
                {
                    weightsBufferView = model.BufferViews[weightsAccessor.BufferView.Value];
                }
                BufferView jointsBufferView = null;
                if (jointsAccessor != null)
                {
                    jointsBufferView = model.BufferViews[jointsAccessor.BufferView.Value];
                }

                ReadOnlySpan <Vector3> positionSpan = MemoryMarshal.Cast <byte, Vector3>(
                    new ReadOnlySpan <byte>(rawBuffers[positionBufferView.Buffer], positionBufferView.ByteOffset + positionAccessor.ByteOffset, positionAccessor.Count * 12));
                ReadOnlySpan <Vector3> normalsSpan = null;
                if (normalsBufferView != null)
                {
                    normalsSpan = MemoryMarshal.Cast <byte, Vector3>(
                        new ReadOnlySpan <byte>(rawBuffers[normalsBufferView.Buffer], normalsBufferView.ByteOffset + normalAccessor.ByteOffset, normalAccessor.Count * 12));
                }
                ReadOnlySpan <Vector2> texCoordSpan = null;
                if (texCoordBufferView != null)
                {
                    texCoordSpan = MemoryMarshal.Cast <byte, Vector2>(
                        new ReadOnlySpan <byte>(rawBuffers[texCoordBufferView.Buffer], texCoordBufferView.ByteOffset + texcoordAccessor.ByteOffset, texcoordAccessor.Count * 8));
                }
                ReadOnlySpan <Vector4> tangentSpan = null;
                if (tangentBufferView != null)
                {
                    tangentSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[tangentBufferView.Buffer], tangentBufferView.ByteOffset + tangentAccessor.ByteOffset, tangentAccessor.Count * 16));
                }
                ReadOnlySpan <Vector4> weightsSpan = null;
                if (weightsBufferView != null)
                {
                    weightsSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[weightsBufferView.Buffer], weightsBufferView.ByteOffset + weightsAccessor.ByteOffset, weightsAccessor.Count * 16));
                }
                ReadOnlySpan <Vector4> jointsSpan = null;
                if (jointsBufferView != null)
                {
                    jointsSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(rawBuffers[jointsBufferView.Buffer], jointsBufferView.ByteOffset + jointsAccessor.ByteOffset, jointsAccessor.Count * 16));
                }

                for (int v = 0; v < vertices.Length; v++)
                {
                    vertices[v].Position = positionSpan[v];

                    if (normalsSpan != null)
                    {
                        vertices[v].Normal = normalsSpan[v];
                    }

                    if (texCoordSpan != null)
                    {
                        vertices[v].TexCoord = texCoordSpan[v];
                    }

                    if (tangentSpan != null)
                    {
                        vertices[v].Tangent = new Vector3(tangentSpan[v].X, tangentSpan[v].Y, tangentSpan[v].Z);
                        if (normalsSpan != null)
                        {
                            vertices[v].BiTangent = Vector3.Cross(normalsSpan[v], vertices[v].Tangent) * tangentSpan[v].W;
                        }
                    }
                }

                SkeletalMesh skeletalMesh = new SkeletalMesh();

                if (prim.Indices == null)
                {
                    skeletalMesh = SkeletalMesh.FromVertices(vertices);
                }
                else
                {
                    int      primIndex     = prim.Indices.Value;
                    Accessor indexAccessor = GetAccessorByIndex(primIndex, model);
                    if (indexAccessor != null)
                    {
                        if (indexAccessor.Type != Accessor.TypeEnum.SCALAR)
                        {
                            throw new InvalidDataException("Index accessor must have type SCALAR");
                        }

                        uint[] indices = new uint[indexAccessor.Count];

                        BufferView indexBufferView = model.BufferViews[indexAccessor.BufferView.Value];
                        switch (indexAccessor.ComponentType)
                        {
                        case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                        {
                            ReadOnlySpan <byte> indexSpan =
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count);

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                        {
                            ReadOnlySpan <ushort> indexSpan = MemoryMarshal.Cast <byte, ushort>(
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 2));

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                        {
                            ReadOnlySpan <uint> indexSpan = MemoryMarshal.Cast <byte, uint>(
                                new ReadOnlySpan <byte>(rawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 4));

                            indices = indexSpan.ToArray();
                        }
                        break;

                        default:
                            throw new NotImplementedException("ComponentType " + indexAccessor.ComponentType + " not implemented.");
                        }

                        skeletalMesh = SkeletalMesh.FromVertices(vertices, indices);
                    }
                }

                skeletalMesh.Name = mesh.Name + "_" + p + ".skeletalMesh";
                packageToSaveIn.StoreAsset(skeletalMesh);
                meshes.Add(skeletalMesh);

                Materials.Material material = CreateMaterialForMesh(prim, model);
                skeletalMesh.Material = material;
            }

            return(meshes);
        }
Example #16
0
        public static Bar TrussLimitedCapacity(Autodesk.DesignScript.Geometry.Line line, Materials.Material material, Sections.Section section, double maxCompression, double maxTension, bool compressionPlasticity, bool tensionPlasticity, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("true")] bool orientLCS, string identifier = "T")
        {
            // convert class
            Geometry.Edge edge = Geometry.Edge.FromDynamoLine(line);

            // create bar
            var type = BarType.Truss;
            Bar bar  = new Bar(edge, type, material, section, identifier);

            bar.MaxCompression        = maxCompression;
            bar.MaxTension            = maxTension;
            bar.CompressionPlasticity = compressionPlasticity;
            bar.TensionPlasticity     = tensionPlasticity;

            // set local y-axis
            if (!localY.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                bar.BarPart.LocalY = FemDesign.Geometry.FdVector3d.FromDynamo(localY);
            }

            // else orient coordinate system to GCS
            else
            {
                if (orientLCS)
                {
                    bar.BarPart.OrientCoordinateSystemToGCS();
                }
            }

            // return
            return(bar);
        }
        private static void LoadMesh(AssetImporterGltfMeshContext context, int meshIndex, Matrix worldMatrix)
        {
            Mesh mesh = context.Model.Meshes[meshIndex];

            for (int p = 0; p < mesh.Primitives.Length; p++)
            {
                var prim = mesh.Primitives[p];

                if (prim.Mode != MeshPrimitive.ModeEnum.TRIANGLES)
                {
                    throw new NotImplementedException("Modes other than TRIANGLES are not implemented (yet)");
                }

                Accessor positionAccessor = GetAccessorByType("POSITION", context.Model, prim);
                if (positionAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("POSITION accessor must have type VEC3");
                }

                Accessor normalAccessor = GetAccessorByType("NORMAL", context.Model, prim);
                if (normalAccessor != null &&
                    normalAccessor.Type != Accessor.TypeEnum.VEC3)
                {
                    throw new InvalidDataException("NORMAL accessor must have type VEC3");
                }

                Accessor texcoordAccessor = GetAccessorByType("TEXCOORD_0", context.Model, prim);
                if (texcoordAccessor != null &&
                    texcoordAccessor.Type != Accessor.TypeEnum.VEC2)
                {
                    throw new InvalidDataException("TEXCOORD accessor must have type VEC2");
                }

                Accessor tangentAccessor = GetAccessorByType("TANGENT", context.Model, prim);
                if (tangentAccessor != null &&
                    tangentAccessor.Type != Accessor.TypeEnum.VEC4)
                {
                    throw new InvalidDataException("TANGENT accessor must have type VEC4");
                }

                TangentVertex[] vertices           = new TangentVertex[positionAccessor.Count];
                BufferView      positionBufferView = context.Model.BufferViews[positionAccessor.BufferView.Value];
                BufferView      normalsBufferView  = null;
                if (normalAccessor != null)
                {
                    normalsBufferView = context.Model.BufferViews[normalAccessor.BufferView.Value];
                }
                BufferView texCoordBufferView = null;
                if (texcoordAccessor != null)
                {
                    texCoordBufferView = context.Model.BufferViews[texcoordAccessor.BufferView.Value];
                }
                BufferView tangentBufferView = null;
                if (tangentAccessor != null)
                {
                    tangentBufferView = context.Model.BufferViews[tangentAccessor.BufferView.Value];
                }

                ReadOnlySpan <Vector3> positionSpan = MemoryMarshal.Cast <byte, Vector3>(
                    new ReadOnlySpan <byte>(context.RawBuffers[positionBufferView.Buffer], positionBufferView.ByteOffset + positionAccessor.ByteOffset, positionAccessor.Count * 12));
                ReadOnlySpan <Vector3> normalsSpan = null;
                if (normalsBufferView != null)
                {
                    normalsSpan = MemoryMarshal.Cast <byte, Vector3>(
                        new ReadOnlySpan <byte>(context.RawBuffers[normalsBufferView.Buffer], normalsBufferView.ByteOffset + normalAccessor.ByteOffset, normalAccessor.Count * 12));
                }
                ReadOnlySpan <Vector2> texCoordSpan = null;
                if (texCoordBufferView != null)
                {
                    texCoordSpan = MemoryMarshal.Cast <byte, Vector2>(
                        new ReadOnlySpan <byte>(context.RawBuffers[texCoordBufferView.Buffer], texCoordBufferView.ByteOffset + texcoordAccessor.ByteOffset, texcoordAccessor.Count * 8));
                }
                ReadOnlySpan <Vector4> tangentSpan = null;
                if (tangentBufferView != null)
                {
                    tangentSpan = MemoryMarshal.Cast <byte, Vector4>(
                        new ReadOnlySpan <byte>(context.RawBuffers[tangentBufferView.Buffer], tangentBufferView.ByteOffset + tangentAccessor.ByteOffset, tangentAccessor.Count * 16));
                }

                for (int v = 0; v < vertices.Length; v++)
                {
                    vertices[v].Position = positionSpan[v];

                    if (normalsSpan != null)
                    {
                        vertices[v].Normal = normalsSpan[v];
                    }

                    if (texCoordSpan != null)
                    {
                        vertices[v].TexCoord = texCoordSpan[v];
                    }

                    if (tangentSpan != null)
                    {
                        vertices[v].Tangent = new Vector3(tangentSpan[v].X, tangentSpan[v].Y, tangentSpan[v].Z);
                        if (normalsSpan != null)
                        {
                            vertices[v].BiTangent = Vector3.Cross(normalsSpan[v], vertices[v].Tangent) * tangentSpan[v].W;
                        }
                    }
                }

                StaticMesh staticMesh = null;

                if (prim.Indices == null)
                {
                    staticMesh = StaticMesh.FromVertices(vertices);
                }
                else
                {
                    int      primIndex     = prim.Indices.Value;
                    Accessor indexAccessor = GetAccessorByIndex(primIndex, context.Model);
                    if (indexAccessor != null)
                    {
                        if (indexAccessor.Type != Accessor.TypeEnum.SCALAR)
                        {
                            throw new InvalidDataException("Index accessor must have type SCALAR");
                        }

                        uint[] indices = new uint[indexAccessor.Count];

                        BufferView indexBufferView = context.Model.BufferViews[indexAccessor.BufferView.Value];
                        switch (indexAccessor.ComponentType)
                        {
                        case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                        {
                            ReadOnlySpan <byte> indexSpan =
                                new ReadOnlySpan <byte>(context.RawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count);

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                        {
                            ReadOnlySpan <ushort> indexSpan = MemoryMarshal.Cast <byte, ushort>(
                                new ReadOnlySpan <byte>(context.RawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 2));

                            for (int idx = 0; idx < indices.Length; idx++)
                            {
                                indices[idx] = (uint)indexSpan[idx];
                            }
                        }
                        break;

                        case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                        {
                            ReadOnlySpan <uint> indexSpan = MemoryMarshal.Cast <byte, uint>(
                                new ReadOnlySpan <byte>(context.RawBuffers[indexBufferView.Buffer], indexBufferView.ByteOffset + indexAccessor.ByteOffset, indexAccessor.Count * 4));

                            indices = indexSpan.ToArray();
                        }
                        break;

                        default:
                            throw new NotImplementedException("ComponentType " + indexAccessor.ComponentType + " not implemented.");
                        }

                        staticMesh = StaticMesh.FromVertices(vertices, indices);
                    }
                }

                staticMesh.Name = mesh.Name + "_" + p + ".staticMesh";
                context.PackageToSaveIn.StoreAsset(staticMesh);

                Materials.Material material = CreateMaterialForMesh(prim, context.Model);
                staticMesh.Material = material;

                context.ImportedAssets.Add(staticMesh);
            }
        }
Example #18
0
 public static Wire Define(double diameter, Materials.Material reinforcingMaterial, WireProfileType profile)
 {
     return(new Wire(diameter, reinforcingMaterial, profile));
 }
Example #19
0
        /// <summary>
        /// Construct SlabPart with EdgeConnections.
        /// </summary>
        public static SlabPart Define(string name, Geometry.Region region, List <Thickness> thickness, Materials.Material material, EdgeConnection shellEdgeConnection, ShellEccentricity eccentricity, ShellOrthotropy orthotropy)
        {
            // add edgeConnections to region
            region.SetEdgeConnections(shellEdgeConnection);

            // construct new slabPart
            SlabPart slabPart = new SlabPart(name, region, thickness, material, eccentricity, orthotropy);

            // return
            return(slabPart);
        }
Example #20
0
        /// <summary>
        /// Create a default concrete shell with panels using a continuous analytical model.
        /// </summary>
        /// <param name="region">Panel region.</param>
        /// <param name="externalEdgeConnection"></param>
        /// <param name="material"></param>
        /// <param name="section"></param>
        /// <param name="identifier">Name of shell.</param>
        /// <param name="orthotropy"></param>
        /// <param name="ecc"></param>
        /// <returns></returns>
        public static Panel DefaultContreteContinuous(Geometry.Region region, EdgeConnection externalEdgeConnection, Materials.Material material, Sections.Section section, string identifier, double orthotropy, ShellEccentricity ecc)
        {
            Geometry.FdPoint3d anchorPoint    = region.Contours[0].Edges[0].Points[0];
            InternalPanel      internalPanel  = new InternalPanel(region);
            InternalPanels     internalPanels = new InternalPanels(internalPanel);
            PanelType          type           = PanelType.Concrete;
            string             panelName      = "A";
            double             gap            = 0.003;
            bool externalMovingLocal          = externalEdgeConnection.MovingLocal;

            return(new Panel(region, anchorPoint, internalPanels, externalEdgeConnection, type, material, section, identifier, panelName, gap, orthotropy, ecc, externalMovingLocal));
        }
Example #21
0
        public static Panel ProfiledPlate(Autodesk.DesignScript.Geometry.Surface surface, Materials.Material material, Sections.Section section, [DefaultArgument("ShellEccentricity.Default()")] ShellEccentricity eccentricity, [DefaultArgument("1")] double orthoRatio, [DefaultArgument("EdgeConnection.Hinged()")] EdgeConnection edgeConnection, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localX, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localZ, [DefaultArgument("0")] double avgMeshSize, string identifier = "PP")
        {
            // convert geometry
            Geometry.Region region = Geometry.Region.FromDynamo(surface);

            // create panel
            Panel obj = Panel.DefaultContreteContinuous(region, edgeConnection, material, section, identifier, orthoRatio, eccentricity);

            // set local x-axis
            if (!localX.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                obj.LocalX = FemDesign.Geometry.FdVector3d.FromDynamo(localX);
            }

            // set local z-axis
            if (!localZ.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                obj.LocalZ = FemDesign.Geometry.FdVector3d.FromDynamo(localZ);
            }

            // set mesh
            obj.UniformAvgMeshSize = avgMeshSize;

            // return
            return(obj);
        }
Example #22
0
 public override void SetMaterial(Materials.Material mm)
 {
     m.SetMaterial(mm);
 }
Example #23
0
        public static Bar Modify(Bar bar, [DefaultArgument("false")] bool newGuid, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Curve curve, [DefaultArgument("null")] Materials.Material material, [DefaultArgument("null")] Sections.Section[] section, [DefaultArgument("null")] Connectivity[] connectivity, [DefaultArgument("null")] Eccentricity[] eccentricity, [DefaultArgument("null")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("false")] bool orientLCS, [DefaultArgument("null")] string identifier)
        {
            if (bar.BarPart.HasComplexCompositeRef || bar.BarPart.HasDeltaBeamComplexSectionRef)
            {
                throw new System.Exception("Composite Section in the model.The object has not been implemented yet. Please, get in touch if needed.");
            }
            else
            {
                bar = bar.DeepClone();

                if (newGuid)
                {
                    bar.EntityCreated();
                    bar.BarPart.EntityCreated();
                }

                if (curve != null)
                {
                    // convert geometry
                    Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc2(curve);

                    // update edge
                    bar.BarPart.Edge = edge;
                }

                if (material != null)
                {
                    bar.BarPart.ComplexMaterialObj = material;
                }

                if (section != null)
                {
                    bar.BarPart.ComplexSectionObj.Sections = section;
                }

                if (connectivity != null)
                {
                    bar.BarPart.Connectivity = connectivity;
                }

                if (eccentricity != null)
                {
                    bar.BarPart.ComplexSectionObj.Eccentricities = eccentricity;
                }

                if (localY != null)
                {
                    bar.BarPart.LocalY = Geometry.FdVector3d.FromDynamo(localY);
                }

                if (orientLCS)
                {
                    bar.BarPart.OrientCoordinateSystemToGCS();
                }

                if (identifier != null)
                {
                    bar.Identifier         = identifier;
                    bar.BarPart.Identifier = bar.Identifier;
                }

                return(bar);
            }
        }
Example #24
0
 /// <summary>
 /// Construct SlabPart.
 /// </summary>
 public SlabPart(string name, Geometry.Region region, List <Thickness> thickness, Materials.Material complexMaterial, ShellEccentricity alignment, ShellOrthotropy orthotropy)
 {
     this.EntityCreated();
     this.Name                    = name;
     this.Region                  = region;
     this.ComplexMaterial         = complexMaterial.Guid;
     this.Alignment               = alignment.Alignment;
     this.AlignOffset             = alignment.Eccentricity;
     this.OrthoAlfa               = orthotropy.OrthoAlfa;
     this.OrthoRatio              = orthotropy.OrthoRatio;
     this.EccentricityCalculation = alignment.EccentricityCalculation;
     this.EccentricityByCracking  = alignment.EccentricityByCracking;
     this.Thickness               = thickness;
     this.LocalPos                = region.CoordinateSystem.Origin;
     this._localX                 = region.CoordinateSystem.LocalX;
     this._localY                 = region.CoordinateSystem.LocalY;
     this.End = "";
 }
Example #25
0
        /// <summary>
        /// Construct standard panel with "Continuous" analytical model.
        /// </summary>
        /// <param name="region">Region of shell containing panels.</param>
        /// <param name="localX">Direction of panels.</param>
        /// <param name="anchorPoint"></param>
        /// <param name="externalRigidity">Default value for shell border EdgeConnections. Can be overwritten by EdgeConnection for each specific edge in Region.</param>
        /// <param name="type">Type of panel.</param>
        /// <param name="complexMaterial">Guid reference to material.</param>
        /// <param name="complexSection">Guid reference to complex section.</param>
        /// <param name="identifier">Name of shell.</param>
        /// <param name="panelName">Name of panel.</param>
        /// <param name="gap">Gap between panels.</param>
        /// <param name="orthotropy">Orthotropy.</param>
        /// <param name="ecc">ShellEccentricity.</param>
        /// <param name="externalMovingLocal">EdgeConnection LCS changes along edge?</param>
        internal Panel(Geometry.Region region, Geometry.FdPoint3d anchorPoint, InternalPanels internalPanels, EdgeConnection externalEdgeConnection, PanelType type, Materials.Material material, Sections.Section section, string identifier, string panelName, double gap, double orthotropy, ShellEccentricity ecc, bool externalMovingLocal)
        {
            this.EntityCreated();

            // elements
            this.Region           = region;
            this.CoordinateSystem = region.CoordinateSystem;
            this.AnchorPoint      = anchorPoint;
            this.InternalPanels   = internalPanels;
            this.ExternalRigidity = externalEdgeConnection.Rigidity;

            // set edge connections
            this.SetExternalEdgeConnections(externalEdgeConnection);

            // attributes
            this.Type                    = type;
            this.Material                = material; // note that material and section are not added directly to complexMaterial and complexSection fields.
            this.Section                 = section;
            this.Identifier              = identifier;
            this.PanelName               = panelName;
            this.Gap                     = gap;
            this.Orthotropy              = orthotropy;
            this.Alignment               = ecc.Alignment;
            this.AlignOffset             = ecc.Eccentricity;
            this.EccentricityCalculation = ecc.EccentricityCalculation;
            this.EccentricityByCracking  = ecc.EccentricityByCracking;
            this.ExternalMovingLocal     = externalMovingLocal;
        }