예제 #1
0
        public void ImportModel(string filePath, bool legacyImport = false)
        {
            NJS_OBJECT newmodel;

            // Old OBJ import (with vcolor face) for NodeTable and legacy import
            if (legacyImport)
            {
                newmodel = new NJS_OBJECT
                {
                    Attach = SAModel.Direct3D.Extensions.obj2nj(filePath, LevelData.TextureBitmaps != null ? LevelData.TextureBitmaps[LevelData.leveltexs].Select(a => a.Name).ToArray() : null),
                };
                COL.Model.Attach = newmodel.Attach;
                COL.Model.ProcessVertexData();
                Visible = true;
                Solid   = true;
                mesh    = COL.Model.Attach.CreateD3DMesh();
                return;
            }
            Assimp.AssimpContext context = new Assimp.AssimpContext();
            context.SetConfig(new Assimp.Configs.FBXPreservePivotsConfig(false));
            Assimp.Scene scene = context.ImportFile(filePath, Assimp.PostProcessSteps.Triangulate | Assimp.PostProcessSteps.JoinIdenticalVertices | Assimp.PostProcessSteps.FlipUVs);
            newmodel         = SAEditorCommon.Import.AssimpStuff.AssimpImport(scene, scene.RootNode, ModelFormat.BasicDX, LevelData.TextureBitmaps[LevelData.leveltexs].Select(a => a.Name).ToArray(), true);
            COL.Model.Attach = newmodel.Attach;
            COL.Model.ProcessVertexData();
            Visible = true;
            Solid   = true;
            mesh    = COL.Model.Attach.CreateD3DMesh();
        }
예제 #2
0
 public override void Init(ObjectData data, string name)
 {
     mesh     = Mesh.Box(1f, 1f, 1f);
     material = new NJS_MATERIAL
     {
         DiffuseColor = Color.FromArgb(180, 180, 180, 180),
         UseAlpha     = true
     };
 }
예제 #3
0
 public override void Init(ObjectData data, string name)
 {
     mesh     = Mesh.Box(0.5f, 0.5f, 0.5f);
     material = new NJS_MATERIAL
     {
         DiffuseColor = Color.FromArgb(127, 178, 178, 178),
         UseAlpha     = false
     };
 }
예제 #4
0
        /// <summary>
        /// Creates a LevelItem from an existing COL data.
        /// </summary>
        /// <param name="col"></param>
        /// <param name="dev">Current Direct3d Device.</param>
        public LevelItem(COL col, int index, EditorItemSelection selectionManager)
            : base(selectionManager)
        {
            this.index = index;
            COL        = col;
            col.Model.ProcessVertexData();
            Mesh = col.Model.Attach.CreateD3DMesh();

            GetHandleMatrix();
        }
예제 #5
0
        public void EditModel()
        {
            ModelDataEditor me = new ModelDataEditor(COL.Model);

            if (me.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                COL.Model = me.editedHierarchy.Clone();
                COL.Model.ProcessVertexData();
                mesh = COL.Model.Attach.CreateD3DMesh();
                COL.Model.Attach.CalculateBounds();
                LevelData.InvalidateRenderState();
            }
        }
예제 #6
0
 public static Mesh[] GetMeshes(NJS_OBJECT model)
 {
     model.ProcessVertexData();
     NJS_OBJECT[] models = model.GetObjects();
     Mesh[]       Meshes = new Mesh[models.Length];
     for (int i = 0; i < models.Length; i++)
     {
         if (models[i].Attach != null)
         {
             Meshes[i] = models[i].Attach.CreateD3DMesh();
         }
     }
     return(Meshes);
 }
