[x3d-public] Thoughts for x3d.py str() calls
John Carlson
yottzumm at gmail.com
Wed Oct 25 03:36:09 PDT 2023
Here's some example joint center numbers, straight out of Blender, with no
units applied, so this is in cm. What I will do is apply appropriate
rounding, but this means I have to apply rounding in every place that
interfaces with x3d.py. I guess we will add an option to round according to
the designer's wishes. But we have to round every floating point number
single, AFAIK, all vectors, etc. This touches a lot of places in the
code. I realize that it touches an equal number, if not more in x3d.py, so
I'll eat the bullet until Joe complains about something else.
center (0.0, 0.0, 0.0)
center (0.0, 97.2412338256836, 0.0)
center (12.659440040588379, 97.504638671875, 0.017503606155514717)
center (12.603313446044922, 56.04541778564453, -7.075007915496826)
center (12.15206241607666, 7.1099324226379395, -7.984044551849365)
center (14.045498847961426, 4.36808967590332, 2.269944429397583)
center (14.045498847961426, 4.36808967590332, 2.269944429397583)
center (-10.877525329589844, 97.78365325927734, 0.11880593001842499)
center (-13.610543251037598, 57.680973052978516, -2.9976742267608643)
center (-15.683001518249512, 9.33935260772705, -4.999979496002197)
center (-17.3916072845459, 4.219162464141846, 3.1728157997131348)
center (-17.3916072845459, 4.219162464141846, 3.1728157997131348)
center (0.13338443636894226, 107.96749877929688, -0.5744487047195435)
center (0.1378690004348755, 116.86978149414062, -1.0721012353897095)
center (0.19800527393817902, 125.70938110351562, -1.5655956268310547)
center (0.26068776845932007, 134.5579376220703, -1.6424936056137085)
center (0.16388075053691864, 143.69683837890625, -2.840054750442505)
center (0.03892628848552704, 155.13670349121094, -5.653977394104004)
center (-0.1800401508808136, 162.01907348632812, -5.423117160797119)
center (-0.17377641797065735, 182.1359405517578, -4.124372482299805)
center (9.166765213012695, 145.88026428222656, -5.197458267211914)
center (26.146337509155273, 144.68362426757812, -5.138150215148926)
center (28.065906524658203, 120.46793365478516, -7.821353435516357)
center (32.07126998901367, 96.60173797607422, -6.075016975402832)
center (31.337974548339844, 95.66389465332031, -3.5185515880584717)
center (29.714406967163086, 93.0094985961914, -2.17582368850708)
center (29.5553035736084, 89.24510955810547, -1.3806376457214355)
center (32.291690826416016, 94.74623107910156, -4.222545146942139)
center (34.16044616699219, 89.05512237548828, -3.613931655883789)
center (34.828487396240234, 84.86717224121094, -4.1235432624816895)
center (35.18022155761719, 82.01087951660156, -4.478684902191162)
center (32.807472229003906, 95.1517105102539, -5.469103813171387)
center (35.01175308227539, 88.26265716552734, -6.2238898277282715)
center (36.31690979003906, 84.08856964111328, -6.681747913360596)
center (36.603084564208984, 81.26410675048828, -7.149042129516602)
center (33.611297607421875, 95.3590087890625, -7.207472801208496)
center (35.568634033203125, 90.04212188720703, -8.354555130004883)
center (36.391998291015625, 85.34164428710938, -9.333662033081055)
center (36.662662506103516, 82.93714141845703, -9.61007022857666)
center (32.87529373168945, 95.54676055908203, -8.844550132751465)
center (35.2270393371582, 90.29863739013672, -10.437943458557129)
center (36.15745162963867, 87.29093170166016, -11.432869911193848)
center (36.50593566894531, 85.70613098144531, -11.957535743713379)
On Wed, Oct 25, 2023 at 2:42 AM John Carlson <yottzumm at gmail.com> wrote:
> Joe wants lower precision numbers output from x3d.py. I could care less.
> There’s example code in
>
>
> https://github.com/coderextreme/BlenderX3DSupport/blob/main/io_scene_x3dv/blender/exp/x3dv_blender_export.py
>
> please look for chicenter and center, lines 662-732.
>
> Note that the lengthUnitConversion can be 0.01 to convert cm to m. We
> realize this can be done with a UNIT statement. Not all of our clients’
> data is in m, so we convert all numbers to m by multiplying, which is where
> the problem started. If the UNIT statement works across all browsers, we
> will gladly switch to it.
>
> We can also patch by providing a scale field, but I’m not sure if scaling
> applies to interpolators in all cases. Some browser vendors say that
> transforms do not apply to interpolators, and recommend moving them outside
> of Transforms.
>
> Please consider this use case of x3d.py. It seems like you’re only
> focused on a single use case, some programmer constructing a whole
> scenegraph as a unit, by hand. I will try to create a better test case,
> but I’d rather think of possible solutions. I will work on finding
> test cases with HAnim.
>
> John
>
> On Tue, Oct 24, 2023 at 9:22 PM Brutzman, Donald (Don) (CIV) <
> brutzman at nps.edu> wrote:
>
>> I have no idea what you are talking about because you have not created a
>> test case that explains what you want. Sorry.
>>
>>
>>
>> all the best, Don
>>
>> --
>>
>> Don Brutzman Naval Postgraduate School, Code USW/Br
>> brutzman at nps.edu
>>
>> Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA
>> +1.831.656.2149
>>
>> X3D graphics, virtual worlds, navy robotics
>> https://faculty.nps.edu/brutzman
>>
>>
>>
>> *From:* John Carlson <yottzumm at gmail.com>
>> *Sent:* Thursday, October 19, 2023 9:16 AM
>> *To:* GPU Group <gpugroup at gmail.com>
>> *Cc:* Brutzman, Donald (Don) (CIV) <brutzman at nps.edu>; Peitso, Loren
>> (CIV) <lepeitso at nps.edu>; X3D Graphics public mailing list <
>> x3d-public at web3d.org>
>> *Subject:* Re: Thoughts for x3d.py str() calls
>>
>>
>>
>> There are 239 instances of "str" in X3duomToX3dPythonPackage.xslt. 208
>> of them are not related to isinstance
>>
>>
>>
>> Please advise before I go sailing in modifying them to another function.
>> This looks like a major modification.
>>
>>
>>
>> On Thu, Oct 19, 2023 at 11:09 AM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Redeclaring the float class doesn't seem to work, isinstance fails
>>
>>
>>
>> Monkey patching doesn't work:
>>
>>
>>
>> def custom_float_str(value):
>>
>> return f"{value:.5g}"
>>
>>
>>
>> # Monkey-patch the float class
>>
>> float.__str__ = custom_float_str
>>
>>
>>
>> Overriding the str function doesn't work, because that overrides the str
>> type as well.
>>
>>
>>
>> Adding methods to SFFloat doesn't seem to work.
>>
>>
>>
>> I'm pretty much bamboozled, and the next step is to replace many str()
>> calls in x3d.py with my own function, which was my original idea.
>>
>>
>>
>> Another idea is to convert all floating point input to x3d.py to strings.
>>
>>
>>
>> Hmm! I don't like python much, as a beginner.
>>
>>
>>
>>
>>
>> On Thu, Oct 19, 2023 at 9:56 AM John Carlson <yottzumm at gmail.com> wrote:
>>
>> I’m guessing I can override float.__str__() and maybe the list.__str__()
>> methods. Do I do that in x3d.py or my code?
>>
>>
>>
>> I’m on unfamiliar ground and will have to do some testing unless someone
>> has a definitive response.
>>
>>
>>
>> I hope this works. I will run through the smoke tests provided.
>>
>>
>>
>> I will probably modify the Blender X3DV exporter first, and if that
>> doesn’t work, proceed to modify x3d.py. I don’t think it’s a good idea to
>> modify x3d.py itself.
>>
>>
>>
>> So far, I haven’t seen anyone replacing the str() function.
>>
>>
>>
>> John
>>
>>
>>
>>
>>
>> On Mon, Oct 16, 2023 at 11:10 AM GPU Group <gpugroup at gmail.com> wrote:
>>
>> It seems possible to override functions in python, if there are just a
>> few to override.
>>
>> And one suggestion for x3d.py imperfections is to apply fixes at runtime
>> in some initialization function.
>>
>> - that assumes/requires just a few target functions, not 480 functions
>> that need to be repaired
>>
>> - so for some fixes it may be helpful to change the upstream x3d.py to
>> call a function that can be easily replaced.
>>
>> -Doug
>>
>> Example:
>>
>> file myclass.py
>>
>> class Wonky:
>>
>> def __init__(self):
>>
>> self.color = "Red"
>>
>> def func1(self, color :str) -> bool:
>>
>> if color == self.color:
>>
>> return True
>>
>> return False
>>
>>
>>
>> file override.py
>>
>> from myclass import *
>>
>>
>>
>> mc = Wonky()
>>
>> print("match with Blue? "+str(mc.func1("Blue")))
>>
>>
>>
>> def func2(self, color: str) -> bool:
>>
>> if self.color != color:
>>
>> return True
>>
>> return False
>>
>> Wonky.func1 = func2 # <<<<<<<<<<<< OVERRIDE
>>
>> print("don't match with Blue? "+str(mc.func1("Blue")))
>>
>>
>>
>> output:
>>
>> match with Blue? False
>>
>> don't match with Blue? True
>>
>> -Doug
>>
>>
>>
>> On Mon, Oct 16, 2023 at 9:55 AM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Instead of calling str() to print out a value, call a function that does
>> precision floating point formatting on floats according to a user’s
>> wishes. If the value is a list, call the function recursively with a list
>> comprehension, otherwise, call str.
>>
>>
>>
>> I think this is doable by mere humans.
>>
>>
>>
>> Thanks,
>>
>>
>>
>> John
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20231025/53994d52/attachment-0001.html>
More information about the x3d-public
mailing list