Loading material parameteres from FBX in XNA - c#

I've got some material parameters stored in the FBX file (DiffuseFactor, ShininessExponent, SpecularFactor and others), but I can't get to them using Effect.Parameters nor BasicEffect (they've got only the basic stuff - like EmmisiveColor or alpha). I know, that I can try to write a Effect-derived class, but is there any other way? A built-in feature or maybe some half-raw parameters stored somewhere?

If you create a custom model processor (for the content pipeline) and override the ConvertMaterial method you can access this type of data in the input MaterialContent.OpaqueData collection.
I know if you output an EffectMaterialContent from this method like they do in the Skinned Model sample, you can attach this data to the EffectMaterialContent's OpaqueData collection and it will be visible in the shader using the names you supply. This was as of XNA 3.1 anyway, I'm not sure if there's a better/alternate way to do this now.
EDIT: Wow, didn't realize this question was almost a year old.

Related

BRISQUE Implementation for OpenCvSharp

I used BRISQUE in Matlab before and it worked fine so I decided to use it again in C#.
However, BRISQUE in OpenCvSharp (the same goes for Python and C++ as well) requires a SVM model data and range data saves - as seen in the documentation.
public static QualityBRISQUE Create(string modelFilePath, string rangeFilePath)
public static QualityBRISQUE Create(SVM model, Mat range)
According to MATLAB's documentation; < brisque compare A to a default model computed from images of natural scenes with similar distortions >. Do such save files exist in openCV or must I make them manually?
I found them, on the opencv_contrib GitHub page.
You can find both YML files (the model and the range files) here.

How to enable loopTime for animation clips (FBX and others) in Unity 2017.1

I have a FBX model with animation clips as subassets (embeded in it), I want to enable looping for all clips in it. I found that AnimationUtility's GetClipSettings method is obsolete now and also tried using it but it didn't work. This is probably because Unity has changed their API for looping and it seems that the only way to access loopTime property is by manually accessing the subassets of fbx model and checking the loopTime property. However, I have to automate this process since I'm generating dynamic animation controllers for my models before building assetbundles. The pipeline includes post/pre-processing and then building assetbundles through editor scripts. So far, I have come across this post using which I was able to enable loopTime just by setting ModelImporterClipAnimation.loopTime = true for every clip and it works. However, now the model seems to look completely pink as it loses reference to its materials for whatever reason, this happens only when I include the AssetPostprocessing script.
How should this be dealt with?
Why is the model losing materials if the OnPreprocessAnimation of AssetPostprocessor is included? Am I missing something?
Should I also handle Material references by some other method, if I mess with the AssetPostprocessor?
Can we access loopTime by some other way? It is not specified in the docs, though.
My code is exactly the same as the referenced post above other than the slight change to enable loopTime. Or is there a better way to do all this?
P.S. I'm posting this question after a day full of searching and experimenting, apologies in advance if the question is not clear enough. I can add more info if needed.
I think that you have to handle the material yourself. You can set ModelImporter.importMaterials to false to create a default diffuse material when importing the model.
If material already exist, you can also search for existing material and load it when importing the model:
ModelImporter modelImporter = (ModelImporter)assetImporter;
modelImporter.materialName = ModelImporterMaterialName.BasedOnMaterialName;
modelImporter.materialSearch = ModelImporterMaterialSearch.Local;
See ModelImporterMaterialName and ModelImporterMaterialSearch docs for other options you have.

How to Create Model from Scratch

I am working to generate terrain for our project, something that will be contained in the Model class that I can draw, but I new class would be alright since I may need to look inside for specific data often, and then I would just need the basic function to work with the Game class.
Anyway, I have a fair amount of knowledge of the XNA framework, but because of how convoluted it handles anything. So my problem is I can't just make a Model, I can't instantiate that class or anything. I have what I believe the proper data to form a model's geometry, which is all I need right now, and later possibly have it textured.
I don't know where to go from here.
XNA you usually use Content.Load, to have their content pipeline read in a file and parse it specifically, but I want to avoid that because I want my terrain generated. I can compute an array of Vertex data and indices for the triangles I want to make-up a mesh, but so far my efforts have tried to instantiate any object like Model or those it contains, have failed.
If there is some factory class I can use to build it, I have no idea what that is, so if someone else can point me in the right direction there and give me a rough outline on how to build a model, that would help.
If that's not the answer, maybe I need to do something completely different, either centered on using Content.Load or not, but basically I don't want my terrain sitting in a file, consistent between executions, I want to control the mesh data on load and randomize it, etc.
So how can I get a model generated completely programmatically, to show up on the screen, and still have its data exposed?
Model and its associated classes (eg: ModelMesh), are convenience classes. They are not the only way to draw models. It is expected that sometimes, particularly when doing something "special", you will have to re-implement them entirely, using the same low-level methods that Model uses.
Here's the quick version of what you should do:
First of all, at load time, create a VertexBuffer and an IndexBuffer and use SetData on each to fill each with the appropriate data.
Then, at draw time, do this:
GraphicsDevice.SetVertexBuffer(myVertexBuffer);
GraphicsDevice.Indices = myIndexBuffer;
// Set up your effect. Use a BasicEffect here, if you don't have something else.
myEffect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.Textures[0] = myTexture; // From Content.Load<Texture2D>("...")
GraphicsDevice.DrawIndexedPrimitives(...);

ASP.Net MVC 2: Using a viewmodel destroys my model binding

I guess this is a story of how frameworks cheerfully do 95% of what you need, but then frown disapprovingly at that final five percent; inform you that if you want to participate in nonstandard malarky it's your own business, thank you very much, and it'll be here if you decide you want to return to doing things it's good at. Generally speaking it's inevitable that this final five percent will contain some version of a must-have feature.
I have a strongly-typed view which updates a data object. I've used idiomatic MVC2 helpers, eg Html.TextBoxFor(model = > model.Name). I've used Editor templates for nested objects. (My backend is a collection of Mongo documents, so I need to represent complex types).
Then I need a dropdown. It turns out dropdowns are a bit finicky; no problem, I'll make a viewmodel instead of passing in the item directly:
class itemViewModel
{
...
public Item item { get; set; }
public IEnumerable<SelectListItem> dropdown { get; set; }
}
public ActionResult()
{
return View("Update", new itemViewModel(item, dropdown))
}
... that works fine, the dropdown populates. But! my view requires updating:
Html.TextBoxFor(model => model.Name) ->
Html.TextBoxFor(model => model.item.Name)
Great, problem solved. Oops, now my model binding doesn't work. I debug and look at the Request.Form values: Oh. item.Name instead of Name. Makes sense. I tell my Update view to expect an itemViewModel instead, and the binding works.
Oh wait, no it doesn't. Because I have nested objects that use editors. They are strongly typed and they don't know that the model they're receiving is actually a property of the viewmodel. So they're still spitting out Address.City instead of item.Address.City, and the binding fails.
I can think of several workarounds:
Write specialized custom model binder
Put the whole damn form into its own typed editor, so it gets the item model without knowing it's a property
Kill the viewmodel and hack the dropdown using the ViewData dictionary
Quit using the HtmlHelpers and hand-write the whole form
Write my own HtmlHelper extensions that will take a lamba and a model object as parameters.
Put every label/field grouping into an individual editor template.
All of these feel like either overkill or sloppiness. Viewmodels seem to be a clean, helpful approach. Does using them mean that I have to be sloppy in other areas, or reproduce minor variations on sizeable chunks of the framework? I taught myself C# over the last three months (a graphic designer trying to figure out what the hell static typing is with no CS background was probably pretty funny to watch). I work in isolation; there's no one to learn best practices from. I feel like if I don't learn some of them, I'll end up with an unmaintainable dung heap. So, your opinions are appreciated.
Sigh. A couple more hours of Googling and a few shots in the dark, and it appears that there is an unbelievably straightforward way for doing this, using the Bind attribute:
[HttpPost]
public ActionResult([Bind(Prefix="item")] item)
{
//item's complex types populate correctly
}
The attribute seems to be smart enough to reach into the complex types.
I will leave this as a tribute to my own ignorance, and in hopes that some other hapless n00b will find an answer quicker than I did.
Daniel, first off I should say that I commend you on your efforts and taking on .NET , C# and ASP.NET MVC all in one big bite. Ok, so you're frustrated and I relate to that. It's happens to all of us every now and then.
I should let you know that I'm not a fan (not in the least bit, in fact) of ASP.NET MVC (Problems with ASP.NET MVC Framework Design) and so I can't give you a worked out solution to your problem. But here is how I'd like you to see the situation you're in:
You're in a maze and you've made one wrong turn somewhere and you're going deeper into the maze but you're not going to find a way out. So what you need to do is back out till that wrong turn and see if there is another route. So starting from where you are, ask yourself, "why" for every step/change you've made and back up one step at a time asking why. does that make sense? you'll eventually get to a point where you have other alternative ways to tackle the same (original) problem.

C# - Naming a value combined "getter/setter" method (WebForms & Binding)

Looking for some help on some names for a project I'm currently working on. I don't have a compsci degree so I don't know what to call this.
I have a method called TryToGetSetValue(Direction direction, object value, object valueOnFail)
Then there would be a Direction enum
public enum Direction
{
ModelToForm,
FormToModel
}
Background
This is a legacy ASP.NET application. The models, database, and mainframe are designed poorly. I can't put in MVP or MVC patterns yet (too much work). ASP.NET code is a ridiculous mess (partial pages, single-page design, 5x the normal amount of jQuery, everything is a jQuery UI dialog). I'm just trying to put in a bridge so then I can do more refactoring over the next year.
I have ~200 fields that need to be set on a GET and written back on a POST.
I trying not to x2 these 200 fields and have 400 lines of code to support.
What would you call my method? enum? Is there so other form of binding that would be easy to use instead? I'm not a fan of the DetailsView or FormView built-ins of ASP.NET WebForms.
You probably want a Property
Just my $0.10 here, but how about:
public void AccessProperty(PropertyAccessType accessType, object value, object valueOnFail){...}
public enum PropertyAccessType
{
ModelToForm,
FormToModel
}

Categories