예제 #7
0
 /// <summary>
 /// Creates a new instance of an existing item with the specified position and rotation.
 /// </summary>
 /// <param name="attach">Attach to use for this levelItem</param>
 /// <param name="position">Position in worldspace to place this LevelItem.</param>
 /// <param name="rotation">Rotation.</param>
 public LevelItem(Attach attach, Vertex position, Rotation rotation, int index, EditorItemSelection selectionManager)
     : base(selectionManager)
 {
     this.index = index;
     COL        = new COL
     {
         Model = new NJS_OBJECT
         {
             Attach   = attach,
             Position = position,
             Rotation = rotation
         }
     };
     Visible = true;
     Solid   = true;
     COL.CalculateBounds();
     Mesh = COL.Model.Attach.CreateD3DMesh();
     Paste();
 }
예제 #8
0
 public static void Init(Device device)
 {
     QuestionBoxModel = new ModelFile(Resources.questionmark).Model;
     QuestionBoxMesh  = GetMeshes(QuestionBoxModel).First();
     QuestionMark     = Resources.questionmark_t.ToTexture(device);
 }
예제 #9
0
        public override List <RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            if (!camera.SphereInFrustum(Bounds))
            {
                return(EmptyRenderInfo);
            }

            List <RenderInfo> result = new List <RenderInfo>();

            transform.Push();
            transform.NJTranslate(Position);
            transform.NJRotateY(Rotation.Y);

            switch (CollisionType)
            {
            case (SADXCamColType.CamCol_Sphere):
                VolumeMesh = Mesh.Sphere(2f, 6, 8);
                Material   = new NJS_MATERIAL
                {
                    DiffuseColor   = Color.FromArgb(200, Color.Blue),
                    SpecularColor  = Color.Black,
                    UseAlpha       = true,
                    DoubleSided    = false,
                    Exponent       = 10,
                    IgnoreSpecular = false,
                    UseTexture     = false
                };
                transform.NJScale((Scale.X), (Scale.X), (Scale.X));
                break;

            case (SADXCamColType.CamCol_Plane):
                VolumeMesh = Mesh.Box(2f, 2f, 0f);
                Material   = new NJS_MATERIAL
                {
                    DiffuseColor   = Color.FromArgb(200, Color.Green),
                    SpecularColor  = Color.Black,
                    UseAlpha       = true,
                    DoubleSided    = false,
                    Exponent       = 10,
                    IgnoreSpecular = false,
                    UseTexture     = false
                };
                transform.NJScale((Scale.X), (Scale.Y), (1f));
                break;

            case (SADXCamColType.CamCol_Block):
                VolumeMesh = Mesh.Box(2f, 2f, 2f);
                Material   = new NJS_MATERIAL
                {
                    DiffuseColor   = Color.FromArgb(200, Color.Purple),
                    SpecularColor  = Color.Black,
                    UseAlpha       = true,
                    DoubleSided    = false,
                    Exponent       = 10,
                    IgnoreSpecular = false,
                    UseTexture     = false
                };
                transform.NJScale((Scale.X), (Scale.Y), (Scale.Z));
                break;

            default:
                VolumeMesh = Mesh.Sphere(2f, 6, 8);
                Material   = new NJS_MATERIAL
                {
                    DiffuseColor   = Color.FromArgb(200, Color.Blue),
                    SpecularColor  = Color.Black,
                    UseAlpha       = true,
                    DoubleSided    = false,
                    Exponent       = 10,
                    IgnoreSpecular = false,
                    UseTexture     = false
                };
                transform.NJScale((Scale.X), (Scale.X), (Scale.X));
                break;
            }

            RenderInfo outputInfo = new RenderInfo(VolumeMesh, 0, transform.Top, Material, null, FillMode.Solid, Bounds);

            if (Selected)
            {
                NJS_MATERIAL mat = new NJS_MATERIAL
                {
                    DiffuseColor   = Color.White,
                    IgnoreLighting = true,
                    UseAlpha       = false
                };
                result.Add(new RenderInfo(VolumeMesh, 0, transform.Top, mat, null, FillMode.Wireframe, Bounds));
            }

            result.Add(outputInfo);

            transform.Pop();
            return(result);
        }
