public static GOWrapperSO CombineAnySOs(SceneObject s1, SceneObject s2, bool bDeleteExisting = true) { FScene scene = s1.GetScene(); if (scene.IsSelected(s1)) { scene.Deselect(s1); } if (scene.IsSelected(s2)) { scene.Deselect(s2); } fGameObject parentGO = GameObjectFactory.CreateParentGO("combined"); GOWrapperSO.AppendSOGeometry(parentGO, s1, true); GOWrapperSO.AppendSOGeometry(parentGO, s2, true); GOWrapperSO wrapperSO = new GOWrapperSO() { AllowMaterialChanges = false }; wrapperSO.Create(parentGO); if (bDeleteExisting) { scene.RemoveSceneObject(s1, false); scene.RemoveSceneObject(s2, false); } scene.AddSceneObject(wrapperSO, false); return(wrapperSO); }
public static void AppendMeshSO(DMeshSO appendTo, DMeshSO append) { FScene scene = appendTo.GetScene(); if (scene.IsSelected(appendTo)) { scene.Deselect(appendTo); } if (scene.IsSelected(append)) { scene.Deselect(append); } Frame3f f1 = appendTo.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale1 = appendTo.GetLocalScale(); Frame3f f2 = append.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale2 = append.GetLocalScale(); DMesh3 mesh1 = appendTo.Mesh; DMesh3 mesh2 = append.Mesh; foreach (int vid in mesh2.VertexIndices()) { // convert point in mesh2 to scene coords Vector3f v2 = (Vector3f)mesh2.GetVertex(vid); v2 *= scale2; Vector3f v2s = f2.FromFrameP(v2); // transfer that scene coord into local coords of mesh1 Vector3f v2in1 = f1.ToFrameP(v2s); v2in1 /= scale1; mesh2.SetVertex(vid, v2in1); if (mesh1.HasVertexNormals && mesh2.HasVertexNormals) { Vector3f n = mesh2.GetVertexNormal(vid); Vector3f ns = f2.FromFrameV(n); Vector3f ns2 = f1.ToFrameV(ns); mesh2.SetVertexNormal(vid, ns2); } } MeshEditor editor = new MeshEditor(mesh1); editor.AppendMesh(mesh2); appendTo.NotifyMeshEdited(); // [TODO] change record! scene.RemoveSceneObject(append, false); }
public static GroupSO CreateGroupSO(TransformableSO so1, TransformableSO so2) { FScene scene = so1.GetScene(); if (scene.IsSelected(so1)) { scene.Deselect(so1); } if (scene.IsSelected(so2)) { scene.Deselect(so2); } GroupSO group = new GroupSO(); group.Create(); scene.AddSceneObject(group); group.AddChild(so1); group.AddChild(so2); return(group); }
public static GOWrapperSO CombineAnySOs(SceneObject s1, SceneObject s2, bool bDeleteExisting = true) { FScene scene = s1.GetScene(); if (scene.IsSelected(s1)) { scene.Deselect(s1); } if (scene.IsSelected(s2)) { scene.Deselect(s2); } fGameObject parentGO = GameObjectFactory.CreateParentGO("combined"); fGameObject copy1 = GameObjectFactory.Duplicate(s1.RootGameObject); fGameObject copy2 = GameObjectFactory.Duplicate(s2.RootGameObject); // if inputs are DMeshSOs, they do not have colliders, which we will need... if (s1 is DMeshSO) { foreach (var go in copy1.Children()) { if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null) { go.AddComponent <MeshCollider>(); } } } if (s2 is DMeshSO) { foreach (var go in copy2.Children()) { if (go.GetComponent <MeshFilter>() != null && go.GetComponent <MeshCollider>() == null) { go.AddComponent <MeshCollider>(); } } } parentGO.AddChild(copy1, true); parentGO.AddChild(copy2, true); GOWrapperSO wrapperSO = new GOWrapperSO() { AllowMaterialChanges = false }; wrapperSO.Create(parentGO); if (bDeleteExisting) { scene.RemoveSceneObject(s1, false); scene.RemoveSceneObject(s2, false); } scene.AddSceneObject(wrapperSO, false); return(wrapperSO); }