public static void Init(Device device, Bitmap unknownBitmap) { SquareMesh = new Mesh <FVF_PositionTextured>(SquareVerts, new short[][] { SquareInds }); SquareBounds = SharpDX.BoundingSphere.FromPoints(SquareVerts.Select(a => a.Position).ToArray()).ToSAModel(); QuestionMark = unknownBitmap != null?unknownBitmap.ToTexture(device) : new Texture(device, 16, 16, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); }
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(); }
public void ImportModel(string filePath) { COL.Model.Attach = Direct3D.Extensions.obj2nj(filePath, LevelData.TextureBitmaps[LevelData.leveltexs].Select(a => a.Name).ToArray()); Visible = true; Solid = true; mesh = COL.Model.Attach.CreateD3DMesh(); }
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 }; }
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 }; }
public static void Init(Device device) { QuestionBoxModel = new ModelFile(Resources.questionmark).Model; QuestionBoxMesh = ObjectHelper.GetMeshes(QuestionBoxModel).First(); SquareMesh = new Mesh <FVF_PositionTextured>(SquareVerts, new short[][] { SquareInds }); SquareBounds = SharpDX.BoundingSphere.FromPoints(SquareVerts.Select(a => a.Position).ToArray()).ToSAModel(); QuestionMark = Resources.questionmark_t.ToTexture(device); }
/// <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(); }
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); }
private void MainForm_Load(object sender, EventArgs e) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); Direct3D d3d = new Direct3D(); d3ddevice = new Device(d3d, 0, DeviceType.Hardware, panel1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters { Windowed = true, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D24X8 }); EditorOptions.Initialize(d3ddevice); EditorOptions.OverrideLighting = true; EditorOptions.RenderDrawDistance = 10000; optionsEditor = new EditorOptionsEditor(cam); optionsEditor.FormUpdated += optionsEditor_FormUpdated; optionsEditor.CustomizeKeybindsCommand += CustomizeControls; optionsEditor.ResetDefaultKeybindsCommand += () => { actionList.ActionKeyMappings.Clear(); foreach (ActionKeyMapping keymapping in DefaultActionList.DefaultActionMapping) { actionList.ActionKeyMappings.Add(keymapping); } actionInputCollector.SetActions(actionList.ActionKeyMappings.ToArray()); }; actionList = ActionMappingList.Load(Path.Combine(Application.StartupPath, "keybinds.ini"), DefaultActionList.DefaultActionMapping); actionInputCollector = new ActionInputCollector(); actionInputCollector.SetActions(actionList.ActionKeyMappings.ToArray()); actionInputCollector.OnActionStart += ActionInputCollector_OnActionStart; actionInputCollector.OnActionRelease += ActionInputCollector_OnActionRelease; cammodel = new ModelFile(Properties.Resources.camera).Model; cammodel.Attach.ProcessVertexData(); cammesh = cammodel.Attach.CreateD3DMesh(); if (Program.Arguments.Length > 0) { LoadFile(Program.Arguments[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(); }
private void MainForm_Load(object sender, EventArgs e) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); Direct3D d3d = new Direct3D(); d3ddevice = new Device(d3d, 0, DeviceType.Hardware, panel1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters { Windowed = true, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D24X8 }); settingsfile = SettingsFile.Load(); EditorOptions.Initialize(d3ddevice); EditorOptions.OverrideLighting = true; EditorOptions.RenderDrawDistance = cam.DrawDistance = settingsfile.SA2EventViewer.DrawDistance_General; cam.ModifierKey = settingsfile.SA2EventViewer.CameraModifier; actionList = ActionMappingList.Load(Path.Combine(Application.StartupPath, "keybinds", "SA2EventViewer.ini"), DefaultActionList.DefaultActionMapping); actionInputCollector = new ActionInputCollector(); actionInputCollector.SetActions(actionList.ActionKeyMappings.ToArray()); actionInputCollector.OnActionStart += ActionInputCollector_OnActionStart; actionInputCollector.OnActionRelease += ActionInputCollector_OnActionRelease; optionsEditor = new EditorOptionsEditor(cam, actionList.ActionKeyMappings.ToArray(), DefaultActionList.DefaultActionMapping, false, false); optionsEditor.FormUpdated += optionsEditor_FormUpdated; optionsEditor.FormUpdatedKeys += optionsEditor_FormUpdatedKeys; cammodel = new ModelFile(Properties.Resources.camera).Model; cammodel.Attach.ProcessVertexData(); cammesh = cammodel.Attach.CreateD3DMesh(); if (Program.Arguments.Length > 0) { LoadFile(Program.Arguments[0]); } }
public static void Init() { 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 }; pointHelperA = new PointHelper { BoxTexture = Gizmo.ATexture, DrawCube = true }; pointHelperB = new PointHelper { BoxTexture = Gizmo.BTexture, DrawCube = true }; }
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? }
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); }
private void LoadFile(string filename) { loaded = false; Environment.CurrentDirectory = Path.GetDirectoryName(filename); timer1.Stop(); scenenum = 0; animframe = -1; @event = new Event(filename); meshes = new List <List <Mesh[]> >(); bigmeshes = new List <Mesh[]>(); foreach (EventScene scene in @event.Scenes) { List <Mesh[]> scenemeshes = new List <Mesh[]>(); foreach (EventEntity entity in scene.Entities) { if (entity.Model != null) { if (entity.Model.HasWeight) { scenemeshes.Add(entity.Model.ProcessWeightedModel().ToArray()); } else { entity.Model.ProcessVertexData(); NJS_OBJECT[] models = entity.Model.GetObjects(); Mesh[] entmesh = new Mesh[models.Length]; for (int i = 0; i < models.Length; i++) { if (models[i].Attach != null) { try { entmesh[i] = models[i].Attach.CreateD3DMesh(); } catch { } } } scenemeshes.Add(entmesh); } } else if (entity.GCModel != null) { entity.GCModel.ProcessVertexData(); NJS_OBJECT[] models = entity.GCModel.GetObjects(); Mesh[] entmesh = new Mesh[models.Length]; for (int i = 0; i < models.Length; i++) { if (models[i].Attach != null) { try { entmesh[i] = models[i].Attach.CreateD3DMesh(); } catch { } } } scenemeshes.Add(entmesh); } else { scenemeshes.Add(null); } } meshes.Add(scenemeshes); if (scene.Big?.Model != null) { if (scene.Big.Model.HasWeight) { bigmeshes.Add(scene.Big.Model.ProcessWeightedModel().ToArray()); } else { scene.Big.Model.ProcessVertexData(); NJS_OBJECT[] models = scene.Big.Model.GetObjects(); Mesh[] entmesh = new Mesh[models.Length]; for (int i = 0; i < models.Length; i++) { if (models[i].Attach != null) { try { entmesh[i] = models[i].Attach.CreateD3DMesh(); } catch { } } } bigmeshes.Add(entmesh); } } else { bigmeshes.Add(null); } } TexturePackName = Path.GetFileNameWithoutExtension(filename) + "texture.prs"; TextureInfo = TextureArchive.GetTextures(TexturePackName); Textures = new Texture[TextureInfo.Length]; for (int j = 0; j < TextureInfo.Length; j++) { Textures[j] = TextureInfo[j].Image.ToTexture(d3ddevice); } loaded = true; selectedObject = null; SelectedItemChanged(); currentFileName = filename; }
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 }; }
public void RegenerateMesh() => mesh = COL.Model.Attach.CreateD3DMesh();