Dynamic creation of prims in second life (linden-scripting-language) - linden-scripting-language

I am an experienced programmer, but new to second life / LSL. I was wanting to be able to algorithmically create structures, buildings, objects, etc. But, I cannot find a function that will actually "create" a new prim with a given set of properties and place it in the environment. Can this be done?

Not easily - what you'd need to do is have a base controller prim, which contains a second prim.
This second prim would have a script in which when rezzed would listen to the base controller, and act on parameters passed to it by transforming it's own properties.

Related

how to clone a Vector in codenameone

I need a clean copy of a Vector not a reference.
In Swing I use Vector.clone(); (Not Allowed in codenmeone complains its protected.)
In Codenameone I tried Vector someName = new Vector((Vector)anotherVector)
someName becomes a referance as what ever changes are made to anotherVector, someName inherits those changes.
Thoughts?
Best Regards
The new vector approach works but it isn't a deep copy of the elements within. Unfortunately you can't do a deep copy since clone() requires reflection which we don't have. Unfortunately there's no easy answer. You would need to literally go over every element and create a copy of that element since we can't generically duplicate it.
This can be relatively simple, assuming a vector of MyObject which has a constructor that accepts an existing instance then something like this will work:
Vector<MyObject> newVector = new Vector<>();
for(MyObject obj : oldVector) {
newVector.add(new MyObject(obj));
}

Step Function For Array in Anylogic

How to use an step function for an array in Anylogic?
step function is applied to double values, but I want to applied on elements of an array at a specific time.
You can't... so this is a solution:
Instead of an array you should use a linkedHashMap where your key is the specific time and the element is the step value you want at that time. So you defined it as follow:
And you put the values like this:
stepsArray.put(3.0,2.3);
where 3.0 is the time in which the step will occur and 2.3 is the value the step will take. You have to put there all the values you need. You are the one who has to fill these values according to your needs.
Then you create an cyclic event that will evaluate if it's time to apply a step and you create a variable of type double that will be the one storing the value of the step.
So, the event:
double theTime=round(100*time())/100.0;//it's better to round up the time just in case
if(stepsArray.containsKey(theTime)){
variable=stepsArray.get(theTime);
}
note that I'm using a variable, not a dynamic variable.. they you can connect the variable to wherever your step is needed in the sd model.
This method is a bit complicated, but it's the most general for your completely ambiguous question.
Not sure Felipe's approach is the best one but maybe I misunderstand the question.
Have you tried using a "table function" object? Define it as below where the horizontal axis represents the time unit and the vertical your step function data:
Then, use a cyclic event that every relevant time unit (depends on your model) pulls the current required value from the table function:

I have MDLAsset created from an SCNScene. How do I extract MDLMeshs, MDLCamera(s), and MDLLights?

I am struggling trying to traverse an MDLAsset instance created by loading an SCNScene file (.scn).
I want to identify and extract the MDLMeshs as well as camera(s) and lights. I see no direct way to do that.
For example I see this instance method on MDLAsset:
func childObjects(of objectClass: Swift.AnyClass) -> [MDLObject]
Is this what I use?
I have carefully labeled things in the SceneKit modeler. Can I not refer to those which would be ideal. Surely, there is a dictionary of ids/labels that I can get access to. What am I missing here?
UPDATE 0
I had to resort to pouring over the scene graph in the Xcode debugger due to the complete lack of Apple documentation. Sigh ...
A few things. I see the MDLMesh and MDLSubmesh that is what I am after. What is the traversal approach to get it? Similarly for lights, and camera.
I also need to know the layout of the vertex descriptors so I can sync with my shaders. Can I force a specifc vertex layout on the parsed SCNScene?
MDLObject has a name (because of its conformance to the MDLNamed protocol), and also a path, which is the slash-separated concatenation of the names of its ancestors, but unfortunately, these don't contain the names of their SceneKit counterparts.
If you know you need to iterate through the entire hierarchy of an asset, you may be better off explicitly recursing through it yourself (by first iterating over the top-level objects of the asset, then recursively enumerating their children), since using childObjects(of:) repeatedly will wind up internally iterating over the entire hierarchy to collect all the objects of the specified type.
Beware that even though MDLAsset and MDLObjectContainerComponent conform to NSFastEnumeration, enumerating over them in Swift can be a little painful, and you might want to manually extend them to conform to Sequence to make your work a little easier.
To get all cameras,
[asset childObjectsOfClass:[MDLCamera class]]
Similarly, to get all MDLObjects,
[asset childObjectsOfClass:[MDLObjects class]]
Etc.
MDLSubmeshes aren't MDLObjects, so you traverse those on the MDLMesh.
There presently isn't a way to impose a vertex descriptor on MDL objects created from SCN objects, but that would be useful.
One thing you can do is to impose a new vertex descriptor on an existing MDL object by setting a mesh's vertexDescriptor property. See the MDLMesh.h header for some discussion.

How to design/implement the command pattern when commands have variable number of parameters?

I am constructing a diagram editor in WPF on Windows 7.
Notwithstanding that I am on the verge of learning significant design techniques (TDD, Prism, MVVM, dependency injection), though I understand a handful of established design patterns, here is my question:
As a whole, the commands will have different numbers and type combination of parameters.
(To be clear, each command has a fixed set of parameters)
For example, the following, all of which can be performed with the mouse :
Command Create New Node : parameter = location for new node (Point)
Command Move Node to new position : parameters= Node (graphNode), new location (Point)
Command make an edge connecting two nodes: parameters= From Node(graphNode), To Node(graphNode), Type of Edge (GraphEdgeType)
How ought I apply either the factory or abstract factory pattern to best encapsulate such commands?
What is the preferred way for the client to pass these parameters to the Command executive?
(I have hunted here and elsewhere but not found questions or answers so explicitly framed, and ready to be redirected to something I couldn’t find:-)
[EDIT] I have not been explicit enough:
IF I make a CommandFactory to return Commands, should it be passed commandType (an Enum, say) and a parameter set object ... or should it only be passed the commandType, so that the client subsequently primes the command with parameters?
I suspect that this https://cuttingedge.it/blogs/steven/pivot/entry.php?id=91 (which I found at Command Pattern : How to pass parameters to a command?) is what I am looking for even though I do not yet understand it - it likely transcends any of the melange of techniques I was envisaging but could not express.
How ought I apply either the factory or abstract factory pattern to best encapsulate such commands?
What are you talking about? Just pass in a class with properties for all the "parameters" as parameter.
(If anything this sounds like you need a state machine.)

How to use an array that is created in one class in a second class?

I have created an array in the implementation of my class loginController. Now I want to use this array (with its objects) in another class of my project. What is the right way to import it?
You really need to specify the language.
In general, if the array is a member variable in one class, it's considered bad form to directly use it from another class. This violates the "encapsulation" idea that is quite the thing in object-oriented programming.
The preferred thing to do is often to add methods, called "getters" and "setters", to the class owning the array, or make it available by some other more structural means, which depend on the exact semantics and usage of the array. It might, for instance, not be required that outside users even know that it is an array.
There is no right way given this information. What is located in the array, only integers or strings/objects etc. Do you store objects of pointers to objects?
Passing the array is the sameway as passing any other object to a function
The general answer would be: declare it as public
It is not very good thing to do but as a beginner, you can start with that.

Resources