コード例 #1
0
		public void SetupMeshAndMaterials(HEU_HoudiniAsset asset, HAPI_PartType partType, GameObject outputGameObject)
		{
			_outputMesh = null;
			_outputGameObject = null;

			if (HEU_HAPIUtility.IsSupportedPolygonType(partType))
			{
				// Get the generated mesh. If mesh is missing, nothing we can do.
				MeshFilter meshFilter = outputGameObject.GetComponent<MeshFilter>();
				if (meshFilter != null && meshFilter.sharedMesh != null)
				{
					_outputMesh = meshFilter.sharedMesh;
				}
				else
				{
					// Without a valid mesh, we won't be able to paint so nothing else to do
					return;
				}

				_outputGameObject = outputGameObject;

				if (_localMaterial == null)
				{
					MeshRenderer meshRenderer = _outputGameObject.GetComponent<MeshRenderer>();
					if(meshRenderer != null)
					{
						_localMaterial = HEU_MaterialFactory.GetNewMaterialWithShader(null, HEU_MaterialFactory.GetHoudiniShaderPath(HEU_Defines.DEFAULT_VERTEXCOLOR_SHADER), HEU_Defines.EDITABLE_MATERIAL, false);
					}
				}
			}
		}
コード例 #2
0
 /// <summary>
 /// Returns true if this plugin supports the given partType.
 /// Support means can convert one of Unity's native geometry.
 /// </summary>
 /// <param name="partType"></param>
 /// <returns></returns>
 public static bool IsSupportedPolygonType(HAPI_PartType partType)
 {
     return(partType == HAPI_PartType.HAPI_PARTTYPE_MESH || partType == HAPI_PartType.HAPI_PARTTYPE_BOX || partType == HAPI_PartType.HAPI_PARTTYPE_SPHERE);
 }
コード例 #3
0
	public void SetupMeshAndMaterials(HEU_HoudiniAsset asset, HAPI_PartType partType, GameObject outputGameObject)
	{
	    Color[] oldColors = _outputMesh != null && _outputMesh.isReadable ? 
		_outputMesh.colors : null;

	    _outputMesh = null;
	    _outputGameObject = null;

	    if (HEU_HAPIUtility.IsSupportedPolygonType(partType))
	    {
		// Get the generated mesh. If mesh is missing, nothing we can do.
		MeshFilter meshFilter = outputGameObject.GetComponent<MeshFilter>();
		if (meshFilter != null && meshFilter.sharedMesh != null)
		{
		    _outputMesh = meshFilter.sharedMesh;

		    if (_outputMesh.isReadable)
		    {
			Color[] newColors = _outputMesh.colors;

			if (oldColors != null)
			{
			    // Restore old colors back to newly generated mesh so
			    // as to keep color "state" for visualization

			    int oldLen = oldColors.Length;

			    if (newColors == null || newColors.Length == 0)
			    {
				newColors = new Color[_outputMesh.vertices.Length];
			    }
			    int newLen = newColors.Length;

			    for (int i = 0; i < newLen && i < oldLen; ++i)
			    {
				newColors[i] = oldColors[i];
			    }
			    _outputMesh.colors = newColors;
			    _outputMesh.UploadMeshData(false);
			}
			else if (newColors == null || newColors.Length == 0)
			{
			    // Assign new default colors
			    int count = _outputMesh.vertices.Length;
			    newColors = new Color[count];
			    for (int i = 0; i < count; ++i)
			    {
				newColors[i] = new Color(0.3f, 0.06f, 0.62f);
			    }
			    _outputMesh.colors = newColors;
			    _outputMesh.UploadMeshData(false);
			}
		    }

		}
		else
		{
		    // Without a valid mesh, we won't be able to paint so nothing else to do
		    return;
		}

		_outputGameObject = outputGameObject;

		MeshRenderer meshRenderer = _outputGameObject.GetComponent<MeshRenderer>();
		if (meshRenderer != null)
		{
		    _outputMeshRendererInitiallyEnabled = meshRenderer.enabled;

		    if (_localMaterial == null)
		    {
			_localMaterial = HEU_MaterialFactory.GetNewMaterialWithShader(null, HEU_PluginSettings.DefaultVertexColorShader, HEU_Defines.EDITABLE_MATERIAL, false);
		    }
		}
	    }
	}