Created
January 12, 2015 20:50
-
-
Save ousttrue/7e27b4535f929b5b7000 to your computer and use it in GitHub Desktop.
GeometryMeshLoaderNode for VVVV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region usings | |
using System; | |
using System.ComponentModel.Composition; | |
using VVVV.PluginInterfaces.V1; | |
using VVVV.PluginInterfaces.V2; | |
using VVVV.Utils.VColor; | |
using VVVV.Utils.VMath; | |
using VVVV.Core.Logging; | |
#endregion usings | |
using System.Linq; | |
namespace VVVV.Nodes | |
{ | |
#region PluginInfo | |
[PluginInfo(Name = "MeshLoader" | |
, Category = "Geometry" | |
, Help = "Basic template with one value in/out" | |
, Tags = "" | |
, AutoEvaluate = true | |
)] | |
#endregion PluginInfo | |
public class GeometryMeshLoaderNode : IPluginEvaluate | |
{ | |
#region fields & pins | |
[Input("Path" | |
, StringType = StringType.Filename | |
, FileMask = "MMD File (*.pmd)|*.pmd" | |
, IsSingle=true | |
)] | |
public ISpread<string> Path; | |
[Output("Positions")] | |
public ISpread<Vector3D> Positions; | |
[Output("Normals")] | |
public ISpread<Vector3D> Normals; | |
[Output("TextureCoords")] | |
public ISpread<Vector2D> TextureCoords; | |
[Output("Colors")] | |
public ISpread<RGBAColor> Colors; | |
[Output("Indices")] | |
public ISpread<int> Indices; | |
[Import()] | |
public ILogger FLogger; | |
#endregion fields & pins | |
PmdModel Model | |
{ | |
get; | |
set; | |
} | |
//called when data for any output pin is requested | |
public void Evaluate(int SpreadMax) | |
{ | |
if(Model==null){ | |
var model = PmdModel.Load(Path[0]); | |
Model = model; | |
if (model == null) | |
{ | |
Positions.SliceCount = 0; | |
Normals.SliceCount = 0; | |
TextureCoords.SliceCount = 0; | |
Colors.SliceCount = 0; | |
Indices.SliceCount = 0; | |
} | |
else | |
{ | |
Positions.AssignFrom(model.Vertices.Select(v => v.Position.ToVVVV())); | |
Normals.AssignFrom(model.Vertices.Select(v => v.Normal.ToVVVV())); | |
TextureCoords.AssignFrom(model.Vertices.Select(v => v.UV.ToVVVV())); | |
Colors.AssignFrom(model.Vertices.Select(v => new RGBAColor(1.0, 1.0, 1.0, 1.0))); | |
Indices.AssignFrom(model.Indices); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment