private static PMDFormat.Vertex ConvertVertex(PMXFormat pmx, int vertex_index) {
		PMDFormat.Vertex result = new PMDFormat.Vertex();
		PMXFormat.Vertex pmx_vertex = pmx.vertex_list.vertex[vertex_index];
		result.pos = pmx_vertex.pos;
		result.normal_vec = pmx_vertex.normal_vec;
		result.uv = pmx_vertex.uv;
		switch (pmx_vertex.bone_weight.method) {
		case PMXFormat.Vertex.WeightMethod.BDEF1: goto case PMXFormat.Vertex.WeightMethod.BDEF2;
		case PMXFormat.Vertex.WeightMethod.BDEF2:
			//BDEF1,BDEF2なら
			//完全互換
			result.bone_num = new ushort[]{(ushort)pmx_vertex.bone_weight.bone1_ref, (ushort)pmx_vertex.bone_weight.bone2_ref};
			result.bone_weight = (byte)(pmx_vertex.bone_weight.bone1_weight * 100.0f + 0.5f);
			break;
		case PMXFormat.Vertex.WeightMethod.BDEF4:
			//BDEF4なら
			//ボーン3,4の情報を捨てる
			result.bone_num = new ushort[]{(ushort)pmx_vertex.bone_weight.bone1_ref, (ushort)pmx_vertex.bone_weight.bone2_ref};
			float bone1_weight = pmx_vertex.bone_weight.bone1_weight / (pmx_vertex.bone_weight.bone1_weight + pmx_vertex.bone_weight.bone2_weight);
			result.bone_weight = (byte)(bone1_weight * 100.0f + 0.5f);
			break;
		case PMXFormat.Vertex.WeightMethod.SDEF:
			//SDEFなら
			//SDEFの情報を捨ててBDEF2扱い
			goto case PMXFormat.Vertex.WeightMethod.BDEF2;
		case PMXFormat.Vertex.WeightMethod.QDEF:
			//QDEFなら
			//BDEF4と同じ対応
			goto case PMXFormat.Vertex.WeightMethod.BDEF4;
		default:
			throw new System.ArgumentOutOfRangeException();
		}
		result.edge_flag = (byte)((0.5f <= pmx_vertex.edge_magnification)? 1: 0);
		return result;
	}
 private static PMXFormat.Vertex ConvertVertex(PMDFormat.Vertex pmd_vertex)
 {
     PMXFormat.Vertex result = new PMXFormat.Vertex();
     result.pos        = pmd_vertex.pos;
     result.normal_vec = pmd_vertex.normal_vec;
     result.uv         = pmd_vertex.uv;
     result.add_uv     = new Vector4[0];
     if (100 == pmd_vertex.bone_weight)
     {
         //1頂点
         PMXFormat.BDEF1 bone_weight = new PMXFormat.BDEF1();
         bone_weight.bone1_ref = pmd_vertex.bone_num[0];
         result.bone_weight    = bone_weight;
     }
     else
     {
         //2頂点
         PMXFormat.BDEF2 bone_weight = new PMXFormat.BDEF2();
         bone_weight.bone1_ref    = pmd_vertex.bone_num[0];
         bone_weight.bone2_ref    = pmd_vertex.bone_num[1];
         bone_weight.bone1_weight = pmd_vertex.bone_weight / 100.0f;
         result.bone_weight       = bone_weight;
     }
     result.edge_magnification = (float)pmd_vertex.edge_flag;
     return(result);
 }
 private PMDFormat.Vertex ReadVertex()
 {
     PMDFormat.Vertex result = new PMDFormat.Vertex();
     result.pos         = ReadSinglesToVector3(binary_reader_);
     result.normal_vec  = ReadSinglesToVector3(binary_reader_);
     result.uv          = ReadSinglesToVector2(binary_reader_);
     result.bone_num    = ReadUInt16s(binary_reader_, 2);
     result.bone_weight = binary_reader_.ReadByte();
     result.edge_flag   = binary_reader_.ReadByte();
     return(result);
 }
    private static PMDFormat.Vertex ConvertVertex(PMXFormat pmx, int vertex_index)
    {
        PMDFormat.Vertex result     = new PMDFormat.Vertex();
        PMXFormat.Vertex pmx_vertex = pmx.vertex_list.vertex[vertex_index];
        result.pos        = pmx_vertex.pos;
        result.normal_vec = pmx_vertex.normal_vec;
        result.uv         = pmx_vertex.uv;
        switch (pmx_vertex.bone_weight.method)
        {
        case PMXFormat.Vertex.WeightMethod.BDEF1: goto case PMXFormat.Vertex.WeightMethod.BDEF2;

        case PMXFormat.Vertex.WeightMethod.BDEF2:
            //BDEF1,BDEF2なら
            //完全互換
            result.bone_num    = new ushort[] { (ushort)pmx_vertex.bone_weight.bone1_ref, (ushort)pmx_vertex.bone_weight.bone2_ref };
            result.bone_weight = (byte)(pmx_vertex.bone_weight.bone1_weight * 100.0f + 0.5f);
            break;

        case PMXFormat.Vertex.WeightMethod.BDEF4:
            //BDEF4なら
            //ボーン3,4の情報を捨てる
            result.bone_num = new ushort[] { (ushort)pmx_vertex.bone_weight.bone1_ref, (ushort)pmx_vertex.bone_weight.bone2_ref };
            float bone1_weight = pmx_vertex.bone_weight.bone1_weight / (pmx_vertex.bone_weight.bone1_weight + pmx_vertex.bone_weight.bone2_weight);
            result.bone_weight = (byte)(bone1_weight * 100.0f + 0.5f);
            break;

        case PMXFormat.Vertex.WeightMethod.SDEF:
            //SDEFなら
            //SDEFの情報を捨ててBDEF2扱い
            goto case PMXFormat.Vertex.WeightMethod.BDEF2;

        case PMXFormat.Vertex.WeightMethod.QDEF:
            //QDEFなら
            //BDEF4と同じ対応
            goto case PMXFormat.Vertex.WeightMethod.BDEF4;

        default:
            throw new System.ArgumentOutOfRangeException();
        }
        result.edge_flag = (byte)((0.5f <= pmx_vertex.edge_magnification)? 1: 0);
        return(result);
    }
Exemplo n.º 5
0
	private PMDFormat.Vertex ReadVertex() {
		PMDFormat.Vertex result = new PMDFormat.Vertex();
		result.pos = ReadSinglesToVector3(binary_reader_);
		result.normal_vec = ReadSinglesToVector3(binary_reader_);
		result.uv = ReadSinglesToVector2(binary_reader_);
		result.bone_num = ReadUInt16s(binary_reader_, 2);
		result.bone_weight = binary_reader_.ReadByte();
		result.edge_flag = binary_reader_.ReadByte();
		return result;
	}