Is there any code that I can use to display my 3D model ? , I Tried using HelixToolkit but i don't know how to use it, can anyone show me with a piece of code to just load a 3D Obj file
I'm assuming you've used Nuget to download the Helix3D libraries, but if you download the source code from GitHub then this includes an extensive ExampleBrowser application that gives guidance of how to use Helix3D
Helix3D on GitHub
My application is structured as follows:
XAML
<h:HelixViewport3D x:Name="HelixViewport3D" ShowViewCube="False">
<h:DefaultLights/>
<ModelVisual3D x:Name="MyModel"/>
</h:HelixViewport3D>
C#
var scene = new Model3DGroup();
scene.Add(Load3dObject(#"C:\filename.obj"));
MyModel.Content = scene;
Which calls this helper function Load3dObjectI created to help clean up the code.
private Model3D Load3dObject(string objName)
{
var reader = new ObjReader();
var modelGroup = reader.Read(objName);
return modelGroup;
}
Related
I am really struggling with the fact that i don't know how can I load and use a TensorFlow image classifier model in c#.
To be more precise I want to use a model trained in Teachable Machine that can be exported in multiple TensorFlow formats.
And if possible an example code will be really helpful.
I have tried to ask the same question but it got closed, I really need to find out how can I load and use the model so please let the question open. Thanks a lot for the support.
If you need only to evaluate model in C# code, then you need some lightweight library that can be used as loader and evaluator for your network.
There are many good libraries to work with tensorflow models in C#, like:
TensorFlowSharp
TensorFlow.NET
Unfortunately, all existing libraries has pre-defined logic for training model too, so that is a little ballast for your task.
To accomplish your purposes, please see this detailed article about how to load TF model into your C# application using TensorFlowSharp.
I used TensorFlowSharpin the past, but that library is still stuck with TensorFlow 1.x, and development seems quite dead. Because of that, I moved on to ML.NET.
Please see this article about how to use ML.NET with C# (disclaimer: I was the author of that article). Below is the gist of it.
Convert saved_model to onnx
Install tf2onnx.
pip install tf2onnx
Use it to convert saved_model to onnx.
python -m tf2onnx.convert --saved-model <path to saved_model folder> --output "model.onnx"
Use ML.NET to make prediction
Install the necessary packages.
dotnet add package Microsoft.ML
dotnet add package Microsoft.ML.OnnxRuntime
dotnet add package Microsoft.ML.OnnxTransformer
Define the input and output model classes.
public class Input
{
[VectorType(<input size>)]
[ColumnName("<input node name>")]
public float[] Data { get; set; } // Remember to change the type if your model does not use float
}
public class Output
{
[VectorType(<output size>)]
[ColumnName("<output node name>")]
public float[] Data { get; set; } // Remember to change the type if your model does not use float
}
Load the model in onnx format.
using Microsoft.ML;
var modelPath = "<path to onnx model>";
var outputColumnNames = new[] { "<output name>" };
var inputColumnNames = new[] { "<input name>" };
var mlContext = new MLContext();
var pipeline = _mlContext.Transforms.ApplyOnnxModel(outputColumnNames, inputColumnNames, modelPath);
Make prediction
var input_data= ... // code to load input into an array
var input = new Input { Data = data };
var dataView = mlContext.Data.LoadFromEnumerable(new[] { input });
var transformedValues = pipeline.Fit(dataView).Transform(dataView);
var output = mlContext.Data.CreateEnumerable<Output>(transformedValues, reuseRowObject: false);
// code to use the result in output
I'm working on a Cities: Skylines mod and I want to access the sharedassets.assets file(s) the game has in the Data folder programmatically to get a mesh/prefab.
I've found a tool called Unity Assets Bundle Extractor (UABE) and it is able to open up these files and extract the mesh.
Is there a way to extract a mesh from the sharedassets programmatically with C# code like UABE does?
I've looked in the Unity documentation but so far only have seen this page (not sure if relevant): https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFile.html
I tried adapting the code from there but I haven't had any success so far, only have had not found error messages
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "sharedassets11"));
Is there a way to achieve this? Thanks
Look at the API for AssetBundle.LoadFromFile.
There is a second method AssetBundle.LoadAsset (or alternatively also maybe AssetBundle.LoadAllAssets) you will need:
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "sharedassets11"));
if (myLoadedAssetBundle == null)
{
Debug.Log("Failed to load AssetBundle!");
return;
}
var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("NameOfTheAccordingObject");
Instantiate(prefab);
myLoadedAssetBundle.Unload(false);
I have a web application which uses sharpmap 1.1 to generate maps(Works Pretty awesome), now i want to add an Open street map as background to my current map. I tried some online examples but no luck.
So far I've tried the below.
var ShapeDataProvider = new SharpMap.Data.Providers.ShapeFile(#"Local shp Path");
var layer = new VectorLayer("test");
layer.DataSource = ShapeDataProvider;
var layerOSM = var layer = new VectorLayer("OSM");
layerOSM.DataSource = (SharpMap.Data.Providers.IProvider)(new SharpMap.Layers.TileAsyncLayer(new BruTile.Web.OsmTileSource(), "OSM"));
_map.Layers.Add(layerOSM);
_map.Layers.Add(layer);
So far I'm stuck at this error and Literally no way pass this it seems,
Argument 1: cannot convert from 'BruTile.Web.OsmTileSource' to
'BruTile.ITileSource'
The version of assemblies I'm using in my project are
Sharpmap 1.1.0.0
Brutile 0.7.4.4
ProjNet 1.3.0.3
NetTopologySuite 1.13.2.0
GeoAPI 1.7.2.0
I've added all are from Nuget, If someone could share me a piece of code which works in accessing OpenStreetMap as background layer?
that'll be a life-saver.
Thanks in advance, Cheers!
I suspect different versions of the BruTile assembly referenced in your projects.
I am currently working on sharpmap project with the need to work on offline maps. As i am fresher in this field,I am following the sharpmap tutorial and facing a problem with loading new shape files in the given tutorial code.
For Example :\
SharpMap.Layers.VectorLayer("States");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("path_to_data\\states_ugl.shp", true);
At this line of code, if i pass a different shapefile, code builds with a blank background or no display.
I have tried with different shape files with different sizes but the result is the same. It only works for the mentioned states_ugl.shp file given in the code. Please need help regarding this issue as I am a fresher in this field.
Thanks.
Try giving layer styling for your layer, something like below.
layer.DataSource = DBlayer;
layer.Style.Fill = new SolidBrush(Color.Transparent);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.MaxVisible = 13000;
My plan:
I'm trying to setup my C# project to communicate with Nodebox to call a certain function which populates a graph and draws it in a new window.
Current situation: [fixed... see Update2]
I have already included all python-modules needed, but im still getting a
Library 'GL' not found
it seems that the pyglet module needs a reference to GL/gl.h, but can't find it due to IronPython behaviour.
Requirement:
The project needs to stay as small as possible without installing new packages. Thats why i have copied all my modules into the project-folder and would like to keep it that or a similar way.
My question:
Is there a certain workaround for my problem or a fix for the library-folder missmatch.
Have read some articles about Tao-Opengl and OpenTK but can't find a good solution.
Update1:
Updated my sourcecode with a small pyglet window-rendering example. Problem is in pyglet and referenced c-Objects. How do i include them in my c# project to be called? No idea so far... experimenting alittle now. Keeping you updated.
SampleCode C#:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);
ScriptSource source = engine.CreateScriptSourceFromFile("test.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
SampleCode Python (test.py):
from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle
flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)
def draw(canvas):
canvas.clear()
flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
for boid in flock:
push()
translate(boid.x, boid.y)
scale(0.5 + boid.depth)
rotate(boid.heading)
arrow(0, 0, 15)
pop()
canvas.size = 600, 300
def main(canvas):
canvas.run(draw)
Update2:
Line 139 [pyglet/lib.py] sys.platform is not win32... there was the error. Fixed it by just using the line:
from pyglet.gl.lib_wgl import link_GL, link_GLU, link_WGL
Now the following Error:
'module' object has no attribute '_getframe'
Kind of a pain to fix it. Updating with results...
Update3:
Fixed by adding following line right after first line in C#-Code:
setup.Options["Frames"] = true;
Current Problem:
No module named unicodedata, but in Python26/DLLs is only a *.pyd file`. So.. how do i implement it now?!
Update4:
Fixed by surfing: link text and adding unicodedata.py and '.pyd to C# Projectfolder.
Current Problem:
'libGL.so not found'... guys.. im almost giving up on nodebox for C#.. to be continued
Update5:
i gave up :/ workaround: c# communicating with nodebox over xml and filesystemwatchers. Not optimal, but case solved.
-X:Frames enables the frames option as runtime (it slows code down a little to have access to the Python frames all the time).
To enable frames when hosting you just need to do:
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(new Dictionary<string, object>() {
{ "Frames", true }
});
Instead of the null that you're passing now. That's just creating a new dictionary for the options dictionary w/ the contents "Frames" set to true. You can set other options in there as well and in general the -X:Name option is the same here as it is for the command line.