virtual public void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateFlatShaded("holefill_preview", Colorf.DimGrey); } if (HoleBoundaryMaterial == null) { HoleBoundaryMaterial = SOMaterial.CreateStandard("holefill_boundary", Colorf.PivotYellow); } previewSO = new DMeshSO(); previewSO.EnableSpatial = false; previewSO.Create(new DMesh3(Target.Mesh), PreviewMaterial); previewSO.Name = "HoleFillTool_preview"; previewSO.SetLocalFrame(Target.GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords); previewSO.SetLocalScale(Target.GetLocalScale()); previewSO.OnMeshModified += PreviewSO_OnMeshModified; Scene.AddSceneObject(previewSO); sceneToObjUnitScale = SceneTransforms.SceneToObject(Target, 1.0f); Loops = new MeshBoundaryLoops(previewSO.Mesh); boundaryGeom = new BoundaryCurveSet(previewSO.RootGameObject, HoleBoundaryMaterial.ToFMaterial()); boundaryGeom.Radius = BorderRadius.SceneValue * sceneToObjUnitScale; boundaryGeom.Initialize(Loops); }
virtual public void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); brushIndicator = new BrushCursorSphere() { PositionF = () => { return(Scene.ToWorldP(lastBrushPosS.Origin)); }, Radius = fDimension.World(() => { return(radius.WorldValue); }) }; Indicators.AddIndicator(brushIndicator); brushIndicator.material = MaterialUtil.CreateTransparentMaterialF(Colorf.DarkRed, 0.8f); if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateFlatShaded("MeshEditor_generated", Colorf.DimGrey); } previewSO = new DMeshSO(); previewSO.EnableSpatial = false; previewSO.Create(new DMesh3(Target.Mesh), PreviewMaterial); previewSO.Name = "MeshEditorTool_preview"; previewSO.SetLocalFrame(Target.GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords); previewSO.SetLocalScale(Target.GetLocalScale()); Scene.AddSceneObject(previewSO); PreviewSpatial = new EditMeshSpatial() { SourceMesh = Target.Mesh, SourceSpatial = Target.Spatial, EditMesh = PreviewMesh }; }
public virtual void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); if (OnApplyF == null) { OnApplyF = this.add_so_to_scene; } if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateFlatShaded("tool_generated", Colorf.DimGrey); } // clear selection here inputSelection = new List <SceneObject>(Scene.Selected); set_allow_selection_changes(true); Scene.ClearSelection(); set_allow_selection_changes(false); cache_brim_polys(); PreviewSO = new DMeshSO(); PreviewSO.Create(new DMesh3(), PreviewMaterial); Scene.AddSceneObject(PreviewSO); PreviewSO.Name = "Generated Brim"; initialize_parameters(); }
void initialize_cut_op() { if (MeshSourceOp != null) { return; } MeshSourceOp = new WrapDMeshSourceOp() { MeshSourceF = () => { return(InputMeshSO.Mesh); }, SpatialSourceF = () => { return(InputMeshSO.Spatial); } }; CutOp = new CutPolygonHoleOp() { MeshSource = MeshSourceOp }; ComputeOp = new ThreadedMeshComputeOp() { MeshSource = CutOp }; if (CutPreviewMaterial == null) { CutPreviewMaterial = SOMaterial.CreateFlatShaded("add_hole_cut", Colorf.DimGrey); } CutPreviewSO = new DMeshSO() { EnableSpatial = false }; CutPreviewSO.Create(new DMesh3(), CutPreviewMaterial); Scene.AddSceneObject(CutPreviewSO); CutPreviewSO.SetLocalFrame(InputMeshSO.GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords); CutPreviewSO.SetLocalScale(InputMeshSO.GetLocalScale()); }
public virtual void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); if (OnApplyF == null) { OnApplyF = this.add_so_to_scene; } if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateFlatShaded("tool_generated", Colorf.DimGrey); } // clear selection here inputSelection = new List <SceneObject>(Scene.Selected); set_allow_selection_changes(true); Scene.ClearSelection(); set_allow_selection_changes(false); scene_bounds = AxisAlignedBox3d.Empty; foreach (var so in CC.Objects.PrintMeshes) { if (so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.Solid || so.Settings.ObjectType == PrintMeshSettings.ObjectTypes.Support) { var seq = SceneTransforms.ObjectToSceneXForm(so); foreach (Vector3d p in so.Mesh.Vertices()) { Vector3d ps = seq.TransformP(p); if (ps.y >= 0) { scene_bounds.Contain(ps); } } } } scene_bounds.Min.y = 0; if (scene_bounds.Width <= 0) { scene_bounds.Min.x = scene_bounds.Max.x = 0; } if (scene_bounds.Depth <= 0) { scene_bounds.Min.z = scene_bounds.Max.z = 0; } Height = scene_bounds.Height; PreviewSO = new DMeshSO(); PreviewSO.Create(new DMesh3(), PreviewMaterial); Scene.AddSceneObject(PreviewSO); PreviewSO.Name = "Purge Spiral"; initialize_parameters(); }
public virtual void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); if (OnApplyF == null) { OnApplyF = this.add_so_to_scene; } if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey); } if (ErrorMaterial == null) { ErrorMaterial = SOMaterial.CreateMesh("tool_generated_error", Colorf.VideoRed); } // clear selection here so that multi-select GroupSO goes away, otherwise // when we copy frmaes below, they are relative to that GroupSO, and things move inputSelection = new List <SceneObject>(Scene.Selected); set_allow_selection_changes(true); Scene.ClearSelection(); set_allow_selection_changes(false); MeshSourceOps = new List <ConstantMeshSourceOp>(); SceneMeshes = new List <DMesh3>(); foreach (var so in InputSOs) { var xform = SceneTransforms.ObjectToSceneXForm(so); DMesh3 sceneMesh = new DMesh3(so.Mesh); MeshTransforms.PerVertexTransform(sceneMesh, xform); SceneMeshes.Add(sceneMesh); MeshSourceOps.Add( new ConstantMeshSourceOp(sceneMesh, false, true)); } EditOp = edit_op_factory(MeshSourceOps.Cast <DMeshSourceOp>()); ComputeOp = new ThreadedMeshComputeOp() { MeshSource = EditOp }; PreviewSO = new DMeshSO() { EnableSpatial = EnablePreviewSpatial }; PreviewSO.Create(new DMesh3(), PreviewMaterial); Scene.AddSceneObject(PreviewSO); postprocess_target_objects(); base_initialize_parameters(); }
int hole_start_id; // this is MultiPointTool point ID of hole public override void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); base.Setup(); // shut off transform gizmo Scene.Context.TransformManager.PushOverrideGizmoType(TransformManager.NoGizmoType); InputMeshSO = TargetSO as DMeshSO; // create preview obj if (HolePreviewMaterial == null) { HolePreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey.WithAlpha(0.5f)); } if (CutPreviewMaterial == null) { CutPreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey); } if (ErrorMaterial == null) { ErrorMaterial = SOMaterial.CreateMesh("tool_generated_error", Colorf.VideoRed); } // clear selection here so that multi-select GroupSO goes away, otherwise // when we copy frmaes below, they are relative to that GroupSO, and things move inputSelection = new List <SceneObject>(Scene.Selected); set_allow_selection_changes(true); Scene.ClearSelection(); set_allow_selection_changes(false); // create preview hole object CavityPreviewSO = new DMeshSO(); CavityPreviewSO.Create(new DMesh3(), HolePreviewMaterial); update_hole_mesh(); Scene.AddSceneObject(CavityPreviewSO); CavityPreviewSO.SetLayer(FPlatform.WidgetOverlayLayer); // initialize cut op initialize_cut_op(); // nooooo Vector3d posL = InputMeshSO.Mesh.GetVertex(0); hole_start_id = base.AppendSurfacePoint("hole_point", Colorf.ForestGreen, 2.0f); SetPointPosition(hole_start_id, new Frame3f(posL), CoordSpace.ObjectCoords); SetPointColor(hole_start_id, Colorf.ForestGreen, FPlatform.WidgetOverlayLayer); // init params initialize_parameters(); }
public override void postprocess_target_objects() { if (HiddenPreviewMaterial == null) { HiddenPreviewMaterial = SOMaterial.CreateTransparent("remove_hidden_generated", new Colorf(Colorf.VideoRed, 0.5f)); } RemovedSO = new DMeshSO(); RemovedSO.Create(new DMesh3(), HiddenPreviewMaterial); RemovedSO.SetLayer(FPlatform.WidgetOverlayLayer); RemovedSO.DisableShadows(); Scene.AddSceneObject(RemovedSO); RemovedSO.SetLocalFrame(PreviewSO.GetLocalFrame(CoordSpace.SceneCoords), CoordSpace.SceneCoords); RemovedSO.SetLocalScale(PreviewSO.GetLocalScale()); }
public static void TestMarchingCubes() { MarchingCubes mc = new MarchingCubes(); LocalProfiler p = new LocalProfiler(); p.Start("GENERATE"); mc.ParallelCompute = true; mc.Generate(); p.Stop("GENERATE"); DebugUtil.Log(2, p.AllTimes()); MeshNormals.QuickCompute(mc.Mesh); DebugUtil.WriteDebugMesh(mc.Mesh, "c:\\scratch\\MARCHING_CUBES.obj"); DMeshSO meshSO = new DMeshSO(); meshSO.Create(mc.Mesh, CC.ActiveScene.DefaultMeshSOMaterial); CC.ActiveScene.AddSceneObject(meshSO, false); }
public DMeshSO BuildSO(FScene scene, SOMaterial material) { DMesh3 revolveMesh = UnityUtil.UnityMeshToDMesh(meshObject.GetSharedMesh(), false); // move axis frame to center of bbox of mesh, measured in axis frame Frame3f useF = OutputFrame; AxisAlignedBox3f boundsInFrame = (AxisAlignedBox3f)BoundsUtil.BoundsInFrame(revolveMesh.Vertices(), useF); useF.Origin = useF.FromFrameP(boundsInFrame.Center); // transform mesh into this frame MeshTransforms.ToFrame(revolveMesh, useF); // create new so DMeshSO meshSO = new DMeshSO(); meshSO.Create(revolveMesh, material); meshSO.SetLocalFrame(useF, CoordSpace.ObjectCoords); return(meshSO); }
void update_preview(List <DMesh3> meshes) { if (PreviewSOs != null) { foreach (var so in PreviewSOs) { Scene.RemoveSceneObject(so, true); } PreviewSOs.Clear(); } foreach (var mesh in meshes) { var so = new DMeshSO() { EnableSpatial = EnablePreviewSpatial }; so.Create(mesh, KeepPreviewMaterial); Scene.AddSceneObject(so); PreviewSOs.Add(so); } }
// Use this for initialization public override void Awake() { // if we need to auto-configure Rift vs Vive vs (?) VR, we need // to do this before any other F3 setup, because MainCamera will change // and we are caching that in a lot of places... if (AutoConfigVR) { VRCameraRig = gs.VRPlatform.AutoConfigureVR(); } // restore any settings SceneGraphConfig.RestorePreferences(); // set up some defaults // this will move the ground plane down, but the bunnies will be floating... //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY; SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f; SceneGraphConfig.DefaultPivotVisualDegrees = 1.5f; SceneGraphConfig.DefaultAxisGizmoVisualDegrees = 10.0f; SceneGraphConfig.InitialSceneTranslate = -4 * Vector3f.AxisY; SceneOptions options = new SceneOptions(); options.UseSystemMouseCursor = false; options.Use2DCockpit = false; options.EnableTransforms = true; options.EnableCockpit = true; options.CockpitInitializer = new PhotoToolCockpit(); options.MouseCameraControls = new MayaCameraHotkeys(); options.SpatialCameraRig = VRCameraRig; // very verbose options.LogLevel = 2; context = new FContext(); context.Start(options); // if you had other gizmos, you would register them here //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder()); //controller.TransformManager.SetActiveGizmoType("snap_drag"); // if you had other tools, you would register them here. context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder()); context.ToolManager.RegisterToolType(DrawSurfaceCurveTool.Identifier, new DrawSurfaceCurveToolBuilder() { AttachCurveToSurface = true, DefaultSamplingRateS = 0.0025f, DefaultSurfaceOffsetS = 0.0025f, CurveMaterialF = () => { var mat = context.Scene.DefaultCurveSOMaterial.Clone(); mat.RGBColor = Colorf.VideoRed; return(mat); } }); context.ToolManager.SetActiveToolType(DrawSurfaceCurveTool.Identifier, ToolSide.Right); // Set up standard scene lighting if requested if (options.EnableDefaultLighting) { GameObject lighting = GameObject.Find("SceneLighting"); if (lighting == null) { lighting = new GameObject("SceneLighting"); } SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>(); setup.Context = context; setup.LightDistance = 30.0f; // related to total scene scale... } Context.Scene.DisableSelectionMaterial = true; /* * Import elements of Unity scene that already exist into the FScene */ // set up ground plane geometry (optional) GameObject groundPlane = GameObject.Find("GroundPlane"); if (groundPlane != null && groundPlane.IsVisible()) { context.Scene.AddWorldBoundsObject(groundPlane); } float fSquareSize = 1.0f; Vector3f eyePos = context.ActiveCamera.GetPosition(); System.Random rand = new System.Random(31337); // [RMS] this path only works in Editor, is relative to top-level project directory string sPhotoFolder = "Data\\PhotoSets\\kitchen"; string[] photos = Directory.GetFiles(sPhotoFolder); foreach (string filename in photos) { Texture2D tex = load_texture(filename); if (tex == null) { continue; } float fScale = fSquareSize / (float)tex.width; if (tex.height > tex.width) { fScale = fSquareSize / (float)tex.height; } float w = fScale * (float)tex.width; float h = fScale * (float)tex.height; TrivialRectGenerator rectgen = new TrivialRectGenerator() { Width = w, Height = h }; rectgen.Generate(); DMesh3 mesh = new DMesh3(MeshComponents.VertexUVs); rectgen.MakeMesh(mesh); SOMaterial material = new SOMaterial() { Name = "photomaterial", Type = SOMaterial.MaterialType.TextureMap, RGBColor = Colorf.White }; material.MainTexture = tex; DMeshSO so = new DMeshSO(); so.Create(mesh, material); context.Scene.AddSceneObject(so); float horz = rand.Next(-50, 50); float vert = rand.Next(-20, 25); int mult = 1000; float dist = (float)(rand.Next(2 * mult, 3 * mult)) / (float)mult; Ray3f r = VRUtil.MakeRayFromSphereCenter(horz, vert); r.Origin += eyePos; float fRayT = 0.0f; RayIntersection.Sphere(r.Origin, r.Direction, eyePos, dist, out fRayT); Vector3f v = r.Origin + fRayT * r.Direction; Frame3f f = new Frame3f(v, v.Normalized); Vector3f toEye = context.ActiveCamera.GetPosition() - f.Origin; toEye.Normalize(); f.AlignAxis(1, toEye); f.ConstrainedAlignAxis(2, Vector3f.AxisY, f.Y); so.SetLocalFrame(f, CoordSpace.WorldCoords); } }
public virtual void Setup() { // push history stream, so that we can do undo/redo internal to tool, // that will not end up in external history push_history_stream(); if (OnApplyF == null) { OnApplyF = this.add_so_to_scene; } if (PreviewMaterial == null) { PreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey); } if (ErrorMaterial == null) { ErrorMaterial = SOMaterial.CreateMesh("tool_generated_error", Colorf.VideoRed); } // clear selection here so that multi-select GroupSO goes away, otherwise // when we copy frmaes below, they are relative to that GroupSO, and things move inputSelection = new List <SceneObject>(Scene.Selected); set_allow_selection_changes(true); Scene.ClearSelection(); set_allow_selection_changes(false); if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false) { combineMesh = new DMesh3(InputSOs[0].Mesh); sceneToObjUnitScale = SceneTransforms.SceneToObject(InputSOs[0], 1.0f); } else { combineMesh = new DMesh3(); MeshEditor editor = new MeshEditor(combineMesh); foreach (var so in InputSOs) { TransformSequence xform = SceneTransforms.ObjectToSceneXForm(so); DMesh3 inputMesh = so.Mesh; int[] mapV; if (editor.AppendMesh(so.Mesh, out mapV)) { MeshTransforms.PerVertexTransform(combineMesh, inputMesh, mapV, (v, old_id, new_id) => { return(xform.TransformP(v)); }); } } ; sceneToObjUnitScale = 1.0; } MeshSourceOp = new ConstantMeshSourceOp(combineMesh, true, true); EditOp = edit_op_factory(MeshSourceOp); ComputeOp = new ThreadedMeshComputeOp() { MeshSource = EditOp }; PreviewSO = new DMeshSO() { EnableSpatial = EnablePreviewSpatial }; PreviewSO.Create(new DMesh3(), PreviewMaterial); if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false) { PreviewSO.SetLocalFrame(InputSOs[0].GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords); PreviewSO.SetLocalScale(InputSOs[0].GetLocalScale()); } Scene.AddSceneObject(PreviewSO); postprocess_target_objects(); base_initialize_parameters(); }
// Use this for initialization public override void Awake() { VRPlatform.VREnabled = false; // restore any settings SceneGraphConfig.RestorePreferences(); // set up some defaults SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f; SceneGraphConfig.DefaultPivotVisualDegrees = 1.5f; SceneGraphConfig.DefaultAxisGizmoVisualDegrees = 10.0f; SceneOptions options = new SceneOptions(); options.UseSystemMouseCursor = true; options.EnableCockpit = true; options.Use2DCockpit = true; options.ConstantSize2DCockpit = true; // you usually want this options.EnableTransforms = true; options.CockpitInitializer = new SetupObjectsDemoCockpit(); options.MouseCameraControls = new MayaCameraHotkeys(); // very verbose options.LogLevel = 2; context = new FContext(); context.Start(options); // register transformation gizmos //context.TransformManager.RegisterGizmoType(AxisTransformGizmo.DefaultName, new AxisTransformGizmoBuilder()); //context.TransformManager.SetActiveGizmoType(AxisTransformGizmo.DefaultName); // if you had other tools, you would register them here. context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder()); context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right); // Set up standard scene lighting if requested if (options.EnableDefaultLighting) { GameObject lighting = GameObject.Find("SceneLighting"); if (lighting == null) { lighting = new GameObject("SceneLighting"); } SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>(); setup.Context = context; setup.LightDistance = 30.0f; // related to total scene scale... } /* * Import elements of Unity scene that already exist into the FScene */ // set up ground plane geometry (optional) GameObject groundPlane = GameObject.Find("GroundPlane"); context.Scene.AddWorldBoundsObject(groundPlane); Sphere3Generator_NormalizedCube gen = new Sphere3Generator_NormalizedCube() { Radius = 1.0f }; DMeshSO meshSO = new DMeshSO(); meshSO.Create(gen.Generate().MakeDMesh(), Context.Scene.DefaultMeshSOMaterial); Context.Scene.AddSceneObject(meshSO); //SceneObject focusSO = null; // convert a mesh GameObject to our DMeshSO // Note: any child GameObjects will be lost GameObject meshGO = GameObject.Find("bunny_mesh"); if (meshGO != null) { //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO; UnitySceneUtil.WrapMeshGameObject(meshGO, context, true); } GameObject meshGO2 = GameObject.Find("bunny_mesh2"); if (meshGO2 != null) { //DMeshSO meshSO = UnitySceneUtil.WrapMeshGameObject(meshGO, context, true) as DMeshSO; UnitySceneUtil.WrapMeshGameObject(meshGO2, context, true); } //// center the camera on the capsule assembly //if (focusSO != null) { // Vector3f centerPt = focusSO.GetLocalFrame(CoordSpace.WorldCoords).Origin; // context.ActiveCamera.Manipulator().ScenePanFocus( // context.Scene, context.ActiveCamera, centerPt, true); //} }