Get ramp attribute in compute() - maya-api

I am basically making a ramp shader and trying to find the proper way to get values from a ramp attribute in the compute() function for a node.
I know it can be done with
MObject oThis = thisMObject();
MRampAttribute rampAttribute(oThis, aRamp); // aRamp is our ramp MObject.
but is it safe to do this in compute?
The Maya documentation mentions in a few places that, in compute, we should only use attributes in the MDataBlock to get input data, but I can't find a way to get a ramp attribute from the MDataBlock. I couldn't find any official code samples using MRampAttribute in compute() either.

Its fine to do this. I don't think you can access MRampAttribute from the data block. I have some plugins nodes that use it exactly as you wrote and I've not noticed any problem.
It's not the only occasion where you need to use the MObject to get a plug in compute() either.

Related

Accessing regmap RegFields

I am trying to find a clean way to access the regmap that is used with *RegisterNode for creating documentation and testing files. The TLRegisterNode has methods for generating the json through some Annotations. These are done in the regmap method by adding them to the ElaborationArtefacts object. Other protocols don't seem to have these annotations.
Is there anyway to iterate over the "regmap" Register Fields post elaboration or during?
I cannot just access the regmap as it's not really a val/var since it's a method. I can't quite figure out where this information is being stored. I don't really believe it's actually "storing" any information as much as it is simply creating the hardware to attach the specified logic to the RegisterNode based logic.
The JSON output is actually fine for me as I could just write a post processing script to convert JSON to my required formats, but I'm wondering if I can access this information OR if I could add a custom function call at the end. I cannot extend the case class *RegisterNode, but I'm not sure if it's possible to add custom functions to run at the end of the regmap method.
Here is something I threw together quickly:
//in *RegisterRouter.scala
def customregmap(customFunc: (RegField.Map*) => Unit, mapping: RegField.Map*) = {
regmap(mapping:_*)
customFunc(mapping:_*)
}
def regmap(mapping: RegField.Map*) = {
//normal stuff
}
A user could then create a custom function to run and pass it to the regmap or to the RegisterRouter
def myFunc(mapping: RegField.Map*): Unit = {
println("I'm doing my custom function for regmap!")
}
// ...
node.customregmap(myFunc,
0x0 -> coreControlRegFields,
0x4 -> fdControlRegFields,
0x8 -> fdControl2RegFields,
)
This is just a quick example I have. I believe what would be better, if something like this was possible, would be to have a Seq of functions that could be added to the RegisterNode that are ran at the end of the regmap method, similar to how TLRegisterNode currently works. So a user could add an arbitrary number and you still use the regmap call.
Background (not directly part of question):
I have a unified register script that I have built over the years in which I describe the registers for a particular IP. It works very similar to the RegField/node.regmap, except it obviously doesn't know about diplomacy and the like. It will generate the Verilog, but also a variety of files for DV (basic `defines for simple verilog simulations and more complex uvm_reg_block defines also with the ability to describe multiple of the IPs for a subsystem all the way up to an SoC level). It will also print out C Header files for SW and Sphinx reStructuredText for documentation.
Diplomacy actually solves one of the main issues I've been dealing with so I'm obviously trying to push most of my newer designs to Chisel/Diplo.
I ended up solving this by creating my own RegisterNode which is the same as the rocketchip RegisterNodes except that I use a different Elaboration Artifact to grab the info and store it for later.

getIn() not traversing an Immutable structure

I have an OrderedMap called "firebase" from the immutable-js library which has three leaf nodes:
but then I'd expect to be able to inspect the ordered map at firebase.auth with:
newValue.getIn(['firebase', 'auth'])
But that doesn't work:
Can someone help me understand what I'm doing wrong.
Your auth is an Immutable OrderedMap, but it seems that your firebase is a simple JavaScript object, not an Immutable.js one. Hence why getIn would not work. Thus newValue.get('firebase').auth would suffice.
If you are not using the redux-immutable package then you are probably going to have these (and other) issues due to combineReducers. However, combineReducers created using redux-immutable uses Immutable.js API to iterate the state so check it out.

