예제 #1
0
        /// <summary>
        /// Set up materials and gizmos
        /// </summary>
        public static void InitializeF3Scene(FContext context)
        {
            // initialize materials and selection-materials
            context.Scene.DisableSelectionMaterial = false;

            context.Scene.SelectedMaterial = MaterialUtil.CreateStandardVertexColorMaterialF(Colorf.VideoYellow);

            context.Scene.PerTypeSelectionMaterial.Add(
                BodyModelSOTypes.Scan, MaterialUtil.ToUnityMaterial(OrthogenMaterials.ScanMaterial));
            context.Scene.PerTypeSelectionMaterial.Add(
                BodyModelSOTypes.Leg, MaterialUtil.ToUnityMaterial(OrthogenMaterials.LegMaterial));
            fMaterial selectedCurveMat = MaterialUtil.CreateFlatMaterialF(Colorf.Gold, 1);

            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.PlaneIntersectionCurve, selectedCurveMat);
            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.TrimLoop, selectedCurveMat);
            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.EnclosedPatch, selectedCurveMat);


            // if you had other gizmos, you would register them here
            //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
            //controller.TransformManager.SetActiveGizmoType("snap_drag");
            context.TransformManager.RegisterGizmoType(AxisTransformGizmo.DefaultName, new AxisTransformGizmoBuilder());
            context.TransformManager.RegisterGizmoType(LenthenMovePivotGizmoType, new MoveLengthenPivotGizmoBuilder()
            {
                WidgetScale = 0.5f * Vector3f.One
            });

            context.TransformManager.SetActiveGizmoType(TransformManager.NoGizmoType);


            BodyModelSOTypes.RegisterSocketGenTypes(context.Scene.TypeRegistry);
        }
    void update_mesh()
    {
        clear_mesh();

        AxisAlignedBox3i bounds    = grid.Extents;
        Vector3i         minCorner = bounds.Min;
        Vector3f         cornerXYZ = grid.ToXYZ(minCorner);

        Bitmap3d bmp;

        try {
            bmp = new Bitmap3d(bounds.Diagonal + Vector3i.One);
        } catch (Exception e) {
            Debug.Log("update_mesh: exception allocating grid of size " + bounds.Diagonal);
            throw e;
        }

        foreach (Vector3i idx in grid.GridIndices(MinSamples))
        {
            Vector3i bidx = idx - minCorner;
            try {
                bmp.Set(bidx, true);
            } catch (Exception e) {
                Debug.Log("bad index is " + bidx + "  grid dims " + bmp.Dimensions);
                throw e;
            }
        }

        // get rid of one-block tubes, floaters, etc.
        // todo: use a queue instead of passes? or just descend into
        //  nbrs when changing one block? one pass to compute counts and
        //  then another to remove? (yes that is a good idea...)
        bmp.Filter(2);
        bmp.Filter(2);
        bmp.Filter(2);
        bmp.Filter(2);
        bmp.Filter(2);
        bmp.Filter(2);


        VoxelSurfaceGenerator gen = new VoxelSurfaceGenerator()
        {
            Voxels = bmp, Clockwise = false,
            MaxMeshElementCount = 65000,
            ColorSourceF        = (idx) => {
                idx = idx + minCorner;
                return(grid.GetColor(idx));
            }
        };

        gen.Generate();
        List <DMesh3> meshes = gen.Meshes;

        List <fMeshGameObject> newMeshGOs = new List <fMeshGameObject>();

        foreach (DMesh3 mesh in meshes)
        {
            MeshTransforms.Scale(mesh, grid.GridStepSize);
            MeshTransforms.Translate(mesh, cornerXYZ);

            Mesh            m      = UnityUtil.DMeshToUnityMesh(mesh, false);
            fMeshGameObject meshGO = GameObjectFactory.CreateMeshGO("gridmesh", m, false, true);
            meshGO.SetMaterial(MaterialUtil.CreateStandardVertexColorMaterialF(Colorf.White));
            newMeshGOs.Add(meshGO);
        }

        CurrentMeshGOs = newMeshGOs;
    }