private void AddInput(source collSource, string inputSemantic, string localInputSemantic = null, ulong setIndex = 0) { if (collSource != null) { Sources.Add(collSource); } if (inputSemantic != null) { var input = new InputLocal(); input.semantic = inputSemantic; input.source = "#" + collSource.id; Inputs.Add(input); } if (localInputSemantic != null) { var vertexInputOff = new InputLocalOffset(); vertexInputOff.semantic = localInputSemantic; vertexInputOff.source = "#" + collSource.id; vertexInputOff.offset = LastInputOffset++; if (localInputSemantic == "TEXCOORD" || localInputSemantic == "COLOR") { vertexInputOff.set = setIndex; } InputOffsets.Add(vertexInputOff); } }
public static InputLocal makeInput(string source, string semantic) { InputLocal input = new InputLocal(); input.source = "#" + source; input.semantic = semantic; return(input); }
private void LoadGeometryFromCollada(CollisionGroupNode parent, geometry geo) { mesh m = geo.Item as mesh; // For safety, read the model's definition of where the position data is // and grab it from there. We could just do a search for "position" in the // source list names, but this makes sure there are no errors. InputLocal pos_input = Array.Find(m.vertices.input, x => x.semantic == "POSITION"); source pos_src = Array.Find(m.source, x => x.id == pos_input.source.Trim('#')); float_array pos_arr = pos_src.Item as float_array; // For some reason Maya puts a leading space in the face index data, // so we need to trim that out before trying to parse the index string. triangles tris = m.Items[0] as triangles; string[] indices = tris.p.Trim(' ').Split(' '); int stride = tris.input.Length; // Make sure this tool can support meshes with multiple vertex attributes. for (int i = 0; i < indices.Length; i += stride * 3) { int vec1_index = Convert.ToInt32(indices[i]); int vec2_index = Convert.ToInt32(indices[i + stride]); int vec3_index = Convert.ToInt32(indices[i + (stride * 2)]); Vector3 vec1 = new Vector3((float)pos_arr.Values[vec1_index * 3], (float)pos_arr.Values[(vec1_index * 3) + 1], (float)pos_arr.Values[(vec1_index * 3) + 2]); Vector3 vec2 = new Vector3((float)pos_arr.Values[vec2_index * 3], (float)pos_arr.Values[(vec2_index * 3) + 1], (float)pos_arr.Values[(vec2_index * 3) + 2]); Vector3 vec3 = new Vector3((float)pos_arr.Values[vec3_index * 3], (float)pos_arr.Values[(vec3_index * 3) + 1], (float)pos_arr.Values[(vec3_index * 3) + 2]); // The benefit of using this library is that we easily got the up-axis // info from the file. If the up-axis was defined as Z-up, we need to // swap the Y and Z components of our vectors so the mesh isn't sideways. // (The Wind Waker is Y-up.) if (m_UpAxis == UpAxisType.Z_UP) { vec1 = SwapYZ(vec1); vec2 = SwapYZ(vec2); vec3 = SwapYZ(vec3); } CollisionTriangle new_tri = new CollisionTriangle(vec1, vec2, vec3, parent); parent.Triangles.Add(new_tri); Triangles.Add(new_tri); } }
public static source FindSourceFromInput(InputLocal input, source[] sources) { string inputSource = input.source.Trim('#'); if (sources.Any(x => x.id == inputSource)) { return(Array.Find(sources, x => x.id == inputSource)); } else { return(null); } }
protected mesh CreatePalletMesh(PalletProperties palletProperties) { // build pallet object Pallet pallet = new Pallet(palletProperties); // build list of boxes List <Box> listBoxes = pallet.BuildListOfBoxes(); // build list of vertices / normals / UVs ulong vertexCount = 0, normalCount = 0, uvCount = 0, triangleCount = 0, boxCount = 0; string triangle_string = string.Empty; List <double> doubleArrayPosition = new List <double>(), doubleArrayNormal = new List <double>(), doubleArrayUV = new List <double>(); foreach (Box box in listBoxes) { foreach (Vector3D p in box.Points) { doubleArrayPosition.Add(p.X); doubleArrayPosition.Add(p.Y); doubleArrayPosition.Add(p.Z); ++vertexCount; } foreach (Vector3D n in box.Normals) { doubleArrayNormal.Add(n.X); doubleArrayNormal.Add(n.Y); doubleArrayNormal.Add(n.Z); ++normalCount; } foreach (Vector2D uv in box.UVs) { doubleArrayUV.Add(uv.X); doubleArrayUV.Add(uv.Y); ++uvCount; } foreach (TriangleIndices tr in box.Triangles) { triangle_string += tr.ConvertToString(boxCount); ++triangleCount; } ++boxCount; } mesh palletMesh = new mesh(); // position source source palletPositionSource = new source() { id = "pallet_position", name = "pallet_position" }; float_array farrayPosition = new float_array { id = "pallet_position_float_array", count = (ulong)doubleArrayPosition.Count, Values = doubleArrayPosition.ToArray() }; palletPositionSource.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = vertexCount, source = "#pallet_position_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; palletPositionSource.Item = farrayPosition; // normal source source palletPositionNormal = new source() { id = "pallet_normal", name = "pallet_normal" }; float_array farrayNormal = new float_array { id = "pallet_normal_float_array", count = (ulong)doubleArrayNormal.Count, Values = doubleArrayNormal.ToArray() }; palletPositionNormal.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = normalCount, source = "#pallet_normal_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; palletPositionNormal.Item = farrayNormal; // uv source source palletPositionUV = new source() { id = "pallet_UV", name = "pallet_UV" }; float_array farrayUV = new float_array { id = "pallet_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() }; palletPositionUV.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 2, count = vertexCount, source = "#pallet_UV_float_array", param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } } } }; palletPositionUV.Item = farrayUV; // insert sources palletMesh.source = new source[] { palletPositionSource, palletPositionNormal, palletPositionUV }; // vertices InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#pallet_position" }; palletMesh.vertices = new vertices() { id = "pallet_vertex", input = new InputLocal[] { verticesInput } }; triangles trianglesPallet = new triangles() { material = "materialPallet", count = triangleCount }; trianglesPallet.input = new InputLocalOffset[] { new InputLocalOffset() { semantic = "VERTEX", source = "#pallet_vertex", offset = 0 } , new InputLocalOffset() { semantic = "NORMAL", source = "#pallet_normal", offset = 1 } , new InputLocalOffset() { semantic = "TEXCOORD", source = "#pallet_UV", offset = 2, set = 0, setSpecified = true } }; trianglesPallet.p = triangle_string; palletMesh.Items = new object[] { trianglesPallet }; return(palletMesh); }
protected mesh CreateCaseMesh(BoxProperties caseProperties) { // build box Box box = new Box(0, caseProperties); // build list of vertices / normals / UVs ulong vertexCount = 0, normalCount = 0, uvCount = 0; List <double> doubleArrayPosition = new List <double>(), doubleArrayNormal = new List <double>(), doubleArrayUV = new List <double>(); foreach (Vector3D p in box.PointsSmallOffset) { doubleArrayPosition.Add(p.X); doubleArrayPosition.Add(p.Y); doubleArrayPosition.Add(p.Z); ++vertexCount; } foreach (Vector3D n in box.Normals) { doubleArrayNormal.Add(n.X); doubleArrayNormal.Add(n.Y); doubleArrayNormal.Add(n.Z); ++normalCount; } foreach (Vector2D uv in box.UVs) { doubleArrayUV.Add(uv.X); doubleArrayUV.Add(uv.Y); ++uvCount; } mesh caseMesh = new mesh(); // position source source casePositionSource = new source() { id = "case_position", name = "case_position" }; float_array farrayPosition = new float_array { id = "case_position_float_array", count = (ulong)doubleArrayPosition.Count, Values = doubleArrayPosition.ToArray() }; casePositionSource.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = vertexCount, source = "#case_position_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; casePositionSource.Item = farrayPosition; // normal source source casePositionNormal = new source() { id = "case_normal", name = "case_normal" }; float_array farrayNormal = new float_array { id = "case_normal_float_array", count = (ulong)doubleArrayNormal.Count, Values = doubleArrayNormal.ToArray() }; casePositionNormal.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 3, count = normalCount, source = "#case_normal_float_array", param = new param[] { new param() { name = "X", type = "float" }, new param() { name = "Y", type = "float" }, new param() { name = "Z", type = "float" } } } }; casePositionNormal.Item = farrayNormal; // uv source source casePositionUV = new source() { id = "case_UV", name = "pallet_UV" }; float_array farrayUV = new float_array { id = "case_UV_float_array", count = (ulong)doubleArrayUV.Count, Values = doubleArrayUV.ToArray() }; casePositionUV.technique_common = new sourceTechnique_common() { accessor = new accessor() { stride = 2, count = vertexCount, source = "#case_UV_float_array", param = new param[] { new param() { name = "S", type = "float" }, new param() { name = "T", type = "float" } } } }; casePositionUV.Item = farrayUV; // insert sources caseMesh.source = new source[] { casePositionSource, casePositionNormal, casePositionUV }; // vertices InputLocal verticesInput = new InputLocal() { semantic = "POSITION", source = "#case_position" }; caseMesh.vertices = new vertices() { id = "case_vertex", input = new InputLocal[] { verticesInput } }; List <object> trianglesList = new List <object>(); // build list of triangles foreach (HalfAxis.HAxis axis in HalfAxis.All) { triangles trianglesCase = new triangles() { material = string.Format("materialCase{0}", (uint)axis), count = 2 }; trianglesCase.input = new InputLocalOffset[] { new InputLocalOffset() { semantic = "VERTEX", source = "#case_vertex", offset = 0 } , new InputLocalOffset() { semantic = "NORMAL", source = "#case_normal", offset = 1 } , new InputLocalOffset() { semantic = "TEXCOORD", source = "#case_UV", offset = 2, set = 0, setSpecified = true } }; string triangle_string = string.Empty; foreach (TriangleIndices tr in box.TrianglesByFace(axis)) { triangle_string += tr.ConvertToString(0); } trianglesCase.p = triangle_string; trianglesList.Add(trianglesCase); } // build list of lines lines linesCase = new lines() { material = "materialCaseLines", count = 12, input = new InputLocalOffset[] { new InputLocalOffset() { semantic = "VERTEX", source = "#case_vertex", offset = 0 } }, p = "0 1 1 2 2 3 3 0 4 5 5 6 6 7 7 4 0 4 1 5 2 6 3 7" }; trianglesList.Add(linesCase); caseMesh.Items = trianglesList.ToArray(); return(caseMesh); }
private void Awake() { _menuInput = new InputLocal(); }
public skin ExportSkin(List <Bone> bones, Dictionary <string, Bone> nameMaps, string geometryId) { var sources = new List <source>(); var joints = new List <string>(); var poses = new List <float>(); var boundBones = new HashSet <string>(); var orderedBones = new List <Bone>(); foreach (var boneBinding in BoneBindings) { boundBones.Add(boneBinding.BoneName); orderedBones.Add(nameMaps[boneBinding.BoneName]); } /* * Append all bones to the end of the bone list, even if they're not influencing the mesh. * We need this because some tools (eg. Blender) expect all bones to be present, otherwise their * inverse world transform would reset to identity. */ foreach (var bone in bones) { if (!boundBones.Contains(bone.Name)) { orderedBones.Add(bone); } } foreach (var bone in orderedBones) { boundBones.Add(bone.Name); joints.Add(bone.Name); var invWorldTransform = FloatsToMatrix(bone.InverseWorldTransform); invWorldTransform.Transpose(); poses.AddRange(new float[] { invWorldTransform.M11, invWorldTransform.M12, invWorldTransform.M13, invWorldTransform.M14, invWorldTransform.M21, invWorldTransform.M22, invWorldTransform.M23, invWorldTransform.M24, invWorldTransform.M31, invWorldTransform.M32, invWorldTransform.M33, invWorldTransform.M34, invWorldTransform.M41, invWorldTransform.M42, invWorldTransform.M43, invWorldTransform.M44 }); } var jointSource = ColladaUtils.MakeNameSource(Name, "joints", new string[] { "JOINT" }, joints.ToArray()); var poseSource = ColladaUtils.MakeFloatSource(Name, "poses", new string[] { "TRANSFORM" }, poses.ToArray(), 16, "float4x4"); var weightsSource = PrimaryVertexData.MakeBoneWeights(Name); var vertices = PrimaryVertexData.Deduplicator.DeduplicatedPositions; var vertexInfluenceCounts = new List <int>(vertices.Count); var vertexInfluences = new List <int>(vertices.Count); int weightIdx = 0; foreach (var vertex in vertices) { int influences = 0; var indices = vertex.BoneIndices; var weights = vertex.BoneWeights; for (int i = 0; i < 4; i++) { if (weights[i] > 0) { influences++; vertexInfluences.Add(indices[i]); vertexInfluences.Add(weightIdx++); } } vertexInfluenceCounts.Add(influences); } var jointOffsets = new InputLocalOffset(); jointOffsets.semantic = "JOINT"; jointOffsets.source = "#" + jointSource.id; jointOffsets.offset = 0; var weightOffsets = new InputLocalOffset(); weightOffsets.semantic = "WEIGHT"; weightOffsets.source = "#" + weightsSource.id; weightOffsets.offset = 1; var vertWeights = new skinVertex_weights(); vertWeights.count = (ulong)vertices.Count; vertWeights.input = new InputLocalOffset[] { jointOffsets, weightOffsets }; vertWeights.v = string.Join(" ", vertexInfluences.Select(x => x.ToString()).ToArray()); vertWeights.vcount = string.Join(" ", vertexInfluenceCounts.Select(x => x.ToString()).ToArray()); var skin = new skin(); skin.source1 = "#" + geometryId; skin.bind_shape_matrix = "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"; var skinJoints = new skinJoints(); var skinJointInput = new InputLocal(); skinJointInput.semantic = "JOINT"; skinJointInput.source = "#" + jointSource.id; var skinInvBindInput = new InputLocal(); skinInvBindInput.semantic = "INV_BIND_MATRIX"; skinInvBindInput.source = "#" + poseSource.id; skinJoints.input = new InputLocal[] { skinJointInput, skinInvBindInput }; skin.joints = skinJoints; skin.source = new source[] { jointSource, poseSource, weightsSource }; skin.vertex_weights = vertWeights; return(skin); }
public mesh ExportToCollada(ExporterOptions options) { // TODO: model transform/inverse transform? source vertexSource = null; var sources = new List <source>(); ulong inputOffset = 0; var inputs = new List <InputLocal>(); var inputOffsets = new List <InputLocalOffset>(); foreach (var component in PrimaryVertexData.VertexComponentNames) { var input = new InputLocal(); source source = null; switch (component.String) { case "Position": { source = PrimaryVertexData.MakeColladaPositions(Name); vertexSource = source; input.semantic = "POSITION"; var vertexInputOff = new InputLocalOffset(); vertexInputOff.semantic = "VERTEX"; vertexInputOff.source = "#" + source.id; vertexInputOff.offset = inputOffset++; inputOffsets.Add(vertexInputOff); break; } case "Normal": { if (options.ExportNormals) { source = PrimaryVertexData.MakeColladaNormals(Name); input.semantic = "NORMAL"; } break; } case "Tangent": { if (options.ExportTangents) { source = PrimaryVertexData.MakeColladaTangents(Name); input.semantic = "TANGENT"; } break; } case "Binormal": { if (options.ExportTangents) { source = PrimaryVertexData.MakeColladaBinormals(Name); input.semantic = "BINORMAL"; } break; } case "MaxChannel_1": case "MaxChannel_2": case "UVChannel_1": case "UVChannel_2": { if (options.ExportUVs) { int uvIndex = Int32.Parse(component.String.Substring(11)) - 1; source = PrimaryVertexData.MakeColladaUVs(Name, uvIndex); var texInputOff = new InputLocalOffset(); texInputOff.semantic = "TEXCOORD"; texInputOff.source = "#" + source.id; texInputOff.offset = inputOffset++; inputOffsets.Add(texInputOff); } break; } case "BoneWeights": case "BoneIndices": // These are handled in ExportSkin() break; case "DiffuseColor0": case "map1": // Possibly bogus D:OS name for DiffuseColor0 // TODO: This is not exported at the moment. break; default: throw new NotImplementedException("Vertex component not supported: " + component.String); } if (source != null) { sources.Add(source); } if (input.semantic != null) { input.source = "#" + source.id; inputs.Add(input); } } var triangles = PrimaryTopology.MakeColladaTriangles( inputOffsets.ToArray(), PrimaryVertexData.Deduplicator.VertexDeduplicationMap, PrimaryVertexData.Deduplicator.UVDeduplicationMaps ); var colladaMesh = new mesh(); colladaMesh.vertices = new vertices(); colladaMesh.vertices.id = Name + "-vertices"; colladaMesh.vertices.input = inputs.ToArray(); colladaMesh.source = sources.ToArray(); colladaMesh.Items = new object[] { triangles }; return(colladaMesh); }
public List <animation> ExportKeyframeTrack(TransformTrack transformTrack, string name, string target) { var track = transformTrack.ToKeyframes(); track.MergeAdjacentFrames(); track.InterpolateFrames(); var anims = new List <animation>(); var inputs = new List <InputLocal>(); var outputs = new List <float>(track.Keyframes.Count * 16); foreach (var keyframe in track.Keyframes.Values) { var transform = keyframe.ToTransform().ToMatrix4(); transform.Transpose(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { outputs.Add(transform[i, j]); } } } var interpolations = new List <string>(track.Keyframes.Count); for (int i = 0; i < track.Keyframes.Count; i++) { interpolations.Add("LINEAR"); } var knots = new List <float>(track.Keyframes.Count); foreach (var keyframe in track.Keyframes) { knots.Add(keyframe.Key); } /* * Fix up animations that have only one keyframe by adding another keyframe at * the end of the animation. * (This mainly applies to DaIdentity and DnConstant32f) */ if (track.Keyframes.Count == 1) { knots.Add(transformTrack.ParentAnimation.Duration); for (int i = 0; i < 16; i++) { outputs.Add(outputs[i]); } interpolations.Add(interpolations[0]); } var knotsSource = ColladaUtils.MakeFloatSource(name, "inputs", new string[] { "TIME" }, knots.ToArray()); var knotsInput = new InputLocal(); knotsInput.semantic = "INPUT"; knotsInput.source = "#" + knotsSource.id; inputs.Add(knotsInput); var outSource = ColladaUtils.MakeFloatSource(name, "outputs", new string[] { "TRANSFORM" }, outputs.ToArray(), 16, "float4x4"); var outInput = new InputLocal(); outInput.semantic = "OUTPUT"; outInput.source = "#" + outSource.id; inputs.Add(outInput); var interpSource = ColladaUtils.MakeNameSource(name, "interpolations", new string[] { "INTERPOLATION" }, interpolations.ToArray()); var interpInput = new InputLocal(); interpInput.semantic = "INTERPOLATION"; interpInput.source = "#" + interpSource.id; inputs.Add(interpInput); var sampler = new sampler(); sampler.id = name + "_sampler"; sampler.input = inputs.ToArray(); var channel = new channel(); channel.source = "#" + sampler.id; channel.target = target; var animation = new animation(); animation.id = name; animation.name = name; var animItems = new List <object>(); animItems.Add(knotsSource); animItems.Add(outSource); animItems.Add(interpSource); animItems.Add(sampler); animItems.Add(channel); animation.Items = animItems.ToArray(); anims.Add(animation); return(anims); }
public List <animation> ExportTransform(IList <Keyframe> keyframes, string name, string target) { var anims = new List <animation>(); var inputs = new List <InputLocal>(); var outputs = new List <float>(keyframes.Count * 16); foreach (var keyframe in keyframes) { var transform = Matrix4.Identity; if (keyframe.hasRotation) { transform *= Matrix4.CreateFromQuaternion(keyframe.rotation.Inverted()); } if (keyframe.hasScaleShear) { var scaleShear = Matrix4.Identity; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { scaleShear[i, j] = keyframe.scaleShear[i, j]; } } transform *= scaleShear; } if (keyframe.hasTranslation) { transform[0, 3] += keyframe.translation[0]; transform[1, 3] += keyframe.translation[1]; transform[2, 3] += keyframe.translation[2]; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { outputs.Add(transform[i, j]); } } } var interpolations = new List <string>(keyframes.Count); for (int i = 0; i < keyframes.Count; i++) { // TODO: Add control point estimation code and add in/out tangents for Bezier //interpolations.Add("BEZIER"); interpolations.Add("LINEAR"); } var knots = new List <float>(keyframes.Count); foreach (var keyframe in keyframes) { knots.Add(keyframe.time); } /* * Fix up animations that have only one keyframe by adding another keyframe at * the end of the animation. * (This mainly applies to DaIdentity and DnConstant32f) */ if (keyframes.Count == 1) { knots.Add(ParentAnimation.Duration); for (int i = 0; i < 16; i++) { outputs.Add(outputs[i]); } interpolations.Add(interpolations[0]); } var knotsSource = ColladaUtils.MakeFloatSource(name, "inputs", new string[] { "TIME" }, knots.ToArray()); var knotsInput = new InputLocal(); knotsInput.semantic = "INPUT"; knotsInput.source = "#" + knotsSource.id; inputs.Add(knotsInput); var outSource = ColladaUtils.MakeFloatSource(name, "outputs", new string[] { "TRANSFORM" }, outputs.ToArray(), 16, "float4x4"); var outInput = new InputLocal(); outInput.semantic = "OUTPUT"; outInput.source = "#" + outSource.id; inputs.Add(outInput); var interpSource = ColladaUtils.MakeNameSource(name, "interpolations", new string[] { "INTERPOLATION" }, interpolations.ToArray()); var interpInput = new InputLocal(); interpInput.semantic = "INTERPOLATION"; interpInput.source = "#" + interpSource.id; inputs.Add(interpInput); var sampler = new sampler(); sampler.id = name + "_sampler"; sampler.input = inputs.ToArray(); var channel = new channel(); channel.source = "#" + sampler.id; channel.target = target; var animation = new animation(); animation.id = name; animation.name = name; var animItems = new List <object>(); animItems.Add(knotsSource); animItems.Add(outSource); animItems.Add(interpSource); animItems.Add(sampler); animItems.Add(channel); animation.Items = animItems.ToArray(); anims.Add(animation); return(anims); }
public List <animation> ExportTransform(string name, string target) { var anims = new List <animation>(); if (NumKnots() > 0) { var inputs = new List <InputLocal>(); var numKnots = NumKnots(); var knots = GetKnots(); var outputs = new List <float>(knots.Count * 16); var quats = GetQuaternions(); foreach (var rotation in quats) { var transform = Matrix4.CreateFromQuaternion(rotation); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { outputs.Add(transform[i, j]); } } } var interpolations = new List <string>(numKnots); for (int i = 0; i < numKnots; i++) { // TODO: Add control point estimation code and add in/out tangents for Bezier //interpolations.Add("BEZIER"); interpolations.Add("LINEAR"); } /* * Fix up animations that have only one keyframe by adding another keyframe at * the end of the animation. * (This mainly applies to DaIdentity and DnConstant32f) */ if (numKnots == 1) { knots.Add(ParentAnimation.Duration); for (int i = 0; i < 16; i++) { outputs.Add(outputs[i]); } interpolations.Add(interpolations[0]); } var knotsSource = ColladaUtils.MakeFloatSource(name, "inputs", new string[] { "TIME" }, knots.ToArray()); var knotsInput = new InputLocal(); knotsInput.semantic = "INPUT"; knotsInput.source = "#" + knotsSource.id; inputs.Add(knotsInput); var outSource = ColladaUtils.MakeFloatSource(name, "outputs", new string[] { "TRANSFORM" }, outputs.ToArray(), 16, "float4x4"); var outInput = new InputLocal(); outInput.semantic = "OUTPUT"; outInput.source = "#" + outSource.id; inputs.Add(outInput); var interpSource = ColladaUtils.MakeNameSource(name, "interpolations", new string[] { "" }, interpolations.ToArray()); var interpInput = new InputLocal(); interpInput.semantic = "INTERPOLATION"; interpInput.source = "#" + interpSource.id; inputs.Add(interpInput); var sampler = new sampler(); sampler.id = name + "_sampler"; sampler.input = inputs.ToArray(); var channel = new channel(); channel.source = "#" + sampler.id; channel.target = target; var animation = new animation(); animation.id = name; animation.name = name; var animItems = new List <object>(); animItems.Add(knotsSource); animItems.Add(outSource); animItems.Add(interpSource); animItems.Add(sampler); animItems.Add(channel); animation.Items = animItems.ToArray(); anims.Add(animation); } return(anims); }
public animation ExportChannel(string name, string target, string paramName, int coordinate, bool isRotation) { var inputs = new List <InputLocal>(); var numKnots = NumKnots(); var knots = GetKnots(); var outputs = ExportChannelControlData(coordinate, isRotation); var interpolations = new List <string>(numKnots); for (int i = 0; i < numKnots; i++) { // TODO: Add control point estimation code and add in/out tangents for Bezier //interpolations.Add("BEZIER"); interpolations.Add("LINEAR"); } /* * Fix up animations that have only one keyframe by adding another keyframe at * the end of the animation. * (This mainly applies to DaIdentity and DnConstant32f) */ if (numKnots == 1) { knots.Add(ParentAnimation.Duration); outputs.Add(outputs[0]); interpolations.Add(interpolations[0]); } var knotsSource = ColladaUtils.MakeFloatSource(name, "inputs", new string[] { "TIME" }, knots.ToArray()); var knotsInput = new InputLocal(); knotsInput.semantic = "INPUT"; knotsInput.source = "#" + knotsSource.id; inputs.Add(knotsInput); var outSource = ColladaUtils.MakeFloatSource(name, "outputs", new string[] { paramName }, outputs.ToArray()); var outInput = new InputLocal(); outInput.semantic = "OUTPUT"; outInput.source = "#" + outSource.id; inputs.Add(outInput); var interpSource = ColladaUtils.MakeNameSource(name, "interpolations", new string[] { "" }, interpolations.ToArray()); var interpInput = new InputLocal(); interpInput.semantic = "INTERPOLATION"; interpInput.source = "#" + interpSource.id; inputs.Add(interpInput); var sampler = new sampler(); sampler.id = name + "_sampler"; sampler.input = inputs.ToArray(); var channel = new channel(); channel.source = "#" + sampler.id; channel.target = target; var animation = new animation(); animation.id = name; animation.name = name; var animItems = new List <object>(); animItems.Add(knotsSource); animItems.Add(outSource); animItems.Add(interpSource); animItems.Add(sampler); animItems.Add(channel); animation.Items = animItems.ToArray(); return(animation); }