Since I've ran out of models during making game in XNA i tried to make my own. But there is a problem - when I making .fbx model, adding texture via blender, doing uv mapping and then applying this model to my XNA project, everything works fine but the texture not displaying. Only thing that I see is the gray model. What can I do to fix that?
Textures are not saved along with the model file. You have to separately load the texture:
var texture = Content.Load<Texture>("TextureName");
When the texture is loaded you can bind it to the effect:
basicEffect.TextureEnabled = true;
basicEffect.Texture = texture;
Related
I know that I can add sequences of individual images in Xcode, and let it create the Texture Atlas. This process is well-described in easily-searched venues. (Like this one.)
I am getting atlases from designers, created with Adobe Animate (v18.0) already combined into the full sheet, and moreover with the accompanying XML file describing the animation. (In which sub-images and display frames do not match 1:1, so it's hard to see how Xcode would figure that out.)
It's not clear to me from the SpriteKit docs whether/how to use these pre-defined Texture Atlases. Is this possible?
If you're getting pre-baked texture atlases, with externally-generated descriptions of where the sprites should get their textures, you'll probably have to create your sprites using SKTextures that you create using the init(rect:in:) initializer of a SKTexture.
You'll need to read the sprite's extents out of the XML file, and then create a texture out of the atlas. Then you can create a new SKTexture object that represents a part of the larger texture to act as your sprite's texture.
This is untested pseudocode, but it shows the process:
let spriteRect = (get the rect from the XML)
let atlas = SKTexture( imageNamed: "myTextureAtlas" )
let spriteTexture = SKTexture( rect:spriteRect, in:atlas )
let sprite = SKSpriteNode( texture:spriteTexture )
Once you have this process in place, you can animate the sprites using the usual methods, like setting up SKActions with a list of textures out of the texture atlas.
I'm trying to learn SceneKit development and try to add a skybox in the background.
To store the cube map textures I found that XCAssets has a type Cube Texture Set which seems to fit the bill perfectly.
However. I've not found any way to access the texture in code (e.g. as an image set where you call UIImage(named: "asset_name") ). I've tried creating an SKTexture, MDLTexture og MTKTexture from the asset but without success. Do anyone know how I can use the cube texture set?
You can load the cube texture from the asset catalog easily using MetalKit.
import MetalKit
at the top of your file. These two lines do the business:
let textureLoader = MTKTextureLoader(device: scnView.device!)
scene.background.contents = try! textureLoader.newTexture(name: textureName,
scaleFactor: 1.0,
bundle: .main, options: nil)
I tried this in a project created from the default SceneKit game template, and placed these two lines in GameViewController.swift after setting the view's background color
(I expect you can do it using the other technologies too, but this is how you can load a cube texture using Metal)
I am using SceneKit to show a 3D model on iOS. I would like to use PBR. At the moment I am using the scene editor not coding to edit my materials. I can set any field to PNGs at the models material (metalness, normals, etc..) except the roughness. When I set it, the whole model turns pink. If I use float value, there is no problem. Do you have any idea, what the problem could be?
I'm using XNA 3.1
I have recently created a 2D Heads Up Display (HUD) by using Components.Add(myComponent) to my game. The HUD looks fine, showing a 2D map, crosshairs and framerate counter. The thing is, whenever the HUD is on screen the 3D objects in the game no longer draw correctly.
Something further from my player might get drawn after something closer, the models sometimes lose definition when I walk past them. When I remove the HUD all is drawn normally.
Are their any known issues regarding this that I should be aware of? How should I draw a 2D HUD over my 3D game area?
This is what it looks like without a GameComponent:
And here's how it looks with a GameComponent (in this case it's just some text offscreen in the upper left corner that shows framerate), notice how the tree in the back is appearing in front of the tree closer to the camera:
You have to enable the depth buffer:
// XNA 3.1
GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
// XNA 4.0
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
SpriteBatch.Begin alters the state of the graphics pipeline:
SpriteBatch render states for XNA 3.1
SpriteBatch render states for XNA 4.0
In both versions depth buffering is disabled, that's what causes the issue.
Again, I cannot stress this enough:
Always make sure that ALL render states are correctly set before drawing any geometry.
BlendState
DepthStencilState
RasterizerState
Viewports
RenderTargets
Shaders
SamplerStates
Textures
Constants
Educate yourself on the purpose of each state and each stage in the rendering pipeline. If in doubt, try resetting everything to default.
Is it possible to add a textured material to an object with a custom mesh in Three.js?
Whenever I try exporting an object from Blender to Three.js with a texture on it, the object disappears. Looking through the three.js examples, it seems like they've carefully avoided putting textures on anything other than the built-in geometries, and forcing a texture on such a mesh causes it to again disappear.
For example, if I edit scene_test.js, which is a scene file called from webgl_scene_test.html, if I apply the "textured_bg" to the "walt" head, it will disappear.
It looks like the missing piece of the puzzle was that you have to apply the set of UV coordinates to the mesh of the object in question.
First, select your texture, and under "Mapping" make sure that the "coordinates" dropdown is set to "UV"
Then, click on the "object data" button, and in the UV Texture list, click the plus icon. This seems to automatically add the UV data to the mesh.