The spec explains the animations.samplers.input property as:
The index of an accessor containing keyframe input values, e.g., time. That accessor must have componentType FLOAT. The values represent time in seconds with time[0] >= 0.0, and strictly increasing values, i.e., time[n + 1] > time[n].
However, I'm having a bit of trouble understanding this from the first basic example on the demo repo, Animated Triangle
Specifically, if we bring the relevant binary data for the animation from animation.bin and decode it into a Float32Array, we get the following list of values:
[0, 0.25, 0.5, 0.75, 1, 0, 0, 0, 1, 0, 0, 0.7070000171661377, 0.7070000171661377, 0, 0, 1, 0, 0, 0, 0.7070000171661377, -0.7070000171661377, 0, 0, 0, 1]
This of course does not make sense in light of "strictly increasing values".
What am I misunderstanding here? How are these values meant to be used (in combination with output) in order to update the rotation over time?
Note that animation.bin is the view referenced from the input sampler. In other words, from the gltf
input == accessor 2
accessor 2 == bufferView 2
bufferView 2 == bytes(0-100) from buffer 1
buffer 1 == animation.bin
You've decoded too far. Although bufferView 2 is bytes 0 to 100, accessor 2 does not call for all those bytes. Here's accessor 2:
{
"bufferView" : 2,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 5,
"type" : "SCALAR",
"max" : [ 1.0 ],
"min" : [ 0.0 ]
},
Note the count: 5 in there. Count is defined as:
The number of attributes referenced by this accessor, not to be confused with the number of bytes or number of components.
So, accesessor 2 is the first five SCALAR values from offset 0 in bufferView 2, namely the first five numbers from your decoded output above:
[0, 0.25, 0.5, 0.75, 1]
FWIW, there are tools to help investigate glTF binary files. Here's the "Peek Definition" function from VSCode's glTF extension:
(Disclaimer, I'm one of the authors of this extension, although I did not write this decode feature myself).
Related
I know you can generate a normal range with Array(0...10), but how about reversed?
For example:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
You can do:
let tenToZero: [Int] = (0...10).reversed()
Note that it is necessary to specify the type here, otherwise it would use the overload of reversed that returns a ReversedCollection.
Alternatively, you can use either of the stride functions and use -1 for the by argument:
stride(from:to:by:)
stride(from:through:by:)
Example:
let tenToZero = Array(stride(from: 10, through: 0, by: -1))
I am using following code to insert points in the scatter chart:
series: [
{
name: 'Machine 1',color: '#0000FF',marker: {radius: 3, symbol: 'circle'},
data: [
{x: Date.UTC(2020,10,07,00,00,00), y: 0, prod_type: 'Production', number_of_cycles: '10',},
{x: Date.UTC(2020,10,07,00,01,00), y: 0, prod_type: 'Production', number_of_cycles: '11',}
]
},
{
name: 'Machine 2',color: '#00FF00',marker: {radius: 3, symbol: 'circle'},
data: [
{x: Date.UTC(2020,10,07,00,00,00), y: 1, prod_type: 'Setup', number_of_cycles: '1',},
{x: Date.UTC(2020,10,07,00,01,00), y: 1, prod_type: 'Setup', number_of_cycles: '2',}
]
}
]
This works but when I put a high number of points (more than 1,000) into one section data[], the chart shows nothing.
Thanks for your help
Jan
That is caused by the turboThreshold option:
turboThreshold: number
When a series contains a data array that is longer than this, only one
dimensional arrays of numbers, or two dimensional arrays with x and y
values are allowed. Also, only the first point is tested, and the rest
are assumed to be the same format. This saves expensive data checking
and indexing in long series. Set it to 0 disable.
Note: In boost mode turbo threshold is forced. Only array of numbers
or two dimensional arrays are allowed. Defaults to 1000.
You can map your data to a simpler format, like: [x, y] or change the value of turbo threshold.
API Reference: https://api.highcharts.com/highcharts/series.scatter.turboThreshold
I am writing an app that can get weight measurement from Xiaomi mi scale 2. After reading all available uuid's, only "181B" connection, specifically "2A9C" characteristic (Body weight measurement in bluetooth gatt) gets notifications.
Value data is [2, 164, 178, 7, 1, 1, 2, 58, 56, 253, 255, 240, 60]. Only last two values vary, the rest is time and date, witch is not set currently (253, 255 are zeroes when the weight varies on the scale until it stabilizes).
Can someone help me get only persons weight, should i be getting data maybe in a different way, from other uuid's (like custom ones: 00001530-0000-3512-2118-0009AF100700, 00001542-0000-3512-2118-0009AF100700), and how do i retrieve them.
Correct answer by Paulw11: You need to look at bit 0 of the first byte to determine if the weight is in imperial or SI; the bit is 0 so the data is SI. The to get the weight, convert the last two bytes to a 16 bit integer (60*256+240 = 15,600) and multiply by 0.005 = 78kg
In my case, it was a little different:
I got data like this [207, 0, 0, 178, 2, 0, 0, 0, 0, 0, 127] (6.9 KG) and the solution is:
let bytesArray = [207, 0, 0, 178, 2, 0, 0, 0, 0, 0, 127]
let weight = (( bytesArray[4] * 256 + bytesArray[3] ) * 10.0) / 1000
And now I have my 6.9 kg.
I was using Mi Smart scale and i had the following byte array.
02-A4-B2-07-02-13-06-33-35-FD-FF-EC-09" received - 12.7 KG
02-A4-B2-07-02-13-06-3B-17-FD-FF-C8-3C" - 77.8 KG
I used the last two bytes to get the weights in KG.
(09*256 + EC)/200 = 12.7
(3C*256+C8)/200 = 77.8
My byte array was 13 bytes long.
bytes 0 and 1: control bytes
bytes 2 and 3: year
byte 4: month
byte 5: day
byte 6: hours
byte 7: minutes
byte 8: seconds
bytes 9 and 10: impedance
bytes 11 and 12: weight (divide by 100 for pounds and catty, divide by 200 for kilograms)
Let say we can mark weekend day active or inactive. I need to use Integer to say system that I marked day active or inactive, to retrieve this integer I need to use array [1, 1, 1, 1, 1, 1, 1]. So if you see at this array all day of week marked as active and in Hexadecimal it's 0000007F.
If I use [0, 0, 0, 0, 0, 0, 1] this string it means Hexadecimal = 00000001. So my question is how to create Hexadecimal from array and then get form it an Integer. So in case with 0000007F it should be 127.
I assume that it should be something like that:
let array = [1, 1, 1, 1, 1, 1, 1]
let hexadecimal = array.toHexadecimal
let intNumber = hexadecimal.toInt
print(intNumber) // prints 127
Also I guess it can be for example an array with ints like [0, 1, 1, 1, 1, 0, 1] wich means that Monday and from Wednesday till Saturday (including) are active days.
You can use reduce method to sum up your binary array (inspired at this answer) and use String(radix:) initializer to convert your integer to hexa string:
Swift 3 • Xcode 8 or later
let binaryArray = [1, 1, 1, 1, 1, 1, 1]
let integerValue = binaryArray.reduce(0, {$0*2 + $1})
let hexaString = String(integerValue, radix: 16) // "7f"
I'm writing a game using Lua and Love2d but I've hit a snag when dealing with nested tables.
I have a function that runs through a table containing numbers corresponding to walls, buttons, etc. and prints colored blocks based on the keys. An example of one of these tables would look like this:
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1 }
{ 1, 0, 0, 0, 0, 0, 0, 0, 1 }
{ 1, 0, 1, 1, 2, 0, 0, 0, 1 }
{ 1, 0, 0, 0, 0, 0, 0, 0, 1 }
{ 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
This works fine when rendered. However when I attempt to create this same table using a function that reads this data from a text file looking like this:
111111111
100000001
101120001
100000001
111111111
It creates a table that seems identical but it simply doesn't work when I try to render it.
So I tried debugging using a bit of code that prints out table contents and though the contents are the same, the bit of hex describing the nested tables are different. Example:
Reading the first nested table of the map file:
1 table: 0x106c5a720
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
Reading the first nested table of the manually created table:
1 table: 0x106c64120
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
What's going on here? The values are all identical but something strange is happening.
edit: Here's the bit of code that renders the map for reference:
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
print("found a wall")
love.graphics.rectangle("fill", x * 30, y * 30, 30, 30)
elseif map[y][x] == 2 then
print("found a button")
love.graphics.setColor(255, 0, 0)
love.graphics.rectangle("fill", x * 30, y * 30, 30, 30)
love.graphics.setColor(0, 0, 255)
end
end
end
When reading data from a text file, you are getting strings.
In your original map table you have numbers.
Numbers are not equal to strings.
assert(1 ~= '1')