Load Curve from file instead using Content Manager - xna

I'm looking to load a Curve file in XNA but not through the content manager process e.g. Load("").
Is there any way to do this?
For example:
Curve curve = new Curve("filename"); or
Curve curve = Curve.FromFile("filename"); // similar to loading texture2d and song.

Creating curve data in xml form and building/importing it using the content processor will work (and the easiest way to go) for PC, win7phone, & xb360. If you are planning more platforms than that, then yes, you would have to write your own.

Related

Correct way to import and create many large sprites: SpriteKit

Despite reading through much of Apple's docs and reading through their forums and watching their WWDC videos, I seem to have missed the steps required to utilise the texture packing and performance of Sprite Kit for making many large-ish Sprites.
Imagine 100 different sprite images, for 100 different sprites. If each image is 256x256 pixels, they're going to take up more than one SpriteSheet at 2048x2048. And let's imagine that's the limit, rather than 4096x4096, just so it's understood that more than one spritesheet is going to be required.
There might be as many as 20 different sprites on screen at any given time. So performance is a consideration.
How to import these images and then create these sprites in the manner SpriteKit intends for its texture packing and performance considerations of in game use?
Just a specific link to Apple recommended absolute steps will be fine. I must have just skimmed right over it.
Apple's new docs go this far:
Which completely fails to convey:
Import folder, or images?
Import to WHERE within the project?
Load and reference them, how?
So let me see if I can reasonably answer your question. Please keep in mind that while I have used SpriteKit, I'm not a big fan of it. And when I did use it, I did not use any of the tools Apple provided (eg. SKTextureAtlas, sks files, etc). Nevertheless, this should still be applicable. Best practices as per Apple? I have no idea.
Question: Import folder, or images?
If you use Xcode's means of generating atlases, you Add Files... to your project a folder named XYZ.atlas, where XYZ will be the texture name. This folder contains all of your textures which will be in the atlas.
Question: Import to WHERE within the project?
Just has to be in your project. But you should have some organization Group hierarchy in your project file.
Question: Load and reference them, how?
An example of loading would be something like (yeah, I know boo, Obj-C):
self.myTextureAtlas = [SKTextureAtlas atlasNamed:#"MyTexture"];
Inevitably, you will want access to the actual textures and you'll need to do something like:
self.tex0 = [self.myTextureAtlas textureNamed:#"tex0"];
A good tutorial is here: https://www.raywenderlich.com/45152/sprite-kit-tutorial-animations-and-texture-atlases
Here is also a screenshot that shows the .atlas folder. It also shows a couple of tool generated atlas files.
So here you can see I have 2 Groups which are references to folder MyTexture.atlas and ProgressBar.atlas. In game, they will be called MyTexture and ProgressBar.
I have also included, just as an example the same atlases, but pre-built. You would not have both in your project, I only used it to show what including a pre-built would loo like. I generated them using TexturePacker. I'll get into why this may be a better option later on. TexturePacker also can create SpriteKit atlases instead of the atlas PNG.
In reality, an atlas is really just a texture with sub-textures are associated with it. The sub-textures are X/Y/W/H sections of the texture. The actual memory for the texture is "held" by the atlas. Understanding what an atlas is is a useful thing, because it allows you to think through how you would support it if you had to implement it yourself. Or enhance it.
Now let's go over how you would use this altogether to do something useful.And for this you're going to need a texture manager (aka TextureManager), sprite manager (aka SpriteManager) and a manifest of some sort.
The manifest is really some form of association between "sprite name" to atlas:sub texture pair. For example:
{
"progressbar": {
"atlas": "ProgressBar",
"subtexture": progressbarbacking"
},
"progressbarfillr": {
"atlas": "ProgressBar",
"subtexture": progressbarfillr"
}
}
In this case it is some JSON, but you can have whatever format you want. When I build my games, I have a build assets phase which generates all my textures and from that, builds a manifest. This manifest tells me not only what textures exist, but is used later on to find the correct association of a "sprite name" to the actual atlas and sub texture. "sprite name" is just some name you have associated meaning. It could be "zombie" for example.
You use a TextureManager as your asynchronous loader. In addition, it is your inventory manager of all your textures. As an inventory manager, it will prevent you from double loading textures and also give you the correct reference to textures/atlases when requested (if they exist).
You would use the SpriteManager to create a new SKSpriteNode using the data from the manifest. For example:
SKSpriteNode *progressBar = [[SpriteManager sharedInstance] createSprite:#"progressbar"];
Here I've made it a singleton. Use whatever implementation you want. If you hate singletons, that is fine, this is just an example. You'll note that it returns a SKSpriteNode. I see a lot of people making subclasses from SKSpriteNodes. I never do this. To me, the graphic component is always a "has a". However, if you are doing an "is a", you can still do this. You just need to feed in the class you need. I'm considering the way of handling that out of scope for this question.
Now if you look at the manifest, you'll notice that progressbar is associated with an atlas named ProgressBar and a sub texture named progressbarbacking. To get the texture you need, you'd have some implementation code in SpriteManager like:
// NOTE the literal names would be variables which contained the unpacked association from progressbar
// literal strings are used to make the idea easier to follow
SKTextureAtlas *atlas = [[TextureMaanger sharedInstance] findAtlasNamed:#"ProgressBar"];
//Error check of course
SKTexture *tex = [atlas textureNamed:#"progressbarbacking"];
// Error check of course
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:tex];
Or perhaps you would just have a call:
SKTexture *tex = [[TextureManager] sharedInstance] texNamed:#"progressbarbacking" atlas:#"ProgressBar"];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:tex];
And there you have it. A means to get sprites from atlases.
Best practices as per Apple? Dunno, but it is along the lines of what I do.
Some people will complain that there will be dictionaries involved and some of this will be "slow". And yes, there is a penalty for this. And reality, I don't use a dictionary for this either, but it is easier to get the idea across as the dictionary. Also keep in mind that I consider the usage of this to occur during loading phases and very little during game play, if at all. One of the tricks to performant games is pre-loading all or as much of the data you need prior to actual game play.
Oh, going to why I pre-build the atlases. So part of your question was organization of textures to atlas. And that is why. I like to see the generated atlas and understand what the size is and what is in it. Additionally it makes downloadable atlases easier.
As an optimization, you would want to try and put textures in which are all drawn relatively the same time. For example, it would make sense to have all HUD items in the same atlas versus mixing HUD with background.

How to save a geometry and its material created in Three.js as collada file?

I'm relatively new to programming and currently trying to learn more about three.js, a JavaScript 3D library. Many things are relatively easy to understand, but I an having a hard time saving an geometry and its material.
I have build a simple cube and an image is projected on to it whenever a picture is loaded.
like this:
$('#picture')[0].onload = function() {
var texture = new THREE.Texture(this,null);
texture.needsUpdate = true;
cube.material = new THREE.MeshBasicMaterial( { map: texture } );
render();
}
My goal is to save the cube and its material. Ideally I would like to save it directly as a .dae file since another program in which i would like to import my cube only takes .dae files.
However, i can not find a collada exporter for THREE.js. Therefore, I searched for other exporters which can produce a file format I can open in e.g. Blender or MeshLab and save as .dae from there. Unfortunately, I have not been able to save both geometry and material/picture with these exporters:
GeometryExporter.js, OBJExporter.js, SceneExporter.js
I also looked into the combination of OBJ and MTL. I did find the OBJMTLLoader.js, however I lack the knowledge to rewrite the OBJMTLLoader.js in to a OBJMTLExporter.js
Can anyone help me find a way to get from a cube and its (picture) material in THREE.js to a .dae file?
For a very simple use case such as this, you could write the DAE manually, or even simpler, modify existing DAE on the fly. It's just XML if you change the file extension.
Create the simple cube with material in Blender, export it to DAE, and use it as a template. Simple DAE files are not very hard to read with text editor, you could find the relevant parts and just search & replace those parts in javascript (texture reference, material properties and UVs maybe).
This might not be exactly what you are looking for, but could work. Not many formats have proper support for materials, and I doubt you have much success finding a working, fully featured Three.js exporter for such a thing (not sure though).

How to make a change in Qualcomm's Vuforia Sample App

I have been looking through the threads at the Qualcomm Forums but no luck since I don't know exactly how to look for what I want.
I'm working with the ImageTargets Sample for iOS and I want to change the teapot to another image (a text rather) I had.
I already have the render and I got the .h using opengl library but I can't figure out what do I need to change to make this work and since this is the very basic and I haven't been able to make it work I really haven't ventured to try anything else.
Could anyone please help me out?
I would paste code here but it's a whole project so I don't know exactly what to put if needed please let me know.
If the case is still valid, here's what you have to do:
get header file for 3D object
get texture image for this object
in EAGLView.mm make this changes:
import "yourobject3d.h"
add your texture to textureFilenames array(this should be at the begining of EAGLView
eventually take care about kObjectScale (by deafult it was about 3.0f, for one object I did have to change it even up to 120.0f)
in setup3dObjects method assign proper arrays of vertices/normals/texture coords (check in "yourobject3d.h" file for proper arrays and naming) to Object3D *object
make this change in renderFrameQCAR
//glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
I believe that is all... if something take a look at Vuforia's forum, i.e. here: https://developer.vuforia.com/node/2047669
NOTE: default teapot.h does (!) have indices, which are not present in banana.h (from comment below) so take care about that too
Have a look at the EAGLView.mm file. There you'll have to load the textures (images) and 3d objects (you'll need to import your .h instead of teapot.h and modify setup3dObjects accordingly).
They are finally rendered by calling the renderFrameQCAR function.
Actually, teapot is not an image. It's a 3D model stored in .h format which includes Vertices, Normals, and Texture coordinates. You should have a good knowledge of OpenGL ES to understand those codes in sample app.
An easier way to change the 3D model to whatever you want is to use a rendering engine which facilitates the drawing and rendering stuffs and you don't need to bother OpenGL APIs. I've done it with jPCT-AE for Android platform but for iOS there is a counterpart called OpenFrameworks engine. It has some plugins to load 3Ds or MD2 files and since it's written in C++ you can easily integrate it with QCAR.
This is a short video of my result with jPCT and QCAR:
Qualcomm Vuforia + jPCT-AE test video

Using 3D Studio Max DirectX shader in XNA problem

UPDATE 2: It now appears this is more of a modelling issue than a programming one. Whoops.
I'm new to XNA development, and despite my C# experience, I've been stuck at one spot for going on two days now.
The situation: I've created a model in 3D Studio Max 2010 which uses two materials, both are of type DirectX Shader. The model exports to FBX without error and Visual Studio compiles it properly. When I ran the Draw() method initially, it threw an exception on the 'BasicEffect' portion of one of my loops, demonstrating (at least to me) that it was loading the .fx file correctly, which must be embedded in the FBX file or something.
The problem:
When using the following code
foreach (ModelMesh mesh in map.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
effect.CurrentTechnique = effect.Techniques["DefaultTechnique"];
effect.Begin();
effect.Parameters["World"].SetValue(Matrix.CreateTranslation(Vector3.Zero));
effect.Parameters["View"].SetValue(ActiveCamera.ViewMatrix);
effect.Parameters["Projection"].SetValue(ActiveCamera.ProjectionMatrix);
effect.Parameters["WorldViewProj"].SetValue(Matrix.Identity * ActiveCamera.ProjectionMatrix);
effect.Parameters["WorldView"].SetValue(Matrix.Identity * ActiveCamera.ViewMatrix);
foreach (EffectPass ep in effect.CurrentTechnique.Passes)
{
ep.Begin();
// something goes here?
ep.End();
}
effect.End();
}
mesh.Draw();
}
The only thing that happens is a white box appears covering the bottom half of the screen, regardless of camera position or angle. I got the name of the effect parameters of the default.fx file specified in Max (it's at [program files]\autodesk\3ds Max 2010\maps\fx).
I get the feeling I'm setting one or all of these incorrectly. I've tried to look up tutorials and follow their code, however none of it seems to work for my model.
Any help or ideas?
UPDATE:
By making these changes:
effect.Parameters["WorldViewProj"].SetValue(Matrix.CreateTranslation(Vector3.Zero) * ActiveCamera.ViewMatrix * Conductor.ActiveCamera.ProjectionMatrix);
effect.Parameters["WorldView"].SetValue(Matrix.CreateTranslation(Vector3.Zero) * ActiveCamera.ViewMatrix);
The model was able to draw. However, everything is completely white :(
Unfortunately, especially without seeing your shader and/or knowing what error it is that you're getting, it's going to be pretty difficult to figure out what's wrong here. There are a number of things that could be going wrong.
My suggestion is to start with a simpler test. Make a box, apply a very simple shader ... and make that render. Then, add some parameter that (for example) multiplies the red component of the pixel shader by the amount passed in. And make that render successfully.
By simplifying the problem set, you are figuring out the nuances of the shaders that max exports and how you set the properties. At some point, you'll realize what you're doing wrong and will be able to apply that to your more complex shader.
I'm quite interested in hearing how this goes ... make sure you comment on this once you've fixed it so I see the outcome. Good luck! :-)

XNA File Load

In XNA, how do I load in a texture or mesh from a file without using the content pipeline?
The .FromFile method will not work on xbox or zune. You have two choices:
Just use the content pipeline ... on xbox or zune (if you care about them), you can't have user-supplied content anyways, so it doesn't matter if you only use the content pipeline.
Write code to load the texture (using .SetData), or of course to parse the model file and load the appropriate vertexbuffers, etc.
For anyone interested in loading a model from a file check out this tutorial:
http://creators.xna.com/en-us/sample/winforms_series2
This is a windows only Way to load a texture without loading it through the pipeline, As Cory stated above, all content must be compiled before loading it on the Xbox, and Zune.
Texture2D texture = Texture2D.FromFile(GraphicsDeviceManager.GraphicsDevice, #Location of your Texture Here.png);
I believe Texture2D.FromFile(); is what you are looking for.
It does not look like you can do this with a Model though.
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d.fromfile.aspx
If you really want to load an Xna Xna.Framework.Graphics.Model on PC without the content pipeline (eg for user generated content), there is a way. I used SlimDX to load an X file, and avoid the parsing code, the some reflection tricks to instantiate the Model (it is sealed and has a private constructor so wasn't meant to be extended or customised). See here: http://contenttracker.codeplex.com/SourceControl/changeset/view/20704#346981

Resources