public Vector3 GetSelectedSidePos() { if (selected_side > -1 && selected_segment > -1) { Side s = segment[selected_segment].side[selected_side]; return(s.FindCenter()); } else { editor.AddOutputText("WARNING: No selected segment side"); return(Vector3.Zero); } }
public void GetSelectedSidePosAndNormal(out Vector3 pos, out Vector3 normal) { if (selected_side > -1 && selected_segment > -1) { Side s = segment[selected_segment].side[selected_side]; pos = s.FindCenter(); normal = s.FindNormal(); } else { editor.AddOutputText("WARNING: No selected segment side"); pos = Vector3.Zero; normal = Vector3.Zero; } }
//Returns segnum, or -1 public int InsertSegmentSelectedSide(bool regular = false) { if (selected_side > -1 && selected_segment > -1) { Side s = segment[selected_segment].side[selected_side]; if (s.segment.neighbor[selected_side] < 0) { Vector3 side_normal = -s.FindNormal(); Vector3 side_right = s.FindBestEdgeDir(); // s.FindEdgeDir(0); Vector3 side_up = Vector3.Cross(side_normal, side_right).Normalized(); Vector3 side_center = s.FindCenter(); int idx_new = InsertSegmentBasic(s, side_center, side_normal, side_right, side_up, regular, editor.CurrExtrudeLength); segment[idx_new].CopyTexturesAndDecalsFromSegmentAtBack(segment[selected_segment], selected_side); s.DisableDecals(); // Tag the two segments (for refreshing decals) UnTagAllSegments(); segment[idx_new].m_tag = true; s.segment.m_tag = true; // Select the new cube (depending on the option) if (editor.ShouldInsertAdvance) { selected_segment = idx_new; //selected_side = (int)SideOrder.FRONT; } return(idx_new); } else { // Already has a neighbor } } else { // Nothing selected } return(-1); }
public void FindBaseAttributes(Decal d) { Side s = d.side; m_base_normal = s.FindNormal(); // Center position switch (d.align) { case DecalAlign.TEXTURE: m_base_pos = s.FindUVCenterIn3D(); break; case DecalAlign.CENTER: m_base_pos = s.FindCenter(); break; case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_LEFT: case DecalAlign.EDGE_UP: m_base_pos = s.FindEdgeCenter((int)d.align - (int)DecalAlign.EDGE_RIGHT); break; } m_base_rvec = Vector3.Zero; // Up vector switch (d.align) { case DecalAlign.TEXTURE: m_base_uvec = s.FindUVUpVector(); break; case DecalAlign.CENTER: m_base_uvec = s.FindBestEdgeDir(); break; case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_LEFT: case DecalAlign.EDGE_UP: m_base_rvec = -s.FindEdgeDir((int)d.align - (int)DecalAlign.EDGE_RIGHT); m_base_uvec = Vector3.Cross(m_base_normal, m_base_rvec); break; } // Find the right vec for cases we haven't already if (m_base_rvec == Vector3.Zero) { m_base_rvec = Vector3.Cross(m_base_uvec, m_base_normal); } // Apply the rotation of the decal properties to the Up and Right Vector Matrix4 vec_rot = Matrix4.CreateFromAxisAngle(m_base_normal, d.RotationAngle()); m_base_uvec = Vector3.TransformNormal(m_base_uvec, vec_rot); m_base_rvec = Vector3.TransformNormal(m_base_rvec, vec_rot); // Base rotation m_base_rot = Matrix4.Transpose(Matrix4.LookAt(Vector3.Zero, m_base_normal, m_base_uvec)); }