예제 #10
0
        public void RebuildMesh(Device device)
        {
            List <FVF_PositionColored> vertList = new List <FVF_PositionColored>();
            List <short> faceIndexList          = new List <short>();

            Vector3 up = new Vector3(0, 1, 0);

            #region Segment vert/face creation
            short highestFaceIndex = 0;

            for (int i = 0; i < splineData.Path.Count - 1; i++)             // don't process the last knot
            {
                Vector3 thisKnot = new Vector3(splineData.Path[i].Position.X, splineData.Path[i].Position.Y, splineData.Path[i].Position.Z);
                Vector3 nextKnot = new Vector3(splineData.Path[i + 1].Position.X, splineData.Path[i + 1].Position.Y, splineData.Path[i + 1].Position.Z);

                Vector3 directionToNextKnot    = Vector3.Normalize(nextKnot - thisKnot);
                Vector3 perpendicularDirection = Vector3.Cross(directionToNextKnot, up);

                // verts for knot 1
                FVF_PositionColored vert1_1;                 // top vert 1 (0)
                FVF_PositionColored vert1_2;                 // top vert 2 (1)
                FVF_PositionColored vert1_3;                 // bottom vert 1 (2)
                FVF_PositionColored vert1_4;                 // bottom vert 2 (3)

                // verts for knot 2
                FVF_PositionColored vert2_1;                 // top vert 1 (4)
                FVF_PositionColored vert2_2;                 // top vert 2 (5)
                FVF_PositionColored vert2_3;                 // bottom vert 1 (6)
                FVF_PositionColored vert2_4;                 // bottom vert 2 (7)

                // move top verts
                vert1_1 = new FVF_PositionColored((thisKnot + (perpendicularDirection * splineMeshRadius)), Color.White);
                vert1_2 = new FVF_PositionColored((thisKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White);

                vert2_1 = new FVF_PositionColored((nextKnot + (perpendicularDirection * splineMeshRadius)), Color.White);
                vert2_2 = new FVF_PositionColored((nextKnot + (perpendicularDirection * (splineMeshRadius * -1))), Color.White);

                // move bottom verts
                vert1_3 = new FVF_PositionColored(vert1_1.Position - (up * splineMeshRadius), Color.White);
                vert1_4 = new FVF_PositionColored(vert1_2.Position - (up * splineMeshRadius), Color.White);

                vert2_3 = new FVF_PositionColored(vert2_1.Position - (up * splineMeshRadius), Color.White);
                vert2_4 = new FVF_PositionColored(vert2_2.Position - (up * splineMeshRadius), Color.White);

                List <short> thisKnotFaceIndexes = new List <short>
                {
                    // far side
                    4, 0, 6,
                    6, 2, 0,

                    // bottom
                    6, 2, 3,
                    3, 7, 6,

                    // our side
                    7, 3, 1,
                    7, 5, 1,

                    // top
                    1, 5, 4,
                    4, 0, 1
                };

                for (int faceIndx = 0; faceIndx < thisKnotFaceIndexes.Count(); faceIndx++)
                {
                    thisKnotFaceIndexes[faceIndx] += (short)vertList.Count();                     // this is the wrong approach because it's the verts we're indexing, not the faces!
                    if (thisKnotFaceIndexes[faceIndx] > highestFaceIndex)
                    {
                        highestFaceIndex = thisKnotFaceIndexes[faceIndx];
                    }
                }

                // add verts to vert list and faces to face list
                vertList.Add(vert1_1);
                vertList.Add(vert1_2);
                vertList.Add(vert1_3);
                vertList.Add(vert1_4);
                vertList.Add(vert2_1);
                vertList.Add(vert2_2);
                vertList.Add(vert2_3);
                vertList.Add(vert2_4);

                faceIndexList.AddRange(thisKnotFaceIndexes);
            }
            #endregion

            vertices    = vertList.ToArray();
            faceIndeces = faceIndexList.ToArray();

            // build bounding sphere
            bounds = SharpDX.BoundingSphere.FromPoints(vertices.Select(a => a.Position).ToArray()).ToSAModel();

            // build actual mesh from face index array and vbuf
            mesh = new Mesh <FVF_PositionColored>(vertices, new short[][] { faceIndeces });

            // create a vertexHandle
            if (vertexHandleMesh == null)
            {
                vertexHandleMesh = Mesh.Box(1, 1, 1);
            }

            textSprite = new Sprite(device);             // todo: do we really have to create this so often? Look into storing a cache list statically?
        }
예제 #11
0
        public static void InitGizmo(Device d3dDevice)
        {
            Attach attach = new ModelFile(Resources.x_null).Model.Attach;

            attach.ProcessVertexData();
            XNullMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.y_null).Model.Attach;
            attach.ProcessVertexData();
            YNullMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.z_null).Model.Attach;
            attach.ProcessVertexData();
            ZNullMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.x_move).Model.Attach;
            attach.ProcessVertexData();
            XMoveMesh = attach.CreateD3DMesh();
            XMaterial = ((BasicAttach)attach).Material[0];

            attach = new ModelFile(Resources.y_move).Model.Attach;
            attach.ProcessVertexData();
            YMoveMesh = attach.CreateD3DMesh();
            YMaterial = ((BasicAttach)attach).Material[0];

            attach = new ModelFile(Resources.z_move).Model.Attach;
            attach.ProcessVertexData();
            ZMoveMesh = attach.CreateD3DMesh();
            ZMaterial = ((BasicAttach)attach).Material[0];

            attach = new ModelFile(Resources.xy_move).Model.Attach;
            attach.ProcessVertexData();
            XYMoveMesh         = attach.CreateD3DMesh();
            DoubleAxisMaterial = ((BasicAttach)attach).Material[0];

            attach = new ModelFile(Resources.zx_move).Model.Attach;
            attach.ProcessVertexData();
            ZXMoveMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.zy_move).Model.Attach;
            attach.ProcessVertexData();
            ZYMoveMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.x_rotation).Model.Attach;
            attach.ProcessVertexData();
            XRotateMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.y_rotation).Model.Attach;
            attach.ProcessVertexData();
            YRotateMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.z_rotation).Model.Attach;
            attach.ProcessVertexData();
            ZRotateMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.x_scale).Model.Attach;
            attach.ProcessVertexData();
            XScaleMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.y_scale).Model.Attach;
            attach.ProcessVertexData();
            YScaleMesh = attach.CreateD3DMesh();

            attach = new ModelFile(Resources.z_scale).Model.Attach;
            attach.ProcessVertexData();
            ZScaleMesh = attach.CreateD3DMesh();

            BoxMesh = Mesh.Box(1, 1, 1);

            HighlightMaterial = new NJS_MATERIAL()
            {
                DiffuseColor = Color.LightGoldenrodYellow, Exponent = 0f, UseTexture = false, IgnoreLighting = true, IgnoreSpecular = true
            };

            ATexture         = Resources.PointATexture.ToTexture(d3dDevice);
            BTexture         = Resources.PointBTexture.ToTexture(d3dDevice);
            StandardMaterial = new NJS_MATERIAL()
            {
                DiffuseColor = Color.Gray, IgnoreLighting = true, IgnoreSpecular = true, UseAlpha = false, UseTexture = true, Exponent = 100f
            };
        }
예제 #12
0
 // Form property update event method
 void pw_FormUpdated(object sender, EventArgs e)
 {
     COL.Model.ProcessVertexData();
     mesh = COL.Model.Attach.CreateD3DMesh();
     LevelData.InvalidateRenderState();
 }
예제 #13
0
 public void RegenerateMesh() => mesh = COL.Model.Attach.CreateD3DMesh();