Alternative to global variables

Hi I am doing a simple script where I want to track what step I am up to and use the result from a button click handler.
1)I cannot pass the variable as it is an event
2)Cannot use global variables as they seem to be constants only once set
Is there any way to set and object or variable multiple times and access the current value from within a handler function?
Found several examples suggesting a hidden widget, as well as that being a poor solution I also struggled to retrieve the value once set. IE it had a .setValue but no .getValue
Help please this is not a difficult thing in any other language I have tried but new to GAS
Cheers
There are more options - one, as you mentioned is to use a hidden widget. Although there is no .getValue(), it can be accessed through e.parameter within the click handler.
Two, for small amounts of data, you can use ScriptProperties / UserProperties and CacheService
Third, you can use the script DB or a spreadsheet if you are dealing with large amounts of data.
Having said all this, it would be better if you can post some code of what you're trying to achieve. Many times, code speaks louder than words.
Private Cache is intended for this type of thing https://developers.google.com/apps-script/reference/cache/

Where in the Google source code is window.document.all function defined?

Any one know where the function window.document.all is defined? Tried searches but nothing coming up.
Many thanks
Edit: note I am aware that thus deprecated and documentgetelementbyid should be used. still need to know what is executed when this function is run.
It has nothing to do with Google V8. It is a legacy property of the document object. It stores an array of all elements in the document, indexed by ID.
You should use document.getElementById() instead.
If you are asking this question then the source code will probably not be useful to you in the first place. But here you go:
https://github.com/WebKit/webkit/blob/5b7f307f78ff665c0102bd008d2a47b9b2f8e5b5/Source/WebCore/dom/Document.cpp#L4405

.get mootools method not working in joomla 1.5

i have a problem in joomla 1.5.18. i'm trying to get text from an element using for instance
var divContent = $$('#myDiv').get('text');
but each time i get the error, in chrome: Uncaught TypeError: Object #<HTMLDivElement> has no method 'get'; in firefox: divContent.get is not a function. why i'm getting this error?
even following samples in mootools i get the same.
i know how to do it for each object in the collection. i got doing $$('.') and using the "each" method:
$$('p.classname').each(function (el){
el.addEvent('click', function() {
var txt = el.get('text');
...
});
});
and obviously i add the function onto domready. i don't use jquery 'cause mootools & jquery stops the events each one... -i tried once & what i needed didn't work- and i wish to use all joomla resources including mootools.
checking the version in mootools.js it says 1.13 (?)
not sure which version of mootools comes in joomla 1.5.18, it may be 1.2.5. if so, .get should work but not as you expect it to.
You are probably a jquery user, used to $("#myid") and find that the only way to get similar results with the # in there in mootools is via document.getElements, aka, $$.
the problem is, to get a single item by id in mootools, you actually do document.id("mydiv") or even $("mydiv"). $$("#mydiv") will actually return a COLLECTION of elements with a single member, so [obj], so the real element is $$("#mydiv")[0].
if you apply a .get method to a COLLECTION, the getter normally iterates via a .each through all members and performs the get individually. it will return a new array member for each member of the collection - i.e. ["innertext"]; - though there should be a method for the collection, make sure that the element is there, it's in domready / onload and it's a unique id.
Still, I'd swap to using the $("mydiv").get("text"), it ought to be fine. This is all all too common assumption of jquery users that don't read the manual, in my experience. It results in bad and un-performant code due to all the .each iterations mootools has to silently do to work with the collection for you. Just saying.
You can also (and should) upgrade your Joomla to the latest version (security fixes, etc) and I believe it was about version 1.5.20 they included a newer version of mootools right out of the box (also there is a plugin for mootools upgrade you can enable). I believe the version included out of 1.5.20 is like 1.2.5 or something...
That may help!