I asked a similair question earilier, but it was not generic enough, so here's another attempt.
I currently have a whole bunch of 3d .obj and .jpg files which I want to display in my WPF application. However, I want to do this at runtime, so converting them using Blend is not an option.
I don't mind having to convert to other types of 3d files, as long as this can be done at runtime (either programmaticly or by using a command line tool).
So I guess my question is: Is there any way to import a 3d file in WPF at runtime?
Thanks!
I don't think there's a built in way. You'll most likely have to write an importer for your own specific needs. You can find some file format information here> http://en.wikipedia.org/wiki/Wavefront_.obj_file
Thanks to #MattDavey
I managed to get The HelixToolkit (http://helixtoolkit.codeplex.com/) to work and got what I wanted using the ModelImporter.Load method.
Related
I'm looking to add ebook support (.pdf .txt .epub .mobi .rtf Support) to a game I'm making in Unity using C#. Thing is I really do not know where to start when it comes to this and most of my google searches have gotten me nothing but Ebooks about programming or game development. So I'm hoping someone here would have a good idea where I could start and/or information that would help set me in the right direction.
So just to summarize my comments on the OP:
With the least amount of work, embedding a web browser control like Webkit is probably the best option. It should properly read all the common filetypes you mentioned, save for .epub and .mobi. A separate library or control will need to be obtained or coded for those to work. Additionally, if the user already has a default program set up to open those filetypes, you can open them outside of the game with Process.Start(...) which is part of the System.Diagnostics namespace.
If it comes down to you having to code this yourself, a PDF is just drawn graphics on a canvas, txt is just raw text data, and an rtf is text data with some markup to get the formatting right. Coding a component that opens those for you should not be abnormally difficult.
I have a Photoshop Document with a few layers that I can turn on and off to make the image display different data. Is it possible to place this image in a WPF page and use C# to turn on and off layers? I've been googling for a little while but there doesn't seem to be much information on this subject. I read that you might be able to use Expression Blend to do this, however I do not have any experience using it.
Any help would be greatly appreciated, thanks!
(Disclaimer: I'm a software engineer at Microsoft, I used to work on Expression Blend)
In short, no. There is no built-in support for loading Photoshop files in the .NET Framework nor WPF (this is despite Blend's support for loading PSD documents into a project - it has its own code for this - and it doesn't support all of the features present in the PSD file format either).
If you want to load a PSD file into your own program you'll need a PSD file reader - either write your own (a fool's errand considering how complicated the file format is) or obtain/license an existing library, there are open-source implementations available (see Paint.NET's).
A problem with PSD files is that individual layers are not necessarily simple rasters by themselves, and PSD documents don't always contain a full-resolution composite either. Consider effects-layers (Brightness, Levels, etc) or layer-effects (Outer Glow, Gradient Overlay, etc).
I suggest instead having Photoshop (via an Action or a Droplet program) convert your PSD's layers to individual PNG files (after applying any effects) and then loading those into your program and displaying them according to your requirements.
I'm working on an application that uses the XNA framework to do it's 3D rendering. I now want to load a texture from file. I've found two methods so far:
Texture2D.FromStream(GraphicsDevice, Stream) The problem with this approach is that it only loads gif, png and jpg and I also need support for tga images.
Create a ContentManager object. The problem with this approach is that it seems like all the textures need to be statically added to the project, from the documentation: "Before a ContentManager can load an asset, you need to add the asset to your game project". The program in question is a level editor and which textures are needed isn't known in advance.
Is there any other easy way to load the texture, I'm thinking about using some other class to load the image (although I don't know which, I'm not very familiar with C#) and then perhaps use the Texture2D.SetData method?
Is there any other easy way to achieve what I'm trying to achieve?
There are a few ways to achieve what you want:
You could invoke the content pipeline from within your editor, dynamically creating your content project. How to do this is described in the WinForms Series 2 Sample. This is probably the "best" way, because it allows you to keep using the content pipeline.
You could, as you say, decode the TGA file yourself and use SetData. There are lots of results for C# TGA readers on Google. This is the first one.
I've used Texture2D.FromFile(device, path) before, and it works well. However occasionally I'll encounter problems and will also have to specify TextureCreationParameters and pass them in. Keep in mind that you'll need to dispose the loaded Texture2D manually.
Is there a .net library to do this?
There is an example here I think. Its part of the mkNETtools.
Downlods should be explained here: http://corp.koders.com/downloads
I recently posted NEbml library sources somewhere on the Net. Google this name. It contains the sample for editing attributes and I'm going to add another sample for reading whole file data.
Do you control the machine (i.e. can you install the Matroska codec on it?) If so, the easiest way might be to load the movie in WPF's video control or another playback framework on Windows and query the length, rather than hardcoding something via the raw container format. More dependencies, but likely useful if you want to go further, like generating thumbnails.
I am planning on building a 2D game library for XNA, and one of the components I want to include is a simple text drawer for debug purposes. Now, to draw text with SpriteBatch you need a .spritefont file, which is an xml format file, and these seem to need to compile into a separate folder. I would prefer not to have to copy that around with the dll, so here is my question:
can i build some sort of text renderer for XNA that
A: does not require me to carry around external files with the dll (if you can embed the sprite font into a dll then that works) and
B: does not force me to rewrite a fair amount of underlying (is it managed directx? a different part of xna?) code that makes the SpriteBatch.DrawString code work.
Could you not just require that a SpriteFont be passed into your library, so that whoever is using the library has to supply that component? That would seem to be the best solution, since then they could use whatever font they wanted. Or you could write in a component that generates the spritefont xml file based on a given font name, because it's not all that complicated of a file. Disregard. I forgot that XNA compiles its resources.
You can precompile the project and then grab the xnb file for the spritefont. Then add the file to the project Content folder as a content file. It should then be deployed together with the library. However u will need to build a separate xnb file for each platform you wish to support (xbox360, windows, zune) and deploy the correct file.
Or why don't u just create a XNA Content Library project?