How to store a state in a Nova scene

by Frédéric Colin 1. September 2010 09:03

There are many possibilities to store user data inside a Nova Scene. That's why I've just added a new sample on Nova Wiki.

If you are interested, just have a look here.

SDK Tip: create a perpendicular plane to the camera

by Frédéric Colin 30. August 2010 06:28

Sometimes, it may be useful to create a kind of panel perpendicular to the active camera. That's why, I've added a new page to demonstrate it on our wiki

Enjoy!

Run Nova Studio on Common Language Runtime 4.0

by Frédéric Colin 24. August 2010 16:58

Maybe you wonder why it may be useful to run on CLR 4.0?

Well, I will say mainly for many Microsoft .NET Framework 4.0 news. As an example (it’s not the only one), if you want to use Windows Communication Foundation 4.0 in Nova Studio Plugins.

If you want to know more about this tip, just go to our wiki.

Change scene quality on the fly

by Frédéric Colin 24. June 2010 22:45

A very good question I was asked recently about the possibility of change on the fly graphics quality of a scene. It's indeed possible in different ways:

  • Using Nova Studio: just go to the "Developer" menu and click on Engine Options:

This options will display the following panel that will allow you to enable or disable any Nova quality options and channels and therefore the speed of rendering.

  • Using Nova scripting, Nova plugin model or Nova SDK. Indeed all Nova quality options and channels are available through Nova Object Model. In the following script, I first create a slider that will change on the fly Nova Engine option according 3 values ranges:
    • From 0.0 to 1.0 excluded: main quality options are disabled.
    • From 1.0 to 2.0 excluded: some quality options are enabled.
    • Else: all quality options are enabled.
Class Script

    Private slider As NovaSlider
    Private currentScene As NovaScene 
    
    Public Sub New(scene As NovaScene)
        currentScene = scene
        slider = Scene.CreateSlider()

        slider.Top = 10
        slider.Left = 10

        slider.Min = 0.0
        slider.Max = 3.0
        slider.Value = slider.Max
        slider.Width = 300
        slider.ID = "SliderQualitySensor"
        slider.Text = "Quality Sensor"
        slider.RelativeWidth = False
        slider.Visible = True
        
        AddHandler slider.ValueChanged, AddressOf manageValueChanged
    End Sub

    Private Sub manageValueChanged(ByVal o As Object, e As EventArgs)
        If  slider.Value >= 0.0 AndAlso slider.Value < 1.0 Then
            changeToLowQuality()                
        ElseIf  slider.Value >= 1.0 AndAlso slider.Value < 2.0 Then
            changeToMediumQuality()
        Else
            changeToHighQuality()
        End If
    End Sub
    
    Private Sub changeToLowQuality()
        currentScene.Engine.QualityLevel = 0
        NovaEngine.Shadows = False
                
        NovaEngine.BumpChannel = False
        NovaEngine.SpecularChannel = False
        NovaEngine.ReflectionChannel = False
        NovaEngine.RefractionChannel = False
        Novaengine.EmissiveChannel = False
        Novaengine.AmbientChannel = False 
        NovaEngine.ParticleSystems = False
        NovaEngine.MirrorMatrixActivated = False
    End Sub
    
    Private Sub changeToMediumQuality()
        currentScene.Engine.QualityLevel = 1
        NovaEngine.Shadows = False
                
        NovaEngine.BumpChannel = True
        NovaEngine.SpecularChannel = True
        NovaEngine.ReflectionChannel = True
        NovaEngine.RefractionChannel = False
        Novaengine.EmissiveChannel = False
        Novaengine.AmbientChannel = False 
        NovaEngine.ParticleSystems = True
        NovaEngine.MirrorMatrixActivated = False
    End Sub
    
    Private Sub changeToHighQuality()
        currentScene.Engine.QualityLevel = 3
        NovaEngine.Shadows = True

        NovaEngine.BumpChannel = True
        NovaEngine.SpecularChannel = True
        NovaEngine.ReflectionChannel = True
        NovaEngine.RefractionChannel = True
        Novaengine.EmissiveChannel = True
        Novaengine.AmbientChannel = True 
        NovaEngine.ParticleSystems = True
        NovaEngine.MirrorMatrixActivated = True
    End Sub
    
    Protected Overrides Sub Finalize()
        RemoveHandler slider.ValueChanged, AddressOf manageValueChanged
        currentScene.Widgets.Clear()
    End Sub
