Comments (12)
I figured it out ๐
In Javascript
let fa = Float32Array.from( [ 10000, 99999, 123456, 30.2000, 3.1419 ]); // typed array
memory.exec(fa.buffer, function(){
GWorld.FastArrayCopy();
});
In C++
auto size = FArrayBufferAccessor::GetSize();
auto buffer = FArrayBufferAccessor::GetData();
float* conv = static_cast<float*>(buffer);
int length = size / 4;
UE_LOG(LogTemp, Log, TEXT("length of array %d"), length);
for (int i = 0; i < length; i++) {
float f = float( conv[i]);
UE_LOG(LogTemp, Log, TEXT("%f"), f);
}
from unreal.js.
Continuing from the above... I was able to get a BlueprintFunctionLibrary compiled, however FArrayBufferAccessor is not found.
According to some examples found in the Unreal.js plugin, it comes from one of these:
#include "JavascriptEditor.h"
#include "JavascriptEditorLibrary.h"
However the source for that is not accessible. Am I going about this the right way? Am I supposed to include the plugin source to have access to these functions?
from unreal.js.
Array buffer accessor is located at 'JavascriptContext.h`. (https://github.com/ncsoft/Unreal.js-core/blob/master/Source/V8/Public/JavascriptContext.h)
If you want to read back from huge typed array (which is passed from C++), there is a working example. (https://github.com/nakosung/UnrealDarknet/blob/master/Content/Scripts/yolo.js)
from unreal.js.
Thanks Nako
What's the proper way to include JavascriptContext.h? Should I include all the project files for the plugin into my game project/folder?
from unreal.js.
No. Add project dependency in your game.Build.cs. And add #include "JavascriptContext.h"
in your cpp. :)
from unreal.js.
https://github.com/nakosung/UnrealDarknet/blob/master/Source/darknet/darknet.Build.cs#L26
This is a working example.
from unreal.js.
Ah thanks! Add V8 instead of Unreal.js? How does Unreal's build system know where to look for this dependency? I currently have the V8 source in my Program Files/Epic/UE/4.1/plugin/UnrealJS/etc... folder. Does the path matter? Should it be inside my project folder instead?
from unreal.js.
If you build engine from source, plugin can be installed as an engine plugin. I'm not sure with packaged build from epic.
from unreal.js.
Alright, will look into it, thanks!
from unreal.js.
I got it mostly working. It looks like memory.bind is deprecated?
Warning: memory.bind is deprecated. use memory.exec(ab,fn) instead.
Should it be like this?
let ab = new ArrayBuffer(32*1024); // 32K bytes buffer
let u8 = new Uint8Array(ab); // typed array
memory.exec(ab, function(){
return [someArrayofData];
});
// BP-Library Function that uses memory
GWorld.FastArrayCopy();
I couldn't find any documentation of memory.exec.
The yolo.js example you linked https://github.com/nakosung/UnrealDarknet/blob/master/Content/Scripts/yolo.js made no use of memory.bind either.
Furthermore, the Hello.js example has this but it isn't clear to me how the memory value is being used afterwards:
from unreal.js.
Yes, unguarded operations are deprecated. :)
memory.exec(ab, function() {
// all operations which accesses array buffer should be guarded within this function.
GWorld.FastArrayCopy();
})
from unreal.js.
Haha. Yes, that seems much safer.
Are there examples of accessing the data inside a FArrayBufferAccessor? For example looping over it?
from unreal.js.
Related Issues (20)
- Actor.GetActorLocation() working in editor, not in packaged build HOT 1
- Unable to build for Android on UE5 (5.0.3) ๐ญ HOT 4
- What is this principle๏ผ HOT 1
- how to user GWorld.GetActorOfClass() HOT 3
- bp How to call unreal.js or override bp HOT 2
- After packing, Blueprint.Load is invalid HOT 6
- don't override blueprint method
- Not working in UE 5.1 HOT 10
- Make a proper documentation PLEASE! HOT 1
- Pass js vaiables to blueprint HOT 3
- [Question] Use this as ingame scripting? HOT 9
- UE5.03 Build for android "lv8_monolith" issue HOT 1
- Program crashes
- Not able to build with version 5.2 HOT 1
- Failed to package ue5.1 to linux. Procedure HOT 1
- Failed to package for windows
- Unreal 5.3 support HOT 10
- How to include npm packages? Ethers.js? HOT 1
- How to bind UMG Widget to JS? HOT 2
- How to Debug JavaScript with Rider ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unreal.js.