public override void Draw(GL_ControlModern control, Pass pass, EditorSceneBase editorScene) { if (pass == Pass.TRANSPARENT) { return; } bool hovered = editorScene.Hovered == this; if (IsNormalTanTransform) { control.UpdateModelMatrix(Matrix4.CreateScale(scale) * MatrixExenstion.CreateRotation(Normal, Tangent) * Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(Position) : Position)); } else { control.UpdateModelMatrix(Matrix4.CreateScale(scale) * (Matrix4.CreateRotationX(rotate.X) * Matrix4.CreateRotationY(rotate.Y) * Matrix4.CreateRotationZ(rotate.Z)) * Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(Position) : Position)); } Vector4 blockColor; Vector4 lineColor; if (hovered && Selected) { lineColor = hoverColor; } else if (hovered || Selected) { lineColor = selectColor; } else { lineColor = Color; } if (hovered && Selected) { blockColor = Color * 0.5f + hoverColor * 0.5f; } else if (hovered || Selected) { blockColor = Color * 0.5f + selectColor * 0.5f; } else { blockColor = Color; } Renderers.ColorBlockRenderer.Draw(control, pass, blockColor, lineColor, control.NextPickingColor()); }
public static Model SetModel(FMDL fmdl) { Model model = new Model(); model.Name = fmdl.Text; model.Path = ""; model.Shapes = new ResDict <Shape>(); model.VertexBuffers = new List <VertexBuffer>(); model.Materials = new ResDict <Material>(); model.UserData = new ResDict <UserData>(); model.Skeleton = new Skeleton(); model.Skeleton = fmdl.Skeleton.node.SkeletonU; model.UserData = fmdl.ModelU.UserData; if (model.Skeleton.InverseModelMatrices == null) { model.Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>(); } if (model.Skeleton.MatrixToBoneList == null) { model.Skeleton.MatrixToBoneList = new List <ushort>(); } foreach (var bone in fmdl.Skeleton.bones) { if (model.Skeleton.InverseModelMatrices.Count <= 0) { break; } int inde = 0; foreach (var bn in model.Skeleton.Bones.Values) { if (bone.Text == bn.Name) { var mat = MatrixExenstion.GetMatrixInverted(bone); if (bn.SmoothMatrixIndex > -1) { model.Skeleton.InverseModelMatrices[bn.SmoothMatrixIndex] = mat; } } inde++; } } int i = 0; var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c); foreach (var shape in duplicates) { shape.Text += i++; } foreach (FSHP shape in fmdl.shapes) { BFRES.CheckMissingTextures(shape); SetShape(shape, shape.ShapeU); model.Shapes.Add(shape.Text, shape.ShapeU); model.VertexBuffers.Add(shape.VertexBufferU); shape.ShapeU.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1); // BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape); } foreach (FMAT mat in fmdl.materials.Values) { SetMaterial(mat, mat.MaterialU, fmdl.GetResFileU()); model.Materials.Add(mat.Text, mat.MaterialU); } return(model); }
public void CalculateIndices() { if (node.SkeletonU != null) { var Skeleton = node.SkeletonU; if (Skeleton.InverseModelMatrices == null) { Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>(); } List <Syroot.Maths.Matrix3x4> SmoothMatrices = new List <Syroot.Maths.Matrix3x4>(); foreach (var Bone in Skeleton.Bones.Values) { Bone.InverseMatrix = new Syroot.Maths.Matrix3x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0); } foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones.Values) { if (bn.Text == Bone.Name) { if (bn.UseSmoothMatrix) { var mat = MatrixExenstion.GetMatrixInverted(bn); Bone.InverseMatrix = mat; SmoothMatrices.Add(mat); } } BoneIndex++; } } Skeleton.InverseModelMatrices = SmoothMatrices; } else { var Skeleton = node.Skeleton; if (Skeleton.InverseModelMatrices == null) { Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>(); } List <Syroot.Maths.Matrix3x4> SmoothMatrices = new List <Syroot.Maths.Matrix3x4>(); foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones) { if (bn.Text == Bone.Name) { if (bn.UseSmoothMatrix || bn.SmoothMatrixIndex != -1) { var mat = MatrixExenstion.GetMatrixInverted(bn); SmoothMatrices.Add(mat); } } BoneIndex++; } } Skeleton.InverseModelMatrices = SmoothMatrices; } }
public void CalculateIndices() { if (node.SkeletonU != null) { var Skeleton = node.SkeletonU; if (Skeleton.InverseModelMatrices == null) { Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>(); } if (Skeleton.MatrixToBoneList == null) { Skeleton.MatrixToBoneList = new List <ushort>(); } //Generate index list List <ushort> SmoothIndices = new List <ushort>(); List <Syroot.Maths.Matrix3x4> SmoothMatrices = new List <Syroot.Maths.Matrix3x4>(); List <ushort> RigidIndices = new List <ushort>(); foreach (var Bone in Skeleton.Bones.Values) { Bone.InverseMatrix = new Syroot.Maths.Matrix3x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0); } ushort SmoothIndex = 0; foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones.Values) { if (bn.Text == Bone.Name) { if (bn.UseSmoothMatrix || bn.SmoothMatrixIndex != -1) { bn.SmoothMatrixIndex = (short)SmoothIndex++; Bone.SmoothMatrixIndex = bn.SmoothMatrixIndex; SmoothIndices.Add(BoneIndex); var mat = MatrixExenstion.GetMatrixInverted(bn); Bone.InverseMatrix = mat; SmoothMatrices.Add(mat); } } BoneIndex++; } } //Rigid Indices come after smooth indices. Start from the last smooth index ushort RigidIndex = (ushort)(SmoothIndices.Count); foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones.Values) { if (bn.Text == Bone.Name) { if (bn.UseRigidMatrix || bn.RigidMatrixIndex != -1) { bn.RigidMatrixIndex = (short)RigidIndex++; Bone.RigidMatrixIndex = bn.RigidMatrixIndex; RigidIndices.Add(BoneIndex); } } BoneIndex++; } } //Rigid indices at the end var AllIndices = SmoothIndices.Concat(RigidIndices).ToList(); Skeleton.MatrixToBoneList = AllIndices.ToArray(); Skeleton.InverseModelMatrices = SmoothMatrices; } else { var Skeleton = node.Skeleton; if (Skeleton.InverseModelMatrices == null) { Skeleton.InverseModelMatrices = new List <Syroot.Maths.Matrix3x4>(); } if (Skeleton.MatrixToBoneList == null) { Skeleton.MatrixToBoneList = new List <ushort>(); } //Generate index list List <ushort> SmoothIndices = new List <ushort>(); List <Syroot.Maths.Matrix3x4> SmoothMatrices = new List <Syroot.Maths.Matrix3x4>(); List <ushort> RigidIndices = new List <ushort>(); ushort SmoothIndex = 0; foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones) { if (bn.Text == Bone.Name) { if (bn.UseSmoothMatrix || bn.SmoothMatrixIndex != -1) { bn.SmoothMatrixIndex = (short)SmoothIndex++; Bone.SmoothMatrixIndex = bn.SmoothMatrixIndex; SmoothIndices.Add(BoneIndex); var mat = MatrixExenstion.GetMatrixInverted(bn); SmoothMatrices.Add(mat); } } BoneIndex++; } } //Rigid Indices come after smooth indices. Start from the last smooth index ushort RigidIndex = (ushort)(SmoothIndices.Count); foreach (BfresBone bn in bones) { ushort BoneIndex = 0; foreach (var Bone in Skeleton.Bones) { if (bn.Text == Bone.Name) { if (bn.UseRigidMatrix || bn.RigidMatrixIndex != -1) { bn.RigidMatrixIndex = (short)RigidIndex++; Bone.RigidMatrixIndex = bn.RigidMatrixIndex; RigidIndices.Add(BoneIndex); } } BoneIndex++; } } //Rigid indices at the end var AllIndices = SmoothIndices.Concat(RigidIndices).ToList(); Skeleton.MatrixToBoneList = AllIndices.ToArray(); Skeleton.InverseModelMatrices = SmoothMatrices; } }