End Class

SliderManager.nsr (2.83 kb)

New scripting tip on Vertice wiki

by Frédéric Colin 21. June 2010 17:06

I've just published a new tip on Vertice wiki. It will allow you change the active novaCamera on the fly using a joystick.

Do you know also you can publish on our wiki? So don't hesitate to contact me if you need further informations and if you think it's too difficult, you should know that everyone has talent, it's my leitmotiv! 

If you are a little bit afraid about publishing, I will help you on your first article by an author-reader cycle, so join us in the Vertice community!

Detect camera Moves in Nova script

by Frédéric Colin 19. June 2010 22:23
Just a small tip to detect camera moves on a scene with Nova script. We may think that PropertyChanged event on NovaCamera can do it, but not...
Indeed for rendering performance reasons, it's not possible to track every properties changes on NovaCamera (see wiki). So here it is a little script to track camera moves on a Nova scene.
The tip is quite simple: at the scene creation, we store initial coordinates and on every rendering we check current coordinates with the previous one (since we work on floating real, we calculate the daifference according an epsilon). After the calcultation, if there is a difference, the camera moved. Since this check is done on every rendering (ie: 30 fps), the result of differential remains true during this time. We can work on the epsilon value to reduce somewhat the sensitivity, but to reduce it further, it should be considered a lapse of time during which the audit should not take place (using a stopwath as an example).
Here is the code Code:
  Private myScene As NovaScene
    Private epsilon As Single = 0.0001
    Private cameraLastGlobalPosition As Vector3
    Private cameraLastRotationPosition As Vector3
    Private camera As NovaCamera
    
    Public Sub New(ByVal scene As NovaScene)
        myScene = scene
        
        camera = myScene.GetCamera("MainCamera")
        StoreCameraPostion()

        AddHandler myScene.AfterRender, AddressOf manageAfterRender
    End Sub

    Private Sub manageAfterRender
        If Math.Abs(CType((camera.GlobalPosition - cameraLastGlobalPosition).Length, Single)) 
> epsilon OrElse Math.Abs(CType((camera.Rotation - cameraLastRotationPosition).Length, Single)) 
> epsilon Then    
            StoreCameraPostion()
            
            PluginHelper.LogInfo("it moves!")
        End If
    End Sub

    Public Sub StoreCameraPostion()
        cameraLastGlobalPosition = camera.GlobalPosition
        cameraLastRotationPosition = camera.Rotation 
    End Sub

    Protected Overrides Sub Finalize()
        RemoveHandler myScene.AfterRender, AddressOf ManageAfterRender
    End Sub
End Class 

Extend Nova Studio scripting with your own object model

by Frédéric Colin 20. May 2010 22:45

I've just published a new tip on our new wiki documentation that will allow you to extend Nova Studio Scripts.

I think, this tip will be very useful to all developers that use Nova scripting model. 

Enjoy!

Nova Explorer and MySql scripting sample - Part VI

by Frédéric Colin 14. November 2009 23:21

In my last post on this subject, I suggested that deploying MySQL ODBC drivers on client PC was not a good design. I spoke about Service Oriented Architecture or more specifically about Rest Services. There will be so many things to write about SOA and Rest Services but it's not the subject. I will just technically describe how I created a Rest service that returns records from my MySql Database.

First of all a small architecture picture:

In my sample, a Web Site on IIS is exposing REST Services over HTTP. These services expose data from my database called "bCatalog" and specifically from my table tProducts. The return data are xml formatted, more specifically in an atom format. Data may be accessed through specific urls such as:

  • "http://localhost:2522/ProductService.svc/tproducts: get all records from the table "tProducts". I highlighted the important tags in resulting xml document:

  • "http://localhost:2522/ProductService.svc/tproducts('Box01WithLabel')": get the specific product from de table "tProducts" where "objectID" (the primary key) is equal to "Box01WithLabel".

In the solution you can download (at the end of the post), you will see I used two Microsoft technologies: ADO.NET Data Services to create Rest Services and ADO.NET Entity Framework to request data from my sql database. Moreover, this time I used the managed MySql driver you can download here.

