Ejemplo n.º 1
0
        protected override GameObject CreateObject(RhinoUnityContext context)
        {
            var curve      = (Rhino.Geometry.Curve)context.File3dmObject.Geometry;
            var nurbsCurve = curve.ToNurbsCurve();
            var points     = nurbsCurve.ToHost();

            var rhinoCurveRenderer = Resources.Load("Prefabs/RhinoCurveRenderer") as GameObject;
            var go = Object.Instantiate(rhinoCurveRenderer, context.Transform);

            var lineRe = go.GetComponent <LineRenderer>();

            if (context.HasMaterial)
            {
                var thickness = context.GetThickness;
                if (thickness != float.NaN)
                {
                    lineRe.startWidth      = thickness;
                    lineRe.endWidth        = thickness;
                    lineRe.widthMultiplier = thickness;
                }
            }

            lineRe.positionCount = points.Length;
            lineRe.SetPositions(points);
            lineRe.material.color = context.DisplayColor;
            return(go);
        }
Ejemplo n.º 2
0
        protected override GameObject CreateObject(RhinoUnityContext context)
        {
            var m            = (Rhino.Geometry.Mesh)context.File3dmObject.Geometry;
            var mesh         = m.ToHost();
            var thickness    = context.GetThickness;
            var hasThickness = thickness > 0.001f;

            var IsUnlit = false;

            if (context.HasMaterial)
            {
                var parts = context.Material.Name.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                IsUnlit = parts.Length > 2 && parts.Last().Equals("1");
            }

            var chosenResource = Lit;

            if (IsUnlit)
            {
                chosenResource = !hasThickness ? UnlitVertex : UnlitVertexWireframe;
            }
            else
            {
                var hasVertexColours = mesh.colors.Length > 0;
                chosenResource = hasVertexColours ? LitVertex : Lit;
            }

            var goPointObj   = Resources.Load(chosenResource) as GameObject;
            var go           = Object.Instantiate(goPointObj, context.Transform);
            var meshFilter   = go.GetComponent <MeshFilter>();
            var meshRenderer = go.GetComponent <MeshRenderer>();
            var meshCollider = go.GetComponent <MeshCollider>();

            if (context.HasMaterial && IsUnlit && hasThickness)
            {
                meshRenderer.material.SetFloat("_WireframeVal", thickness / 5);
            }

            meshFilter.sharedMesh       = mesh;
            meshCollider.sharedMesh     = mesh;
            meshRenderer.material.color = context.DisplayColor;
            return(go);

            return(null);
        }
Ejemplo n.º 3
0
        public static GameObject Read(string path, Transform transform, out RhinoFileInfo rhinoFileInfo)
        {
            var f    = new FileInfo(path);
            var root = new GameObject($"File:{f.Name}");

            root.transform.parent = transform;
            rhinoFileInfo         = root.AddComponent <RhinoFileInfo>();
            var file = File3dm.Read(path);

            rhinoFileInfo.File3dm     = file;
            rhinoFileInfo.Description = file.Notes?.Notes;
            rhinoFileInfo.FullPath    = path;
            var materials = file.AllMaterials;

            List <GameObject> layers = new List <GameObject>();

            foreach (var layer in file.AllLayers)
            {
                var go = new GameObject($"Layer: {layer.Name}");
                go.AddComponent <RhinoLayerController>().SetLayer(layer);
                go.transform.parent = root.transform;
                layers.Add(go);
            }

            foreach (var item in file.Objects)
            {
                var materialIndex = item.Attributes.MaterialIndex;
                var layerIndex    = item.Attributes.LayerIndex;
                var mat           = materials.FindIndex(materialIndex);

                var context = new RhinoUnityContext()
                {
                    File          = file,
                    File3dmObject = item,
                    Transform     = layers[layerIndex].transform
                };

                if (RhinoFactory.CreateInputs(context, out GameObject mobject))
                {
                }
            }

            return(root);
        }
Ejemplo n.º 4
0
        protected override GameObject CreateObject(RhinoUnityContext context)
        {
            var p          = (Rhino.Geometry.Point)context.File3dmObject.Geometry;
            var goPointObj = Resources.Load("Prefabs/RhinoPoint") as GameObject;
            var go         = Object.Instantiate(goPointObj, context.Transform);

            go.transform.position = p.ToHost();

            if (context.HasMaterial)
            {
                var thickness = context.GetThickness;
                if (thickness != float.NaN)
                {
                    go.transform.localScale = thickness * Vector3.one;
                }
            }

            go.GetComponent <MeshRenderer>().material.color = context.DisplayColor;
            return(go);
        }
Ejemplo n.º 5
0
 protected abstract GameObject CreateObject(RhinoUnityContext context);
Ejemplo n.º 6
0
        private static void BindRhinoObjectData(GameObject go, RhinoUnityContext context)
        {
            var rhinoObjectData = go.GetComponent <RhinoObjectData>();

            rhinoObjectData.Bind(context.File3dmObject);
        }