Esempio n. 1
0
        /**
         * Sets the passed faces to use Auto or Manual UVs, and (if previously manual) splits any vertex connections.
         */
        public static void SetAutoUV(pb_Object pb, pb_Face[] faces, bool auto)
        {
            if (auto)
            {
                faces = System.Array.FindAll(faces, x => x.manualUV).ToArray();         // only operate on faces that were previously manual

                pb.SplitUVs(pb_Face.AllTriangles(faces));

                Vector2[][] uv_origins = new Vector2[faces.Length][];
                for (int i = 0; i < faces.Length; i++)
                {
                    uv_origins[i] = pb.GetUVs(faces[i].distinctIndices);
                }

                for (int f = 0; f < faces.Length; f++)
                {
                    faces[f].uv.Reset();
                    faces[f].manualUV     = !auto;
                    faces[f].elementGroup = -1;
                }

                pb.RefreshUV(faces);

                for (int i = 0; i < faces.Length; i++)
                {
                    pb_Transform2D transform = MatchCoordinates(pb.GetUVs(faces[i].distinctIndices), uv_origins[i]);

                    faces[i].uv.offset   = -transform.position;
                    faces[i].uv.rotation = transform.rotation;

                    if (Mathf.Abs(transform.scale.sqrMagnitude - 2f) > .1f)
                    {
                        faces[i].uv.scale = transform.scale;
                    }
                }
            }
            else
            {
                foreach (pb_Face f in faces)
                {
                    f.textureGroup = -1;
                    f.manualUV     = !auto;
                }
            }
        }
Esempio n. 2
0
    private void TextureGroupSelectedFaces(pb_Object pb)    //, pb_Face face)
    {
        if (pb.SelectedFaces.Length < 1)
        {
            return;
        }

        pb_UV cont_uv = pb.SelectedFaces[0].uv;

        int texGroup = pb.UnusedTextureGroup();

        foreach (pb_Face f in pb.SelectedFaces)
        {
            f.SetUV(new pb_UV(cont_uv));
            f.textureGroup = texGroup;
        }

        pb.RefreshUV(pb.SelectedFaces);
        SceneView.RepaintAll();
    }
        private void HandleFinish(Standard input, Action <InputControl> consumeControl)
        {
            // Ready for next object to be created
            if (input.action.wasJustReleased)
            {
                m_AudioModule.Play(m_Trigger, true);
                m_GuideModule.SetVisible(false);
                m_HighlightModule.SetFaceHighlight(m_Object, null);

                m_Dragging = false;
                m_State    = CreateState.Start;
                m_Object.ToMesh();
                m_Object.Refresh();
            }
            else
            {
                if (m_IsDirectSelect)
                {
                    m_DraggedPoint = m_DragOrigin + (Vector3.Project(rayOrigin.position - m_DragOrigin, m_DragDirection));
                }
                else if (m_VertexSnap.valid)
                {
                    m_DraggedPoint = m_DragOrigin + (Vector3.Project(m_VertexSnap.point - m_DragOrigin, m_DragDirection));
                }
                else
                {
                    m_DraggedPoint = VRMath.CalculateNearestPointRayRay(m_DragOrigin, m_DragDirection, rayOrigin.position, rayOrigin.forward);
                }

                if (!m_Dragging)
                {
                    m_Offset   = m_IsDirectSelect ? m_DraggedPoint - m_DragOrigin : Vector3.zero;
                    m_Dragging = true;
                }

                m_DraggedPoint -= m_Offset;

                Vector3 localDragOrigin   = m_Object.transform.InverseTransformPoint(m_DragOrigin);
                Vector3 localDraggedPoint = m_Object.transform.InverseTransformPoint(m_DraggedPoint);
                Vector3 vertexTranslation = localDraggedPoint - localDragOrigin;

                if (vertexTranslation.magnitude > MAX_TRANSLATE_DISTANCE)
                {
                    vertexTranslation = vertexTranslation.normalized * MAX_TRANSLATE_DISTANCE;
                }

                vertexTranslation = Snapping.Snap(vertexTranslation, m_SnapIncrement, VECTOR3_ONE);

                if (vertexTranslation != m_PreviousVertexTranslation)
                {
                    m_PreviousVertexTranslation = vertexTranslation;
                    m_AudioModule.Play(m_Drag);
                }

                foreach (int ind in m_SelectedIndices)
                {
                    m_SettingPositions[ind] = m_Positions[ind] + vertexTranslation;
                }

                m_Object.SetVertices(m_SettingPositions);
                m_Object.msh.vertices = m_SettingPositions;
                m_Object.RefreshUV();
                m_Object.msh.RecalculateBounds();
                m_HighlightModule.UpdateVertices(m_Object);
            }

            setHighlight(m_Object.gameObject, false);
            consumeControl(input.action);
        }
	private void TextureGroupSelectedFaces(pb_Object pb)//, pb_Face face)
	{
		if(pb.SelectedFaces.Length < 1) return;

		pb_UV cont_uv = pb.SelectedFaces[0].uv;

		int texGroup = pb.UnusedTextureGroup();

		foreach(pb_Face f in pb.SelectedFaces)
		{
			f.SetUV( new pb_UV(cont_uv) );
			f.textureGroup = texGroup;
		}

		pb.RefreshUV(pb.SelectedFaces);
		SceneView.RepaintAll();
	}
Esempio n. 5
0
	/**
	 * Sets the passed faces to use Auto or Manual UVs, and (if previously manual) splits any vertex connections.
	 */
	public static void SetAutoUV(pb_Object pb, pb_Face[] faces, bool auto)
	{
		if(auto)
		{
			faces = System.Array.FindAll(faces, x => x.manualUV).ToArray();	// only operate on faces that were previously manual

			pb.SplitUVs( pb_Face.AllTriangles(faces) );

			Vector2[][] uv_origins = new Vector2[faces.Length][];
			for(int i = 0; i < faces.Length; i++)
				uv_origins[i] = pb.GetUVs(faces[i].distinctIndices);

			for(int f = 0; f < faces.Length; f++)
			{
				faces[f].uv.Reset();
				faces[f].manualUV = !auto;
				faces[f].elementGroup = -1;
			}

			pb.RefreshUV(faces);

			for(int i = 0; i < faces.Length; i++)
			{
				pb_Transform2D transform = MatchCoordinates(pb.GetUVs(faces[i].distinctIndices), uv_origins[i]);

				faces[i].uv.offset = -transform.position;
				faces[i].uv.rotation = transform.rotation;
	
				if( Mathf.Abs(transform.scale.sqrMagnitude - 2f) > .1f )
					faces[i].uv.scale = transform.scale;
			}
		}
		else
		{
			foreach(pb_Face f in faces)
			{
				f.textureGroup = -1;
				f.manualUV = !auto;
			}
		}
	}