Exemplo n.º 1
0
        private void AddGizmoCubeParts(MyGizmoSpaceProperties gizmoSpace, MyBlockBuilderRenderData renderData, ref MatrixD invGridWorldMatrix, MyCubeBlockDefinition definition)
        {
            Vector3UByte[] bones = null;
            MyTileDefinition[] tiles = null;
            MatrixD invGridWorldMatrixOrientation = invGridWorldMatrix.GetOrientation();
            float gridSize = 1f;
            if (definition != null && definition.Skeleton != null)
            {
                tiles = MyCubeGridDefinitions.GetCubeTiles(definition);
                gridSize = MyDefinitionManager.Static.GetCubeSize(definition.CubeSize);
            }

            for (int faceIndex = 0; faceIndex < gizmoSpace.m_cubeModelsTemp.Count; faceIndex++)
            {
                string cubePartModel = gizmoSpace.m_cubeModelsTemp[faceIndex];

                gizmoSpace.m_cubeModels.Add(cubePartModel);
                gizmoSpace.m_cubeMatrices.Add(gizmoSpace.m_cubeMatricesTemp[faceIndex]);

                int tileIndex = faceIndex % tiles.Count();

                var invertedTile = Matrix.Transpose(tiles[tileIndex].LocalMatrix);
                var onlyOrientation = invertedTile * gizmoSpace.m_cubeMatricesTemp[faceIndex].GetOrientation();
                var boneMatrix = onlyOrientation * invGridWorldMatrixOrientation;

                if (tiles != null)
                {
                    bones = new Vector3UByte[9];
                    for (int i = 0; i < 9; i++)
                    {
                        bones[i] = new Vector3UByte(128, 128, 128);
                    }

                    var model = MyModels.GetModel(cubePartModel);

                    for (int index = 0; index < Math.Min(model.BoneMapping.Length, 9); index++)
                    {
                        var boneOffset = model.BoneMapping[index];
                        Vector3 centered = boneOffset - Vector3.One;

                        Vector3I transformedOffset = Vector3I.Round(Vector3.Transform(centered, tiles[tileIndex].LocalMatrix) + Vector3.One);

                        for (int skeletonIndex = 0; skeletonIndex < definition.Skeleton.Count; skeletonIndex++)
                        {
                            BoneInfo skeletonBone = definition.Skeleton[skeletonIndex];
                            if (skeletonBone.BonePosition == (SerializableVector3I)transformedOffset)
                            {
                                Vector3 bone = Vector3UByte.Denormalize(skeletonBone.BoneOffset, gridSize);
                                Vector3 transformedBone = Vector3.Transform(bone, boneMatrix);
                                bones[index] = Vector3UByte.Normalize(transformedBone, gridSize);
                                break;
                            }
                        }
                    }
                }

                renderData.AddInstance(MyModel.GetId(cubePartModel), gizmoSpace.m_cubeMatricesTemp[faceIndex], ref invGridWorldMatrix, bones: bones, gridSize: gridSize);
            }
        }
Exemplo n.º 2
0
 public void UpdateGizmoCubeParts(MyGizmoSpaceProperties gizmoSpace, MyBlockBuilderRenderData renderData, ref MatrixD invGridWorldMatrix, MyCubeBlockDefinition definition = null)
 {
     RemoveGizmoCubeParts(gizmoSpace);
     AddGizmoCubeParts(gizmoSpace, renderData, ref invGridWorldMatrix, definition);
 }