1292 {
1293 string[] types = new[] {"scale", "rotate", "translate"};
1294 string[] axes = new[] {"X", "Y", "Z"};
1295 bool first = true;
1296
1297 using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None,
1298 0x1000, FileOptions.SequentialScan))
1299 {
1300 using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
1301 {
1302 writer.Flush();
1303 stream.Position = 0;
1304
1305 writer.WriteStartDocument();
1306 writer.WriteStartElement("COLLADA", "http://www.collada.org/2008/03/COLLADASchema");
1307 writer.WriteAttributeString("version", "1.4.1");
1308
1309 writer.WriteStartElement("asset");
1310 writer.WriteStartElement("contributor");
1311 writer.WriteElementString("authoring_tool", Application.ProductName);
1312 writer.WriteEndElement();
1313 writer.WriteEndElement();
1314
1315 writer.WriteStartElement("library_animations");
1316 {
1317 foreach (
CHR0Node animation
in animations)
1318 {
1319 string animName = animation.
Name;
1320
1321 writer.WriteStartElement("animation");
1322 writer.WriteAttributeString("name", animName);
1323 writer.WriteAttributeString("id", animName);
1324 {
1326 {
1327 string bone = en.
Name;
1329
1330 for (int index = 0; index < 9; index++)
1331 {
1332 int keyFrameCount = keyframes.
_keyArrays[index]._keyCount;
1334
1335 if (keyFrameCount <= 0)
1336 {
1337 continue;
1338 }
1339
1340 string type = types[index / 3];
1341 string axis = axes[index % 3];
1342
1343 string name = $"{bone}_{type}{axis}";
1344
1345
1346
1347 {
1348 #region Input source
1349
1350 writer.WriteStartElement("source");
1351 writer.WriteAttributeString("id", name + "_input");
1352 {
1353 writer.WriteStartElement("float_array");
1354 writer.WriteAttributeString("id", name + "_inputArr");
1355 writer.WriteAttributeString("count", keyFrameCount.ToString());
1356 {
1357 first = true;
1359 entry != root;
1360 entry = entry.
_next)
1361 {
1362 if (first)
1363 {
1364 first = false;
1365 }
1366 else
1367 {
1368 writer.WriteString(" ");
1369 }
1370
1371 writer.WriteString(
1372 (entry._index / fps).ToString(CultureInfo
1373 .InvariantCulture
1374 .NumberFormat));
1375 }
1376 }
1377 writer.WriteEndElement();
1378
1379 writer.WriteStartElement("technique_common");
1380 {
1381 writer.WriteStartElement("accessor");
1382 writer.WriteAttributeString("source", "#" + name + "_inputArr");
1383 writer.WriteAttributeString("count", keyFrameCount.ToString());
1384 writer.WriteAttributeString("stride", "1");
1385 {
1386 writer.WriteStartElement("param");
1387 writer.WriteAttributeString("name", "TIME");
1388 writer.WriteAttributeString("type", "float");
1389 writer.WriteEndElement();
1390 }
1391 writer.WriteEndElement();
1392 }
1393 writer.WriteEndElement();
1394
1395 writer.WriteStartElement("technique");
1396 writer.WriteAttributeString("profile", "MAYA");
1397 {
1398 writer.WriteStartElement("pre_infinity");
1399 writer.WriteString("CONSTANT");
1400 writer.WriteEndElement();
1401
1402 writer.WriteStartElement("post_infinity");
1403 writer.WriteString("CONSTANT");
1404 writer.WriteEndElement();
1405 }
1406 writer.WriteEndElement();
1407 }
1408 writer.WriteEndElement();
1409
1410 #endregion
1411
1412 #region Output source
1413
1414 writer.WriteStartElement("source");
1415 writer.WriteAttributeString("id", name + "_output");
1416 {
1417 writer.WriteStartElement("float_array");
1418 writer.WriteAttributeString("id", name + "_outputArr");
1419 writer.WriteAttributeString("count", keyFrameCount.ToString());
1420 {
1421 first = true;
1423 entry != root;
1424 entry = entry.
_next)
1425 {
1426 if (first)
1427 {
1428 first = false;
1429 }
1430 else
1431 {
1432 writer.WriteString(" ");
1433 }
1434
1435 writer.WriteString(
1436 entry._value.ToString(CultureInfo
1437 .InvariantCulture.NumberFormat));
1438 }
1439 }
1440 writer.WriteEndElement();
1441
1442 writer.WriteStartElement("technique_common");
1443 {
1444 writer.WriteStartElement("accessor");
1445 writer.WriteAttributeString("source", "#" + name + "_outputArr");
1446 writer.WriteAttributeString("count", keyFrameCount.ToString());
1447 writer.WriteAttributeString("stride", "1");
1448 {
1449 writer.WriteStartElement("param");
1450 writer.WriteAttributeString("name", "TRANSFORM");
1451 writer.WriteAttributeString("type", "float");
1452 writer.WriteEndElement();
1453 }
1454 writer.WriteEndElement();
1455 }
1456 writer.WriteEndElement();
1457 }
1458 writer.WriteEndElement();
1459
1460 #endregion
1461
1462 #region In Tangent source
1463
1464 writer.WriteStartElement("source");
1465 writer.WriteAttributeString("id", name + "_inTan");
1466 {
1467 writer.WriteStartElement("float_array");
1468 writer.WriteAttributeString("id", name + "_inTanArr");
1469 writer.WriteAttributeString("count", keyFrameCount.ToString());
1470 {
1471 first = true;
1473 entry != root;
1474 entry = entry.
_next)
1475 {
1476 if (first)
1477 {
1478 first = false;
1479 }
1480 else
1481 {
1482 writer.WriteString(" ");
1483 }
1484
1485 writer.WriteString(
1486 entry._tangent.ToString(CultureInfo
1487 .InvariantCulture.NumberFormat));
1488 }
1489 }
1490 writer.WriteEndElement();
1491
1492 writer.WriteStartElement("technique_common");
1493 {
1494 writer.WriteStartElement("accessor");
1495 writer.WriteAttributeString("source", "#" + name + "_inTanArr");
1496 writer.WriteAttributeString("count", keyFrameCount.ToString());
1497 writer.WriteAttributeString("stride", "1");
1498 {
1499 writer.WriteStartElement("param");
1500 writer.WriteAttributeString("name", "IN_TANGENT");
1501 writer.WriteAttributeString("type", "float");
1502 writer.WriteEndElement();
1503 }
1504 writer.WriteEndElement();
1505 }
1506 writer.WriteEndElement();
1507 }
1508 writer.WriteEndElement();
1509
1510 #endregion
1511
1512 #region Out Tangent source
1513
1514 writer.WriteStartElement("source");
1515 writer.WriteAttributeString("id", name + "_outTan");
1516 {
1517 writer.WriteStartElement("float_array");
1518 writer.WriteAttributeString("id", name + "_outTanArr");
1519 writer.WriteAttributeString("count", keyFrameCount.ToString());
1520 {
1521 first = true;
1523 entry != root;
1524 entry = entry.
_next)
1525 {
1526 if (first)
1527 {
1528 first = false;
1529 }
1530 else
1531 {
1532 writer.WriteString(" ");
1533 }
1534
1535 writer.WriteString(
1536 entry._tangent.ToString(CultureInfo
1537 .InvariantCulture.NumberFormat));
1538 }
1539 }
1540 writer.WriteEndElement();
1541
1542 writer.WriteStartElement("technique_common");
1543 {
1544 writer.WriteStartElement("accessor");
1545 writer.WriteAttributeString("source", "#" + name + "_outTanArr");
1546 writer.WriteAttributeString("count", keyFrameCount.ToString());
1547 writer.WriteAttributeString("stride", "1");
1548 {
1549 writer.WriteStartElement("param");
1550 writer.WriteAttributeString("name", "OUT_TANGENT");
1551 writer.WriteAttributeString("type", "float");
1552 writer.WriteEndElement();
1553 }
1554 writer.WriteEndElement();
1555 }
1556 writer.WriteEndElement();
1557 }
1558 writer.WriteEndElement();
1559
1560 #endregion
1561
1562 #region Interpolation source
1563
1564 writer.WriteStartElement("source");
1565 writer.WriteAttributeString("id", name + "_interp");
1566 {
1567 writer.WriteStartElement("Name_array");
1568 writer.WriteAttributeString("id", name + "_interpArr");
1569 writer.WriteAttributeString("count", keyFrameCount.ToString());
1570 {
1571 first = true;
1573 entry != root;
1574 entry = entry.
_next)
1575 {
1576 if (first)
1577 {
1578 first = false;
1579 }
1580 else
1581 {
1582 writer.WriteString(" ");
1583 }
1584
1585 writer.WriteString("HERMITE");
1586 }
1587 }
1588 writer.WriteEndElement();
1589
1590 writer.WriteStartElement("technique_common");
1591 {
1592 writer.WriteStartElement("accessor");
1593 writer.WriteAttributeString("source", "#" + name + "_interpArr");
1594 writer.WriteAttributeString("count", keyFrameCount.ToString());
1595 writer.WriteAttributeString("stride", "1");
1596 {
1597 writer.WriteStartElement("param");
1598 writer.WriteAttributeString("name", "INTERPOLATION");
1599 writer.WriteAttributeString("type", "Name");
1600 writer.WriteEndElement();
1601 }
1602 writer.WriteEndElement();
1603 }
1604 writer.WriteEndElement();
1605 }
1606 writer.WriteEndElement();
1607
1608 #endregion
1609
1610 #region Sampler
1611
1612 writer.WriteStartElement("sampler");
1613 writer.WriteAttributeString("id", name + "_sampler");
1614 {
1615 writer.WriteStartElement("input");
1616 writer.WriteAttributeString("semantic", "INPUT");
1617 writer.WriteAttributeString("source", "#" + name + "_input");
1618 writer.WriteEndElement();
1619
1620 writer.WriteStartElement("input");
1621 writer.WriteAttributeString("semantic", "OUTPUT");
1622 writer.WriteAttributeString("source", "#" + name + "_output");
1623 writer.WriteEndElement();
1624
1625 writer.WriteStartElement("input");
1626 writer.WriteAttributeString("semantic", "IN_TANGENT");
1627 writer.WriteAttributeString("source", "#" + name + "_inTan");
1628 writer.WriteEndElement();
1629
1630 writer.WriteStartElement("input");
1631 writer.WriteAttributeString("semantic", "OUT_TANGEN");
1632 writer.WriteAttributeString("source", "#" + name + "_outTan");
1633 writer.WriteEndElement();
1634
1635 writer.WriteStartElement("input");
1636 writer.WriteAttributeString("semantic", "INTERPOLATION");
1637 writer.WriteAttributeString("source", "#" + name + "_interp");
1638 writer.WriteEndElement();
1639 }
1640 writer.WriteEndElement();
1641
1642 #endregion
1643
1644 writer.WriteStartElement("channel");
1645 writer.WriteAttributeString("source", "#" + name + "_sampler");
1646 writer.WriteAttributeString("target",
1647 $"{bone}/{type}.{axis}");
1648 writer.WriteEndElement();
1649 }
1650
1651 }
1652 }
1653 }
1654 writer.WriteEndElement();
1655 }
1656
1657 writer.WriteEndElement();
1658 }
1659 }
1660 }
1661 }
Definition: CHR0Node.cs:909
KeyframeCollection Keyframes
Definition: CHR0Node.cs:923
Definition: CHR0Node.cs:17
Definition: KeyframeCollection.cs:17
KeyframeArray[] _keyArrays
Definition: KeyframeCollection.cs:18
Definition: KeyframeCollection.cs:193
KeyframeEntry _next
Definition: KeyframeCollection.cs:195