GithubHelp home page GithubHelp logo

How to use Huge Typed Array? about unreal.js HOT 12 CLOSED

mflux avatar mflux commented on May 19, 2024
How to use Huge Typed Array?

from unreal.js.

Comments (12)

mflux avatar mflux commented on May 19, 2024 1

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.

mflux avatar mflux commented on May 19, 2024

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.

nakosung avatar nakosung commented on May 19, 2024

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.

mflux avatar mflux commented on May 19, 2024

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.

nakosung avatar nakosung commented on May 19, 2024

No. Add project dependency in your game.Build.cs. And add #include "JavascriptContext.h" in your cpp. :)

from unreal.js.

nakosung avatar nakosung commented on May 19, 2024

https://github.com/nakosung/UnrealDarknet/blob/master/Source/darknet/darknet.Build.cs#L26

This is a working example.

from unreal.js.

mflux avatar mflux commented on May 19, 2024

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.

nakosung avatar nakosung commented on May 19, 2024

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.

mflux avatar mflux commented on May 19, 2024

Alright, will look into it, thanks!

from unreal.js.

mflux avatar mflux commented on May 19, 2024

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:

memory.exec(ab,_ => {

from unreal.js.

nakosung avatar nakosung commented on May 19, 2024

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.

mflux avatar mflux commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.