Exemplo n.º 1
0
    public Tile(InstanceDefinition definition, double density, RhinoDoc doc)
    {
        Index = definition.Index;

        var geometry = definition.GetObjects();

        int renderIndex = doc.Layers.FindName("Render").Index;

        var renderMeshes = geometry
                           .Where(g => g.Attributes.LayerIndex == renderIndex)
                           .Select(g => g.Geometry as Mesh)
                           .ToList();

        Renderers = renderMeshes.Select(m => new MeshExport(m)).ToList();

        int collisionsIndex = doc.Layers.FindName("Collision").Index;

        var meshColliders = geometry
                            .Where(g => g.Attributes.LayerIndex == collisionsIndex)
                            .Select(g => g.Geometry as Mesh)
                            .ToList();

        Colliders = meshColliders
                    .Select(m => m.Offset(0.001))
                    .Select(m => new MeshExport(m))
                    .ToList();

        Point3d centroid = Point3d.Origin;
        double  mass     = 0.0;

        foreach (var mesh in meshColliders)
        {
            var    prop        = VolumeMassProperties.Compute(mesh);
            double elementMass = prop.Volume * density;
            centroid += prop.Centroid * elementMass;
            mass     += elementMass;
        }

        centroid /= mass;
        Centroid  = new Vector3Export(centroid);
        Mass      = (float)mass;

        int facesIndex = doc.Layers.FindName("Faces").Index;

        //Faces = geometry
        //         .Where(g => g.Attributes.LayerIndex == facesIndex)
        //         .Select(g =>
        //          {
        //              Curve curve = g.Geometry as Curve;
        //              curve.TryGetPolyline(out Polyline pl);
        //              var plane = new Plane(pl[1], pl[2], pl[0]);
        //              plane.Origin = (pl[0] * 0.5 + pl[2] * 0.5);
        //              return new Orient(plane);
        //          }).ToList();

        Faces = geometry
                .Where(g => g.Attributes.LayerIndex == facesIndex)
                .Select(g =>
        {
            var point = g.Geometry as Point;
            return(new Vector3Export(point.Location));
        }).ToList();
    }
Exemplo n.º 2
0
 public Pose(Plane plane)
 {
     position = new Vector3Export(plane.Origin);
     rotation = new QuaternionExport(plane);
 }