The next step was to update my Nova Script in VB.NET to request data on http. So I just proceeded as follow:

  • I replaced my database Connection String by a simple URL to request all data from "tProducts" table.
  • I completely rewrote the existing "LoadObjectsFromDatabase" method to take into account an http query. Technically, the .NET Framework offers all you need to make http requests and to interpret resulting XML data. The class to use to request is "HttpWebRequest" and the class to use to manipulate XML is "XmlDocument":

The harder task was to manipulate the atom XML Document. I lost a couple of minutes thinking why my xpath request (to get all entry tags, i.e. database records) didn't return anything. In fact, it was quite simple! Indeed, in atom format, there are default namespaces that must prefix all tags. The rest of the job was just finding nodes, route nodes and gatting and storage of values (database fields).

So, with this solution, my database is no more directly exposed to the web and especially I have not to deploy MySql ODBC drivers on each client. In the following zip, you will find:

  • the mxb file I used,
  • the corresponding nss file,
  • the nsr file that contains the previous scripting in case,
  • MySql database scripting.
  • the web exposing Rest Services (you will need Visual Studio 2008 SP1 to load the project)

VerticeSample-Last.zip (66.48 kb)

Enjoy!

Let me know if you are interested with the code to load data only on user interaction (with cache store) by leaving me a comment for this post. Moreover if you have any questions about SOA, please contact me.

Nova Explorer and MySql scripting sample - Part V

by Frédéric Colin 10. November 2009 12:30

It's now time to analyze the solution. We do not yet know very well (joke), but when I see a code or an architecture, I used to have a critical eye over. I confess that it is the same for the code I produce. So, here are my thoughts about the developed solution:

  • Deploying MySQL ODBC driver may be acceptable for an small intranet solution but is not acceptable for a full web compliant environment.
  • The direct use of a database from a Web Plugin may be dangerous for the database server since it forces administrators to openthe firewall for a specific port. That's unsecure and it's not the state of the art even if we place the database server in a DMZ. So we should use secured Web Services or Rest Services, i.e. on a standard protocol (http or https). this is what is called a Service-Oriented Architecture (SOA).
  • It will be better to only store the url of the services layer on http instead of a connection string. Url that can be set by the http server that manages the Web Page including the web plugin tag object.
  • I use the root account to access the catalog that I use to store my information. It's dangerous from a security point of view. We should use a dedicated account with less privileges.
  • You'll notice in my script, I hard stored the culture to format the price. On the other hand, we should not make this as a dynamic part since in my database I store Euros and not Dollars. And with the price of the dollar right now, it won't be interesting, except if we manage changes according to the user culture.
  • If you take a look at the database schema, you will notice it is simplistic. Indeed, products may have more data such as categories, keywords, etc. and we should use an integer as a primary key to perform powerful tables joins.
  • The last thing is the way to load once all data from database. What happens if data change in the database after web Plugin loading? Well, nothing in fact because data are not collected when the user interaction is executed.
  • Last but not least, the Web Plugin had to be updated to reference the missing "System.Data.dll" assembly to access "System.Data.Odbc" namespace. This update will be available soon with Nova Explorer auto-update.

Well, you are going to tell me that I coded with my feets ;-). In fact I responded directly to a need that I have been asked for. Moreover, any script may always be improved with time. I develop this solution in a couple of hours (in fact 3 hours). This partly explains it... Now I will attach myself to do things in the rules of art, anyway, as I believe they should be :-)

So in my next post I will show you how to develop a REST Architecture to expose my data and to consume it in a Nova script.

See you soon!

Nova Explorer and MySql scripting sample - Part IV

by Frédéric Colin 9. November 2009 23:13

Well, last but not least post on this topic, let's use this scene with differents clients.

  • Nova Explorer, certainly the most used:

  • A specific Windows Form application that use the .NET Web Player control:

  • The Web Plugin inside Internet Explorer:

The first step is to generate the mxc and the html files by using Nova Explorer Publish menu:

Then, you have just to open the generated Html page:

Just one more thing like will say a friend of mine: since the trust does not exclude some form of control, below here are of the database contents I used.

In my next post, I will talk about architecture and specifically the one that is induced by this complete sample. In other terms, I will talk about its pros and cons.

Disclaimer
The opinions expressed herein are the author own personal opinions and do not represent their employers' view in anyway..

© Copyright 2010 Nova by Vertice Team