580 {
581 Collada.Collada._importOptions = Properties.Settings.Default.ColladaImportOptions;
582 Collada.Collada._importOptions._forceCCW = true;
583 Collada.Collada._importOptions._fltVerts = true;
584 Collada.Collada._importOptions._fltNrms = true;
585 Collada.Collada._importOptions._fltUVs = true;
586 Collada.Collada.CurrentModel = model;
587
589 model._version = 9;
590
591 List<MDL0BoneNode> BoneCache = new List<MDL0BoneNode>();
592
593 int index = 0;
595 {
597 }
598 else
599 {
601 }
602
604 {
606 }
607 else
608 {
610 }
611
612 ModelBone parent = null;
613 foreach (ModelBone b
in _bones)
614 {
616
617 if (!string.IsNullOrWhiteSpace(b._boneNameEnglish))
618 {
619 bone._name = b._boneNameEnglish;
620 }
621 else
622 {
623 bone._name = b._boneName;
624 }
625
626 bone._entryIndex = index++;
627
628 if (b._parentBoneIndex != ushort.MaxValue)
629 {
630 parent =
_bones[b._parentBoneIndex];
632 {
634 }
635 }
636 else
637 {
639 bone._bindState._scale =
new Vector3(1.0f);
640 bone._bindState._translate =
new Vector3(b._wPos[0], b._wPos[1], b._wPos[2]);
643 }
644
645 BoneCache.Add(bone);
646 }
647
648 MDL0ShaderNode texSpa =
null, tex =
null, colorSpa =
null, color =
null;
649
650 index = 0;
652 {
654 {
655 Name = "Material" + index++
656 };
657
660
661 if (!string.IsNullOrEmpty(m._textureFileName))
662 {
663 if (m._textureFileName.Contains('*'))
664 {
665 string[] names = m._textureFileName.Split('*');
666 if (!string.IsNullOrEmpty(names[0]))
667 {
669 {
670 Name = names[0].Substring(0, names[0].IndexOf('.'))
671 };
672 }
673
674 if (!string.IsNullOrEmpty(names[1]))
675 {
677 {
678 Name = names[1].Substring(0, names[1].IndexOf('.')),
685 Normalize = true
686 };
687 }
688 }
689 else
690 {
692 {
693 Name = m._textureFileName.Substring(0, m._textureFileName.IndexOf('.')),
694 Coordinates = TexSourceRow.TexCoord0
695 };
696 }
697 }
698
699 if (texRef != null)
700 {
702 texRef._parent = mn;
704 }
705
706 if (spaRef != null)
707 {
709 spaRef._parent = mn;
711 }
712
713 mn._chan1._matColor =
new RGBAPixel((
byte) (m._diffuseColor[0] * 255),
714 (byte) (m._diffuseColor[1] * 255), (byte) (m._diffuseColor[2] * 255), 255);
715 mn._chan1.ColorMaterialSource =
GXColorSrc.Register;
716
717 if (texRef != null && spaRef != null)
718 {
719 if (texSpa == null)
720 {
724 texSpa = n;
725 }
726
727 mn.ShaderNode = texSpa;
728 }
729 else if (texRef != null)
730 {
731 if (tex == null)
732 {
736 tex = n;
737 }
738
739 mn.ShaderNode = tex;
740 }
741 else if (spaRef != null)
742 {
743 if (colorSpa == null)
744 {
748 colorSpa = n;
749 }
750
751 mn.ShaderNode = colorSpa;
752 }
753 else
754 {
755 if (color == null)
756 {
760 color = n;
761 }
762
763 mn.ShaderNode = color;
764 }
765
768 }
769
770 model._numTriangles = 0;
771 model._numFacepoints = 0;
772
773 int x = 0;
774 int offset = 0;
776 {
777 PrimitiveManager manager = new PrimitiveManager {_pointCount = (int) m._faceVertCount};
779 {
780 _manager = manager,
781 _drawCalls =
new System.ComponentModel.BindingList<
DrawCall>()
782 };
784 {
786 });
787 p._manager._vertices = new List<Vertex3>();
788 p.Name = "polygon" + x++;
790
791 model._numTriangles += p._numFaces = manager._faceCount = manager._pointCount / 3;
792 model._numFacepoints += p._numFacepoints = manager._pointCount;
793
794 p._manager._indices =
new UnsafeBuffer((
int) m._faceVertCount * 2);
798
802
803 ushort* Indices = (ushort*) p.
_manager._indices.Address;
807
808 manager._triangles = new GLPrimitive((int) m._faceVertCount, BeginMode.Triangles);
809 uint[] pTriarr = manager._triangles._indices;
810 uint pTri = 0;
811
812 index = 0;
813 List<int> usedVertices = new List<int>();
814 List<int> vertexIndices = new List<int>();
815 for (int s = offset, l = 0; l < (int) m._faceVertCount; l++, s++)
816 {
819 ushort j = 0;
820 if (!usedVertices.Contains(i))
821 {
824
825 float weight = (mv._boneWeight / 100.0f).Clamp(0.0f, 1.0f);
826
827 if (weight > 0.0f && weight < 1.0f)
828 {
829 weight1 =
new BoneWeight(BoneCache[mv._boneIndex[0]], weight);
830 weight2 =
new BoneWeight(BoneCache[mv._boneIndex[1]], 1.0f - weight);
831 }
832 else if (weight == 0.0f)
833 {
834 weight1 =
new BoneWeight(BoneCache[mv._boneIndex[1]]);
835 }
836 else
837 {
838 weight1 =
new BoneWeight(BoneCache[mv._boneIndex[0]]);
839 }
840
841 if (weight2 != null)
842 {
843 inf =
new Influence(
new List<BoneWeight> {weight1, weight2});
844 }
845 else
846 {
847 inf =
new Influence(
new List<BoneWeight> {weight1});
848 }
849
851 Vertex3 v;
852 t._x = mv._position[0];
853 t._y = mv._position[1];
854 t._z = mv._position[2];
856 {
859 v = new Vertex3(t, inf);
860 }
861 else
862 {
865 }
866
868 vertexIndices.Add(usedVertices.Count);
869 usedVertices.Add(i);
870 j = (ushort) (usedVertices.Count - 1);
871 }
872 else
873 {
874 j = (ushort) vertexIndices[usedVertices.IndexOf(i)];
875 }
876
877 *Indices++ = j;
878 pTriarr[pTri++] = (uint) l;
879 *Vertices++ = p.
_manager._vertices[j].Position;
880 *Normals++ = mv._normal;
881 *UVs++ = mv._texCoord;
882 }
883
885 offset += (int) m._faceVertCount;
886 }
887
888
890 {
892 {
893 IMatrixNode node = null;
894 bool singlebind = true;
895
896 foreach (Vertex3 v
in p.
_manager._vertices)
897 {
898 if (v.MatrixNode != null)
899 {
900 if (node == null)
901 {
902 node = v.MatrixNode;
903 }
904
905 if (v.MatrixNode != node)
906 {
907 singlebind = false;
908 break;
909 }
910 }
911 }
912
913 if (singlebind && p._matrixNode == null)
914 {
915
916
917 p.
_manager._vertices[0].MatrixNode?.Users.Add(p);
918
919 foreach (Vertex3 v
in p.
_manager._vertices)
920 {
921
922 v.MatrixNode?.Users.Remove(v);
923 }
924
925 p._nodeId = -2;
926 }
927 }
928 }
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
950 Collada.Collada.CurrentModel = null;
951 }
Definition: UnsafeBuffer.cs:7
static MDL0ShaderNode ColorShader
Definition: PMDModel.cs:1174
static MDL0ShaderNode ColorSpaShader
Definition: PMDModel.cs:1052
static ushort[] _faceIndices
Definition: PMDModel.cs:159
static ModelVertex[] _vertices
Definition: PMDModel.cs:158
static MDL0ShaderNode TexShader
Definition: PMDModel.cs:1125
static MDL0ShaderNode TexSpaShader
Definition: PMDModel.cs:978
static ModelMaterial[] _materials
Definition: PMDModel.cs:160
Definition: MDL0ObjectNode.cs:2040
FrameState _bindState
Definition: MDL0BoneNode.cs:55
Matrix _inverseBindMatrix
Definition: MDL0BoneNode.cs:56
Definition: MDL0MaterialRefNode.cs:17
override string Name
Definition: MDL0MaterialRefNode.cs:41
List< ResourceNode > _objList
Definition: MDL0Node.cs:306
InfluenceManager _influences
Definition: MDL0Node.cs:50
MDL0GroupNode _matGroup
Definition: MDL0Node.cs:290
MDL0GroupNode _shadGroup
Definition: MDL0Node.cs:291
void FinishImport(Collada form=null)
Definition: MDL0Node.cs:2605
MDL0GroupNode _boneGroup
Definition: MDL0Node.cs:289
MDL0GroupNode _objGroup
Definition: MDL0Node.cs:292
List< ResourceNode > _shadList
Definition: MDL0Node.cs:305
void BeginImport()
Definition: MDL0Node.cs:2599
MDL0TextureNode FindOrCreateTexture(string name)
Definition: MDL0Node.cs:706
Definition: MDL0ObjectNode.cs:21
BindingList< DrawCall > _drawCalls
Definition: MDL0ObjectNode.cs:626
PrimitiveManager _manager
Definition: MDL0ObjectNode.cs:710
Definition: MDL0ShaderNode.cs:11
Definition: InfluenceManager.cs:381
Definition: InfluenceManager.cs:96
void CalcMatrix()
Definition: InfluenceManager.cs:271
List< BoneWeight > Weights
Don't modify this array!
Definition: InfluenceManager.cs:111
Influence FindOrCreate(Influence inf)
Definition: InfluenceManager.cs:20
GXColorSrc
Definition: MDL0MaterialNode.cs:2882
MatWrapMode
Definition: MDL0MaterialRefNode.cs:1001
MappingMethod
Definition: MDL0MaterialRefNode.cs:1024
TexInputForm
Definition: Enum.cs:560
TexSourceRow
Definition: Enum.cs:574
TexProjection
Definition: Enum.cs:554
Definition: PixelTypes.cs:327
Definition: Vector2.cs:10