You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
2.7 KiB

using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
namespace UnityEditor.VFX.Operator
{
class SampleMeshIndexCountProvider : SampleMeshProvider
{
protected override string nameTemplate { get; } = "Get {0} Index Count";
protected override Type operatorType { get; } = typeof(MeshIndexCount);
}
[VFXHelpURL("Operator-MeshIndexCount")]
[VFXInfo(variantProvider = typeof(SampleMeshIndexCountProvider))]
class MeshIndexCount : VFXOperator
{
override public string name
{
get
{
if (source == SampleMesh.SourceType.Mesh)
return "Get Mesh Index Count";
else
return "Get Skinned Mesh Index Count";
}
}
public class InputPropertiesMesh
{
[Tooltip("Specifies the Mesh to sample from.")]
public Mesh mesh = VFXResources.defaultResources.mesh;
}
public class InputPropertiesSkinnedMeshRenderer
{
[Tooltip("Specifies the Skinned Mesh Renderer component to sample from. The Skinned Mesh Renderer has to be an exposed entry.")]
public SkinnedMeshRenderer skinnedMesh = null;
}
public class OutputProperties
{
[Tooltip("The number of indices in this mesh")]
public uint count;
}
[VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("Specifies the kind of geometry to sample from.")]
private SampleMesh.SourceType source = SampleMesh.SourceType.Mesh;
protected sealed override IEnumerable<VFXPropertyWithValue> inputProperties
{
get
{
var props = base.inputProperties;
if (source == SampleMesh.SourceType.Mesh)
props = props.Concat(PropertiesFromType(nameof(InputPropertiesMesh)));
else if (source == SampleMesh.SourceType.SkinnedMeshRenderer)
props = props.Concat(PropertiesFromType(nameof(InputPropertiesSkinnedMeshRenderer)));
else
throw new InvalidOperationException("Unexpected source type : " + source);
return props;
}
}
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
{
var mesh = inputExpression[0].valueType == VFXValueType.Mesh ? inputExpression[0] : new VFXExpressionMeshFromSkinnedMeshRenderer(inputExpression[0]);
var meshIndexCount = new VFXExpressionMeshIndexCount(mesh);
return new VFXExpression[] { meshIndexCount };
}
}
}