Compare commits
132 Commits
speckle-panel
..
box
| Author | SHA1 | Date | |
|---|---|---|---|
| 205c8dbf5a | |||
| 8159860223 | |||
| 2431b33726 | |||
| 8b70cbba64 | |||
| db2ba86e6d | |||
| 618d480acf | |||
| 26d5afc2c0 | |||
| dc0495dd24 | |||
| a75fb3a0c7 | |||
| 434c9a7b96 | |||
| aa400d19ee | |||
| 5f9eb61228 | |||
| 63bba7063c | |||
| b5076d5d7b | |||
| 2bacc0f1fb | |||
| da962e28f0 | |||
| 41a0d79229 | |||
| 980fe124b2 | |||
| 4b31169776 | |||
| f2a035c23c | |||
| 68f6aea6d7 | |||
| d6a7bdfb28 | |||
| 832df1ef65 | |||
| 0d97cc3e07 | |||
| 7671523547 | |||
| e109007a41 | |||
| e4b8f786f8 | |||
| 25c147aa7d | |||
| 31bf9bbb2b | |||
| 81c702959e | |||
| f45d89346d | |||
| 9b68685cd3 | |||
| d1c744b188 | |||
| 6f777a5f13 | |||
| a52de21d6f | |||
| b8d633d499 | |||
| 81206c63b3 | |||
| e18e622fa5 | |||
| f0c7550477 | |||
| f3a821ea95 | |||
| fd580cd2c5 | |||
| e528e2ba50 | |||
| ebb0fd83cb | |||
| 7d7d605bd2 | |||
| aa8d17268e | |||
| dca71560fe | |||
| 52bcad5911 | |||
| 6af2765508 | |||
| 2827595511 | |||
| d6730b01fc | |||
| 7601863e3c | |||
| 89b6b2bdfc | |||
| c598aa787b | |||
| 4a451fec3b | |||
| 1ff924eea4 | |||
| 303eb7fb6a | |||
| 9ce2117a0a | |||
| 2ac94215ee | |||
| 2dac706ca5 | |||
| af950a569e | |||
| 6e900af1fa | |||
| 66741730e0 | |||
| a595b773ba | |||
| da1989d676 | |||
| a89655f7e0 | |||
| a1c53ff063 | |||
| edafa74bac | |||
| 8ca9f46c8a | |||
| f3d100bbcb | |||
| bbe0a8eead | |||
| cfead600a9 | |||
| 5a1c145cf2 | |||
| c34f39d44c | |||
| 9982d55cfb | |||
| 2f2bbd06e6 | |||
| bdbe31b429 | |||
| 7a96022ad3 | |||
| 67b0a961a5 | |||
| 99d7a42c89 | |||
| 70b092050d | |||
| e4994a2612 | |||
| 9c87d944ea | |||
| 801b91b33f | |||
| 051fbd589f | |||
| 20a93d1c10 | |||
| 877b9b7ecb | |||
| 02929d6904 | |||
| 26706c6cbd | |||
| 746dadcc71 | |||
| fa3eec6f10 | |||
| ad6cb36915 | |||
| c5ce7d37a5 | |||
| 611470db41 | |||
| ce9980e408 | |||
| 5f7a6573aa | |||
| a1843dfb50 | |||
| 1f2b77c41c | |||
| 39ef6a70cf | |||
| 5212528156 | |||
| 510ddd1c01 | |||
| 8119083cab | |||
| 307993e648 | |||
| 8230ec2540 | |||
| 0d38a533cc | |||
| f2fdf86e62 | |||
| 4c62bc3005 | |||
| 5d9bfaa19f | |||
| cebdca009c | |||
| 7549927e67 | |||
| 80293fe975 | |||
| 2ba59cbfcc | |||
| 9ed3d1713a | |||
| 76444ced3c | |||
| 8d07def00f | |||
| 3efc7a4c49 | |||
| 267fafb5a4 | |||
| 8b15e39ff7 | |||
| 75f4575813 | |||
| 5e491c622f | |||
| fdcc06c025 | |||
| 7ff7d66c5a | |||
| fbdcf6a419 | |||
| adc64ac2b5 | |||
| dbc36e5553 | |||
| d1114770f7 | |||
| 438a5990b1 | |||
| 5a70dda7bf | |||
| 51fcef121e | |||
| dde7f0d08c | |||
| a73414f22e | |||
| 7e98e1aa28 | |||
| c1924dce25 |
@@ -0,0 +1,78 @@
|
||||
name: Update issue Status
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [closed]
|
||||
|
||||
jobs:
|
||||
update_issue:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get project data
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
|
||||
ORGANIZATION: specklesystems
|
||||
PROJECT_NUMBER: 9
|
||||
run: |
|
||||
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
|
||||
query($org: String!, $number: Int!) {
|
||||
organization(login: $org){
|
||||
projectNext(number: $number) {
|
||||
id
|
||||
fields(first:20) {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
settings
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
|
||||
|
||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
||||
|
||||
echo "$PROJECT_ID"
|
||||
echo "$STATUS_FIELD_ID"
|
||||
|
||||
echo 'DONE_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .settings | fromjson | .options[] | select(.name== "Done") | .id' project_data.json) >> $GITHUB_ENV
|
||||
echo "$DONE_ID"
|
||||
|
||||
- name: Add Issue to project #it's already in the project, but we do this to get its node id!
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
|
||||
ISSUE_ID: ${{ github.event.issue.node_id }}
|
||||
run: |
|
||||
item_id="$( gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
|
||||
mutation($project:ID!, $id:ID!) {
|
||||
addProjectNextItem(input: {projectId: $project, contentId: $id}) {
|
||||
projectNextItem {
|
||||
id
|
||||
}
|
||||
}
|
||||
}' -f project=$PROJECT_ID -f id=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
||||
|
||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
||||
|
||||
- name: Update Status
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
|
||||
ISSUE_ID: ${{ github.event.issue.node_id }}
|
||||
run: |
|
||||
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
|
||||
mutation($project:ID!, $status:ID!, $id:ID!, $value:String!) {
|
||||
set_status: updateProjectNextItemField(
|
||||
input: {
|
||||
projectId: $project
|
||||
itemId: $id
|
||||
fieldId: $status
|
||||
value: $value
|
||||
}
|
||||
) {
|
||||
projectNextItem {
|
||||
id
|
||||
}
|
||||
}
|
||||
}' -f project=$PROJECT_ID -f status=$STATUS_FIELD_ID -f id=$ITEM_ID -f value=${{ env.DONE_ID }}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
name: Move new issues into Project
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
track_issue:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get project data
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
|
||||
ORGANIZATION: specklesystems
|
||||
PROJECT_NUMBER: 9
|
||||
run: |
|
||||
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
|
||||
query($org: String!, $number: Int!) {
|
||||
organization(login: $org){
|
||||
projectNext(number: $number) {
|
||||
id
|
||||
fields(first:20) {
|
||||
nodes {
|
||||
id
|
||||
name
|
||||
settings
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
|
||||
|
||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
||||
|
||||
- name: Add Issue to project
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GHPROJECT_TOKEN}}
|
||||
ISSUE_ID: ${{ github.event.issue.node_id }}
|
||||
run: |
|
||||
item_id="$( gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
|
||||
mutation($project:ID!, $id:ID!) {
|
||||
addProjectNextItem(input: {projectId: $project, contentId: $id}) {
|
||||
projectNextItem {
|
||||
id
|
||||
}
|
||||
}
|
||||
}' -f project=$PROJECT_ID -f id=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
||||
|
||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
||||
+5
-13
@@ -1,9 +1,6 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
.idea/
|
||||
.vs/
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
@@ -35,14 +32,9 @@
|
||||
*.app
|
||||
*.umap
|
||||
|
||||
# UE file types
|
||||
*.uasset filter=lfs diff=lfs merge=lfs -text
|
||||
*.umap filter=lfs diff=lfs merge=lfs -text
|
||||
Binaries/
|
||||
Intermediate/
|
||||
Saved/
|
||||
|
||||
SpeckleUnrealProject/Binaries/
|
||||
SpeckleUnrealProject/Intermediate/
|
||||
SpeckleUnrealProject/Plugins/SpeckleUnreal/Binaries/
|
||||
SpeckleUnrealProject/Plugins/SpeckleUnreal/Intermediate/
|
||||
SpeckleUnrealProject/Saved/
|
||||
SpeckleUnrealProject/.vs/
|
||||
SpeckleUnrealProject/SpeckleUnrealProject.sln.DotSettings.user
|
||||
.idea/
|
||||
.vs/
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
|
||||
[](https://twitter.com/SpeckleSystems) [](https://speckle.community) [](https://speckle.systems) [](https://speckle.guide/dev/)
|
||||
|
||||
Plugin for Unreal Engine 4 to import objects from Speckle v2.
|
||||
Plugin for Unreal Engine to import objects from Speckle v2.
|
||||
|
||||
|
||||
Screencast of an example: https://user-images.githubusercontent.com/2551138/114720093-61403e00-9d40-11eb-8045-6e8ca656554d.mp4
|
||||
@@ -12,20 +12,21 @@ Screencast of an example: https://user-images.githubusercontent.com/2551138/1147
|
||||
|
||||
## NOTICE
|
||||
|
||||
* Tested on Windows, Unreal Engine v4.26 and Visual Studio Community 2019
|
||||
* Only displays meshes. Breps are converted using their display values.
|
||||
* Our Unreal Connector is in an beta stage of development. Currently we only support receiving objects, and there is no UI to fetch lists of streams/commits/branches.
|
||||
* We officially support Unreal Engine 4.26 and 4.27, and have experimental support for UE5.
|
||||
* Does not use the Speckle Kit workflow as conversions all happen in C++.
|
||||
|
||||
## How To Install
|
||||
|
||||
|
||||
1. Clone the repository or download it as a zip file.
|
||||
2. Navigate to `SpeckleUnrealProject` > `Plugins` and copy the `SpeckleUnreal` folder
|
||||
3. Paste the folder into your Unreal project under `YourUnrealProjectFolder` > `Plugins` (Create a `Plugins` folder if you don't already have one).
|
||||
4. Reopen your project.
|
||||
1. Download `speckle-unreal` repository archive from https://github.com/specklesystems/speckle-unreal/archive/refs/heads/main.zip
|
||||
1. Extract the downloaded archive into your project's `Plugins` directory (if your project directory doesn't contain a directory called Plugins, you should create it)
|
||||
1. Open your UE project (or restart the editor if you already have it opened). This will build the plugin in your environment.
|
||||
|
||||
We will eventually look to distributing the plugin officially on the Unreal Engine Marketplace but for now you'll need to install the plugin manually like this.
|
||||
|
||||
See our [docs](https://speckle.guide/user/unreal.html) for usage instructions.
|
||||
|
||||
## Credits
|
||||
Based off the original Unreal integration for Speckle v1 by Mark and Jak which can be found here: [https://github.com/mobiusnode/SpeckleUnreal](https://github.com/mobiusnode/SpeckleUnreal).
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,364 @@
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "Mixpanel.h"
|
||||
#include "Objects/HighLevel/SpeckleBranch.h"
|
||||
#include "Objects/HighLevel/SpeckleCommit.h"
|
||||
#include "Objects/HighLevel/SpeckleGlobals.h"
|
||||
#include "Objects/HighLevel/SpeckleUser.h"
|
||||
#include "Transports/Transport.h"
|
||||
|
||||
|
||||
void FClientAPI::StreamsGet(const FString& ServerUrl, const FString& AuthToken,
|
||||
const int Limit,
|
||||
const FFetchStreamDelegate OnCompleteAction, const FErrorDelegate OnErrorAction)
|
||||
{
|
||||
const FString RequestLogName = FString(__FUNCTION__);
|
||||
|
||||
const FString PostPayload =
|
||||
"{\"query\": \"query{user {streams(limit:" + FString::FromInt(Limit) + ") {totalCount items {id name description updatedAt createdAt isPublic role collaborators{id name role company avatar}}}}}\"}";
|
||||
|
||||
auto OnError = [=](const FString& Message) mutable
|
||||
{
|
||||
ensureAlwaysMsgf(OnErrorAction.ExecuteIfBound(Message), TEXT("%s: Unhandled error - %s"), *RequestLogName , *Message);
|
||||
};
|
||||
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(CheckRequestFailed(bWasSuccessful, Response, RequestLogName, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!GetResponseAsJSON(Response, RequestLogName, Obj, OnError)) return;
|
||||
|
||||
TArray<TSharedPtr<FJsonValue>> StreamsArrJSON = Obj->GetObjectField(TEXT("data"))
|
||||
->GetObjectField(TEXT("user"))
|
||||
->GetObjectField(TEXT("streams"))
|
||||
->GetArrayField(TEXT("items"));
|
||||
|
||||
TArray<FSpeckleStream> Streams;
|
||||
Streams.Reserve(StreamsArrJSON.Num());
|
||||
|
||||
for (const TSharedPtr<FJsonValue> v : StreamsArrJSON)
|
||||
{
|
||||
FSpeckleStream Stream = FSpeckleStream(v);
|
||||
Streams.Add(Stream);
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s completed successfully. Fetched %d items"), *RequestLogName, Streams.Num());
|
||||
ensureAlwaysMsgf(OnCompleteAction.ExecuteIfBound(Streams), TEXT("%s: Complete handler was not bound properly"), *RequestLogName);
|
||||
};
|
||||
|
||||
|
||||
const FHttpRequestRef Request = CreateGraphQLRequest(ServerUrl, AuthToken, PostPayload);
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
SendGraphQLRequest(Request, RequestLogName, OnError);
|
||||
}
|
||||
|
||||
void FClientAPI::StreamGetBranches(
|
||||
const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const int32 Limit,
|
||||
const FFetchBranchDelegate OnCompleteAction, const FErrorDelegate OnErrorAction)
|
||||
{
|
||||
const FString RequestLogName = FString(__FUNCTION__);
|
||||
|
||||
//TODO limit
|
||||
FString PostPayload = "{\"query\": \"query{ stream (id: \\\"" +
|
||||
StreamId + "\\\"){id name branches(limit : " + FString::FromInt(Limit) + ") {totalCount cursor items{ id name description}}}}\"}";
|
||||
|
||||
// The above can be extended with author information
|
||||
//query{stream(id:"a18f8c8569"){id name branches{totalCount items{id name description author{id, name, email, commits{cursor}}}}}}
|
||||
|
||||
auto OnError = [=](const FString& Message) mutable
|
||||
{
|
||||
ensureAlwaysMsgf(OnErrorAction.ExecuteIfBound(Message), TEXT("%s: Unhandled error - %s"), *RequestLogName , *Message);
|
||||
};
|
||||
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(CheckRequestFailed(bWasSuccessful, Response, RequestLogName, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!GetResponseAsJSON(Response, RequestLogName, Obj, OnError)) return;
|
||||
|
||||
TArray<TSharedPtr<FJsonValue>> BranchesArrJSON = Obj->GetObjectField(TEXT("data"))
|
||||
->GetObjectField(TEXT("stream"))
|
||||
->GetObjectField(TEXT("branches"))
|
||||
->GetArrayField(TEXT("items"));
|
||||
TArray<FSpeckleBranch> Branches;
|
||||
Branches.Reserve(BranchesArrJSON.Num());
|
||||
|
||||
for (const TSharedPtr<FJsonValue>& v : BranchesArrJSON)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* BranchObj;
|
||||
if(ensureAlways(v->TryGetObject(BranchObj)))
|
||||
{
|
||||
FSpeckleBranch Branch = FSpeckleBranch(*BranchObj);
|
||||
Branches.Add(Branch);
|
||||
}
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s completed successfully. Fetched %d items"), *RequestLogName, Branches.Num());
|
||||
ensureAlwaysMsgf(OnCompleteAction.ExecuteIfBound(Branches), TEXT("%s: Complete handler was not bound properly"), *RequestLogName);
|
||||
};
|
||||
|
||||
|
||||
const FHttpRequestRef Request = CreateGraphQLRequest(ServerUrl, AuthToken, PostPayload);
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
SendGraphQLRequest(Request, RequestLogName, OnError);
|
||||
}
|
||||
|
||||
|
||||
void FClientAPI::StreamGetCommits(const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const FString& BranchName, const int32 Limit,
|
||||
const FFetchCommitDelegate OnCompleteAction, const FErrorDelegate OnErrorAction)
|
||||
{
|
||||
const FString RequestLogName = FString(__FUNCTION__);
|
||||
|
||||
FString PostPayload = "{\"query\": \"query{stream (id: \\\"" + StreamId +
|
||||
"\\\"){id name createdAt updatedAt "
|
||||
+ "branch(name: \\\"" + BranchName + "\\\" ){id name description author{name id email} " +
|
||||
"commits(limit: " + FString::FromInt(Limit) + "){totalCount items {id referencedObject sourceApplication totalChildrenCount " +
|
||||
"branchName parents authorName authorId message createdAt commentCount}}}}}\"}"; // authorAvatar
|
||||
|
||||
auto OnError = [=](const FString& Message) mutable
|
||||
{
|
||||
ensureAlwaysMsgf(OnErrorAction.ExecuteIfBound(Message), TEXT("%s: Unhandled error - %s"), *RequestLogName , *Message);
|
||||
};
|
||||
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(CheckRequestFailed(bWasSuccessful, Response, RequestLogName, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!GetResponseAsJSON(Response, RequestLogName, Obj, OnError)) return;
|
||||
|
||||
TArray<TSharedPtr<FJsonValue>> CommitsArrJSON = Obj->GetObjectField(TEXT("data"))
|
||||
->GetObjectField(TEXT("stream"))
|
||||
->GetObjectField(TEXT("branch"))
|
||||
->GetObjectField(TEXT("commits"))
|
||||
->GetArrayField(TEXT("items"));
|
||||
|
||||
TArray<FSpeckleCommit> ArrayOfCommits;
|
||||
ArrayOfCommits.Reserve(CommitsArrJSON.Num());
|
||||
|
||||
for (const TSharedPtr<FJsonValue> v : CommitsArrJSON)
|
||||
{
|
||||
FSpeckleCommit Commit = FSpeckleCommit(v);
|
||||
ArrayOfCommits.Add( Commit );
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s completed successfully. Fetched %d items"), *RequestLogName, ArrayOfCommits.Num());
|
||||
ensureAlwaysMsgf(OnCompleteAction.ExecuteIfBound(ArrayOfCommits), TEXT("%s: Complete handler was not bound properly"), *RequestLogName);
|
||||
};
|
||||
|
||||
|
||||
const FHttpRequestRef Request = CreateGraphQLRequest(ServerUrl, AuthToken, PostPayload);
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
SendGraphQLRequest(Request, RequestLogName, OnError);
|
||||
}
|
||||
|
||||
|
||||
void FClientAPI::FetchGlobals(const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const FString& ReferencedObjectId,
|
||||
const FFetchGlobalsDelegate OnCompleteAction, const FErrorDelegate OnErrorAction)
|
||||
{
|
||||
const FString RequestLogName = FString(__FUNCTION__);
|
||||
|
||||
FString PostPayload = "{\"query\": \"query{stream (id:\\\"" + StreamId +
|
||||
"\\\"){id name description updatedAt createdAt role isPublic object(id:\\\"" +
|
||||
ReferencedObjectId +
|
||||
"\\\"){id data}}}\"}";
|
||||
|
||||
auto OnError = [=](const FString& Message) mutable
|
||||
{
|
||||
ensureAlwaysMsgf(OnErrorAction.ExecuteIfBound(Message), TEXT("%s: Unhandled error - %s"), *RequestLogName , *Message);
|
||||
};
|
||||
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(CheckRequestFailed(bWasSuccessful, Response, RequestLogName, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!GetResponseAsJSON(Response, RequestLogName, Obj, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> GlobalsJSONObject = Obj->GetObjectField(TEXT("data"))
|
||||
->GetObjectField(TEXT("stream"))
|
||||
->GetObjectField(TEXT("object"))
|
||||
->GetObjectField(TEXT("data"));
|
||||
|
||||
|
||||
|
||||
|
||||
FSpeckleGlobals Globals = FSpeckleGlobals(GlobalsJSONObject);
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s completed successfully"), *RequestLogName);
|
||||
ensureAlwaysMsgf(OnCompleteAction.ExecuteIfBound(Globals), TEXT("%s: Complete handler was not bound properly"), *RequestLogName);
|
||||
};
|
||||
|
||||
|
||||
const FHttpRequestRef Request = CreateGraphQLRequest(ServerUrl, AuthToken, PostPayload);
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
SendGraphQLRequest(Request, RequestLogName, OnError);
|
||||
}
|
||||
|
||||
void FClientAPI::FetchUserData(const FString& ServerUrl, const FString& AuthToken,
|
||||
const FFetchUserDelegate OnCompleteAction, const FErrorDelegate OnErrorAction)
|
||||
{
|
||||
const FString RequestLogName = FString(__FUNCTION__);
|
||||
|
||||
const FString PostPayload =
|
||||
"{\"query\": \"query{user{id name email company role suuid bio profiles avatar}}\"}";
|
||||
|
||||
|
||||
auto OnError = [=](const FString& Message) mutable
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s: failed - %s"), *RequestLogName , *Message);
|
||||
ensureAlwaysMsgf(OnErrorAction.ExecuteIfBound(Message), TEXT("%s: Unhandled error - %s"), *RequestLogName , *Message);
|
||||
};
|
||||
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(CheckRequestFailed(bWasSuccessful, Response, RequestLogName, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!GetResponseAsJSON(Response, RequestLogName, Obj, OnError)) return;
|
||||
|
||||
TSharedPtr<FJsonObject> UserJSONObject = Obj->GetObjectField(TEXT("data"))
|
||||
->GetObjectField(TEXT("user"));
|
||||
|
||||
FSpeckleUser MyUserData = FSpeckleUser( UserJSONObject );
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s completed successfully"), *RequestLogName);
|
||||
ensureAlwaysMsgf(OnCompleteAction.ExecuteIfBound(MyUserData), TEXT("%s: Complete handler was not bound properly"), *RequestLogName);
|
||||
};
|
||||
|
||||
const FHttpRequestRef Request = CreateGraphQLRequest(ServerUrl, AuthToken, PostPayload);
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
SendGraphQLRequest(Request, RequestLogName, OnError);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FClientAPI::GetResponseAsJSON(const FHttpResponsePtr Response, const FString& RequestLogName, TSharedPtr<FJsonObject>& OutObject, const TFunctionRef<void(const FString& Message)> OnErrorAction)
|
||||
{
|
||||
|
||||
const FString JsonResponse = Response->GetContentAsString();
|
||||
|
||||
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonResponse);
|
||||
|
||||
if(!FJsonSerializer::Deserialize(Reader, OutObject))
|
||||
{
|
||||
const FString Message = FString::Printf(
|
||||
TEXT("Recieved a response from \"%s\" for \"%s\" request, but the response failed to deserialize: %s"),
|
||||
*Response->GetURL(), *RequestLogName, *JsonResponse);
|
||||
OnErrorAction(Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
FString Error;
|
||||
if(CheckForOperationErrors(OutObject, Error))
|
||||
{
|
||||
OnErrorAction(Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FHttpRequestRef FClientAPI::CreateGraphQLRequest(const FString& ServerUrl, const FString AuthToken, const FString& PostPayload, const FString& Encoding)
|
||||
{
|
||||
FHttpRequestRef Request = FHttpModule::Get().CreateRequest();
|
||||
|
||||
Request->SetURL(ServerUrl + "/graphql");
|
||||
Request->SetVerb(TEXT("POST"));
|
||||
Request->SetHeader("Accept-Encoding", Encoding);
|
||||
Request->SetHeader("Content-Type", TEXT("application/json"));
|
||||
Request->SetHeader("Authorization", "Bearer " + AuthToken);
|
||||
Request->SetContentAsString(PostPayload);
|
||||
|
||||
return Request;
|
||||
}
|
||||
|
||||
bool FClientAPI::SendGraphQLRequest(const FHttpRequestRef Request, const FString& RequestName,
|
||||
const TFunctionRef<void(const FString& Message)> OnErrorAction)
|
||||
{
|
||||
const bool RequestSent = Request->ProcessRequest();
|
||||
|
||||
if(!RequestSent)
|
||||
{
|
||||
const FString Message = FString::Printf(TEXT("Request \"%s\" at \"%s\" failed: \nHTTP request failed to start"),
|
||||
*RequestName, *Request->GetURL());
|
||||
|
||||
OnErrorAction(Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogSpeckle, Log, TEXT("POST Request %s to %s was sent, awaiting response"), *RequestName, *Request->GetURL() );
|
||||
FAnalytics::TrackEvent("unknown", Request->GetURL(), "NodeRun", TMap<FString, FString> { {"name", RequestName }});
|
||||
}
|
||||
|
||||
return RequestSent;
|
||||
}
|
||||
|
||||
|
||||
bool FClientAPI::CheckRequestFailed(bool bWasSuccessful, FHttpResponsePtr Response, const FString& RequestLogName, const TFunctionRef<void(const FString& Message)> OnErrorAction)
|
||||
{
|
||||
//Check the request was sent
|
||||
if(!bWasSuccessful)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request \"%s\" to \"%s\" was unsuccessful: %s"),
|
||||
*RequestLogName, *Response->GetURL(), *Response->GetContentAsString());
|
||||
OnErrorAction(Message);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check Response code
|
||||
const int32 ResponseCode = Response->GetResponseCode();
|
||||
if (ResponseCode != 200)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request \"%s\" to \"%s\" failed with HTTP response %d"),
|
||||
*RequestLogName, *Response->GetURL(), ResponseCode);
|
||||
OnErrorAction(Message);
|
||||
return true;
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Operation %s recieved a response from %s"), *RequestLogName, *Response->GetURL());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FClientAPI::CheckForOperationErrors(const TSharedPtr<FJsonObject> GraphQLResponse, FString& OutErrorMessage)
|
||||
{
|
||||
check(GraphQLResponse != nullptr);
|
||||
|
||||
bool WasError = false;
|
||||
const TArray<TSharedPtr<FJsonValue>>* Errors;
|
||||
if(GraphQLResponse->TryGetArrayField(TEXT("Errors"), Errors))
|
||||
{
|
||||
for(const TSharedPtr<FJsonValue>& e : *Errors)
|
||||
{
|
||||
FString Message;
|
||||
const TSharedPtr<FJsonObject>* ErrorObject;
|
||||
bool HadMessage = e->TryGetObject(ErrorObject)
|
||||
&& (*ErrorObject)->TryGetStringField("message", Message);
|
||||
if(!HadMessage)
|
||||
{
|
||||
Message = "An operation error occured but had no message!\n";
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s"), *Message);
|
||||
}
|
||||
|
||||
OutErrorMessage.Append(Message + "\n");
|
||||
WasError = true;
|
||||
}
|
||||
}
|
||||
return WasError;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveBranchesOperation.h"
|
||||
|
||||
#include "Mixpanel.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
|
||||
UReceiveBranchesOperation* UReceiveBranchesOperation::ReceiveBranchesOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, int32 Limit)
|
||||
{
|
||||
FString ObjectId = "Streams";
|
||||
|
||||
UReceiveBranchesOperation* Node = NewObject<UReceiveBranchesOperation>();
|
||||
Node->StreamId = StreamId.TrimEnd();
|
||||
Node->ServerUrl = ServerUrl.TrimEnd();
|
||||
while(Node->ServerUrl.RemoveFromEnd("/")) { }
|
||||
Node->AuthToken = AuthToken.TrimEnd();
|
||||
Node->Limit = Limit;
|
||||
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
void UReceiveBranchesOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown",
|
||||
ServerUrl, "NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
Request();
|
||||
}
|
||||
|
||||
void UReceiveBranchesOperation::Request()
|
||||
{
|
||||
ensureAlways(Limit > 0);
|
||||
|
||||
FFetchBranchDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveBranchesOperation::HandleReceive);
|
||||
|
||||
FErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveBranchesOperation::HandleError);
|
||||
|
||||
FClientAPI::StreamGetBranches(ServerUrl, AuthToken, StreamId, Limit, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
void UReceiveBranchesOperation::HandleReceive(const TArray<FSpeckleBranch>& Branches)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s to %s Succeeded"), *StaticClass()->GetName(), *ServerUrl);
|
||||
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
OnReceiveSuccessfully.Broadcast(Branches, "");
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveBranchesOperation::HandleError(const FString& Message)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s failed - %s"), *StaticClass()->GetName(), *Message);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
|
||||
const TArray<FSpeckleBranch> EmptyList;
|
||||
OnError.Broadcast(EmptyList, Message);
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveCommitsOperation.h"
|
||||
|
||||
#include "Mixpanel.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
|
||||
// ReceiveOperation
|
||||
UReceiveCommitsOperation* UReceiveCommitsOperation::ReceiveCommitsOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const FString& BranchName, const int32 Limit)
|
||||
{
|
||||
UReceiveCommitsOperation* Node = NewObject<UReceiveCommitsOperation>();
|
||||
Node->ServerUrl = ServerUrl.TrimEnd();
|
||||
while(Node->ServerUrl.RemoveFromEnd("/")) { }
|
||||
Node->AuthToken = AuthToken.TrimEnd();
|
||||
Node->StreamId = StreamId.TrimEnd();
|
||||
Node->BranchName = BranchName;
|
||||
Node->Limit = Limit;
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
// Activate
|
||||
void UReceiveCommitsOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown", ServerUrl,
|
||||
"NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
Request();
|
||||
}
|
||||
|
||||
void UReceiveCommitsOperation::Request()
|
||||
{
|
||||
ensureAlways(Limit > 0);
|
||||
|
||||
FFetchCommitDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveCommitsOperation::HandleReceive);
|
||||
|
||||
FErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveCommitsOperation::HandleError);
|
||||
|
||||
FClientAPI::StreamGetCommits(ServerUrl, AuthToken, StreamId, BranchName, Limit, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
void UReceiveCommitsOperation::HandleReceive(const TArray<FSpeckleCommit>& Commits)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s to %s Succeeded"), *StaticClass()->GetName(), *ServerUrl);
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
|
||||
OnReceiveSuccessfully.Broadcast(Commits, "");
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveCommitsOperation::HandleError(const FString& Message)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s failed - %s"), *StaticClass()->GetName(), *Message);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
|
||||
const TArray<FSpeckleCommit> EmptyList;
|
||||
OnError.Broadcast(EmptyList, Message);
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveGlobalsOperation.h"
|
||||
|
||||
#include "Mixpanel.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
|
||||
UReceiveGlobalsOperation* UReceiveGlobalsOperation::ReceiveGlobalsOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const FString& ReferencedObjectId)
|
||||
{
|
||||
UReceiveGlobalsOperation* Node = NewObject<UReceiveGlobalsOperation>();
|
||||
Node->ServerUrl = ServerUrl.TrimEnd();
|
||||
while(Node->ServerUrl.RemoveFromEnd("/")) { }
|
||||
Node->AuthToken = AuthToken.TrimEnd();;
|
||||
Node->StreamId = StreamId.TrimEnd();;
|
||||
Node->ReferencedObjectId = ReferencedObjectId;
|
||||
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
void UReceiveGlobalsOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown",
|
||||
ServerUrl, "NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
Request();
|
||||
}
|
||||
|
||||
void UReceiveGlobalsOperation::Request()
|
||||
{
|
||||
FFetchGlobalsDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveGlobalsOperation::HandleReceive);
|
||||
|
||||
FErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveGlobalsOperation::HandleError);
|
||||
|
||||
FClientAPI::FetchGlobals(ServerUrl, AuthToken, StreamId, ReferencedObjectId, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UReceiveGlobalsOperation::HandleReceive(const FSpeckleGlobals& Object)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s to %s Succeeded"), *StaticClass()->GetName(), *ServerUrl);
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
OnReceiveSuccessfully.Broadcast(Object, "");
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveGlobalsOperation::HandleError(const FString& Message)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s failed - %s"), *StaticClass()->GetName(), *Message);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
const FSpeckleGlobals BlankGlobals;
|
||||
OnError.Broadcast(BlankGlobals, Message);
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveMyUserDataOperation.h"
|
||||
|
||||
#include "Mixpanel.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
|
||||
UReceiveMyUserDataOperation* UReceiveMyUserDataOperation::ReceiveMyUserDataOperation(
|
||||
UObject* WorldContextObject, const FString& ServerUrl, const FString& AuthToken)
|
||||
{
|
||||
UReceiveMyUserDataOperation* Node = NewObject<UReceiveMyUserDataOperation>();
|
||||
Node->ServerUrl = ServerUrl.TrimEnd();;
|
||||
while(Node->ServerUrl.RemoveFromEnd("/")) { }
|
||||
Node->AuthToken = AuthToken.TrimEnd();;
|
||||
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
void UReceiveMyUserDataOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown",
|
||||
ServerUrl, "NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
Request();
|
||||
}
|
||||
|
||||
|
||||
void UReceiveMyUserDataOperation::Request()
|
||||
{
|
||||
FFetchUserDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveMyUserDataOperation::HandleReceive);
|
||||
|
||||
FErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveMyUserDataOperation::HandleError);
|
||||
|
||||
FClientAPI::FetchUserData(ServerUrl, AuthToken, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UReceiveMyUserDataOperation::HandleReceive(const FSpeckleUser& Object)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s to %s Succeeded"), *StaticClass()->GetName(), *ServerUrl);
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
OnReceiveSuccessfully.Broadcast(Object, "");
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveMyUserDataOperation::HandleError(const FString& Message)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s failed - %s"), *StaticClass()->GetName(), *Message);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
const FSpeckleUser BlankUser;
|
||||
OnError.Broadcast(BlankUser, Message);
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveOperation.h"
|
||||
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Transports/Transport.h"
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Mixpanel.h"
|
||||
|
||||
|
||||
// ReceiveOperation
|
||||
UReceiveOperation* UReceiveOperation::ReceiveOperation(UObject* WorldContextObject,
|
||||
const FString& ObjectId,
|
||||
TScriptInterface<ITransport> RemoteTransport,
|
||||
TScriptInterface<ITransport> LocalTransport)
|
||||
{
|
||||
UReceiveOperation* Node = NewObject<UReceiveOperation>();
|
||||
Node->ObjectId = ObjectId;
|
||||
Node->RemoteTransport = RemoteTransport;
|
||||
Node->LocalTransport = LocalTransport;
|
||||
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
// Activate
|
||||
void UReceiveOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown",
|
||||
"unknown", "NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
//Async(EAsyncExecution::Thread, [this]{Receive();});
|
||||
Receive();
|
||||
}
|
||||
|
||||
void UReceiveOperation::Receive()
|
||||
{
|
||||
check(LocalTransport != nullptr);
|
||||
|
||||
// 1. Try and get object from local transport
|
||||
auto Obj = LocalTransport->GetSpeckleObject(ObjectId);
|
||||
|
||||
if (Obj != nullptr )
|
||||
{
|
||||
HandleReceive(Obj);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Try and get object from remote transport
|
||||
if(RemoteTransport == nullptr)
|
||||
{
|
||||
FString ErrorMessage = TEXT(
|
||||
"Could not find specified object using the local transport, and you didn't provide a fallback remote from which to pull it.");
|
||||
|
||||
HandleError(ErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
FTransportCopyObjectCompleteDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveOperation::HandleReceive);
|
||||
|
||||
FTransportErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveOperation::HandleError);
|
||||
|
||||
RemoteTransport->CopyObjectAndChildren(ObjectId, LocalTransport, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
void UReceiveOperation::HandleReceive(TSharedPtr<FJsonObject> Object)
|
||||
{
|
||||
check(IsInGameThread())
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
if(Object == nullptr)
|
||||
{
|
||||
OnError.Broadcast(nullptr, FString::Printf(TEXT("Failed to get object %s from transport"), *ObjectId));
|
||||
}
|
||||
else
|
||||
{
|
||||
UBase* Res = USpeckleSerializer::DeserializeBase(Object, LocalTransport);
|
||||
if(IsValid(Res))
|
||||
OnReceiveSuccessfully.Broadcast(Res, "");
|
||||
else
|
||||
OnError.Broadcast(nullptr, FString::Printf(TEXT("Root Speckle Object %s failed to deserialize"), *ObjectId));
|
||||
}
|
||||
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveOperation::HandleError(FString& Message)
|
||||
{
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
OnError.Broadcast(nullptr, Message);
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "API/Operations/ReceiveStreamsOperation.h"
|
||||
|
||||
#include "Mixpanel.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/ClientAPI.h"
|
||||
|
||||
|
||||
UReceiveStreamsOperation* UReceiveStreamsOperation::ReceiveStreamsOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const int32 Limit)
|
||||
{
|
||||
FString ObjectId = "Streams";
|
||||
|
||||
UReceiveStreamsOperation* Node = NewObject<UReceiveStreamsOperation>();
|
||||
Node->ServerUrl = ServerUrl.TrimEnd();;
|
||||
Node->AuthToken = AuthToken.TrimEnd();;
|
||||
Node->Limit = Limit;
|
||||
|
||||
Node->RegisterWithGameInstance(WorldContextObject);
|
||||
return Node;
|
||||
}
|
||||
|
||||
void UReceiveStreamsOperation::Activate()
|
||||
{
|
||||
FAnalytics::TrackEvent("unknown",
|
||||
ServerUrl, "NodeRun", TMap<FString, FString> { {"name", StaticClass()->GetName() }});
|
||||
|
||||
Request();
|
||||
}
|
||||
|
||||
void UReceiveStreamsOperation::Request()
|
||||
{
|
||||
FFetchStreamDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &UReceiveStreamsOperation::HandleReceive);
|
||||
|
||||
FErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &UReceiveStreamsOperation::HandleError);
|
||||
|
||||
FClientAPI::StreamsGet(ServerUrl, AuthToken, Limit, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
void UReceiveStreamsOperation::HandleReceive(const TArray<FSpeckleStream>& Streams)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s to %s Succeeded"), *StaticClass()->GetName(), *ServerUrl);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
OnReceiveSuccessfully.Broadcast(Streams, "");
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
void UReceiveStreamsOperation::HandleError(const FString& Message)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("%s failed - %s"), *StaticClass()->GetName(), *Message);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
|
||||
const TArray<FSpeckleStream> EmptyList;
|
||||
OnError.Broadcast(EmptyList, Message);
|
||||
|
||||
SetReadyToDestroy();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "API/Operations/SendOperation.h"
|
||||
|
||||
|
||||
|
||||
// USendOperation* USendOperation::SendOperation(UObject* WorldContextObject, UBase* Base, TScriptArray<TScriptInterface<ITransport>> Transports)
|
||||
// {
|
||||
// USendOperation* Node = NewObject<USendOperation>();
|
||||
// Node->Base = Base;
|
||||
// Node->Transports = Transports;
|
||||
//
|
||||
// Node->RegisterWithGameInstance(WorldContextObject);
|
||||
// return Node;
|
||||
// }
|
||||
//
|
||||
// void USendOperation::Activate()
|
||||
// {
|
||||
// check(Transports.Num() > 0);
|
||||
//
|
||||
// //TODO implement
|
||||
// unimplemented();
|
||||
//
|
||||
// }
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "API/SpeckleSerializer.h"
|
||||
|
||||
#include "Objects/Base.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
#include "Objects/ObjectModelRegistry.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
#include "Transports/Transport.h"
|
||||
#include "UObject/Package.h"
|
||||
|
||||
|
||||
// Create the Deserialization Base
|
||||
UBase* USpeckleSerializer::DeserializeBase(const TSharedPtr<FJsonObject> Obj,
|
||||
const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(Obj == nullptr) return nullptr;
|
||||
|
||||
// Handle Detached Objects
|
||||
TSharedPtr<FJsonObject> DetachedObject;
|
||||
if(USpeckleObjectUtils::ResolveReference(Obj, ReadTransport, DetachedObject))
|
||||
{
|
||||
return DeserializeBase(DetachedObject, ReadTransport);
|
||||
}
|
||||
|
||||
FString SpeckleType;
|
||||
if (!Obj->TryGetStringField("speckle_type", SpeckleType)) return nullptr;
|
||||
FString ObjectId = "";
|
||||
Obj->TryGetStringField("id", ObjectId);
|
||||
|
||||
TSubclassOf<UBase> BaseType;
|
||||
|
||||
FString WorkingType(SpeckleType);
|
||||
|
||||
int32 Tries = 1000;
|
||||
while(ensure(Tries-- > 0))
|
||||
{
|
||||
//Try and deserialize
|
||||
if(UObjectModelRegistry::TryGetRegisteredType(WorkingType, BaseType))
|
||||
{
|
||||
UBase* Base = NewObject<UBase>(GetTransientPackage(), BaseType);
|
||||
if(Base->Parse(Obj, ReadTransport))
|
||||
return Base;
|
||||
}
|
||||
|
||||
//If we couldn't even deserialize this to a Base
|
||||
if(WorkingType == "Base" || BaseType == UBase::StaticClass())
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Skipping deserilization of %s id: %s - object could not be deserilaized to Base"), *SpeckleType, *ObjectId );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//Try the next type
|
||||
if(!UObjectModelRegistry::ParentType(WorkingType, WorkingType))
|
||||
{
|
||||
WorkingType = "Base";
|
||||
UE_LOG(LogSpeckle, Verbose, TEXT("Unrecognised SpeckleType %s - Object id: %s Will be deserialized as Base"), *SpeckleType, *ObjectId );
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UBase* USpeckleSerializer::DeserializeBaseById(const FString& ObjectId,
|
||||
const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
auto Obj = ReadTransport->GetSpeckleObject(ObjectId);
|
||||
return DeserializeBase(Obj, ReadTransport);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "Mixpanel.h"
|
||||
|
||||
#include "Containers/UnrealString.h"
|
||||
#include "HttpModule.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "Launch/Resources/Version.h"
|
||||
#include "Misc/Base64.h"
|
||||
#include "Policies/CondensedJsonPrintPolicy.h"
|
||||
#include "Serialization/JsonSerializerMacros.h"
|
||||
#include "Serialization/JsonWriter.h"
|
||||
|
||||
const FString FAnalytics::MixpanelToken = TEXT("acd87c5a50b56df91a795e999812a3a4");
|
||||
const FString FAnalytics::MixpanelServer = TEXT("https://analytics.speckle.systems");
|
||||
const FString FAnalytics::VersionedApplicationName = FString::Printf(TEXT("Unreal Engine %d.%d"), ENGINE_MAJOR_VERSION, ENGINE_MINOR_VERSION);
|
||||
|
||||
void FAnalytics::TrackEvent(const FString& Email, const FString& Server, const FString& EventName)
|
||||
{
|
||||
const TMap<FString, FString> CustomProperties;
|
||||
TrackEvent(Email, Server, EventName, CustomProperties);
|
||||
}
|
||||
|
||||
void FAnalytics::TrackEvent(const FString& Email, const FString& Server, const FString& EventName, const TMap<FString, FString>& CustomProperties)
|
||||
{
|
||||
#if !SUPPRESS_SPECKLE_ANALYTICS
|
||||
|
||||
|
||||
FString HashedEmail = "@" + Hash(Email); //prepending an @ so we distinguish logged and non-logged users
|
||||
FString HashedServer = Hash(Server);
|
||||
|
||||
TMap<FString, FString> Properties
|
||||
{
|
||||
{ "distinct_id", HashedEmail },
|
||||
{ "server_id", HashedServer },
|
||||
{ "token", MixpanelToken },
|
||||
{ "hostApp", "Unreal Engine" },
|
||||
{ "hostAppVersion", VersionedApplicationName },
|
||||
{ "$os", *UGameplayStatics::GetPlatformName() },
|
||||
{ "type", "action" }
|
||||
};
|
||||
|
||||
|
||||
Properties.Append(CustomProperties);
|
||||
|
||||
FString Json;
|
||||
{
|
||||
auto Writer = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&Json);
|
||||
FJsonSerializerWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> Serializer(Writer);
|
||||
Serializer.StartObject();
|
||||
FString EventNameString = EventName;
|
||||
Serializer.Serialize(TEXT("event"), EventNameString);
|
||||
Serializer.SerializeMap(TEXT("properties"), Properties);
|
||||
Serializer.EndObject();
|
||||
Writer->Close();
|
||||
}
|
||||
const FString Data = FBase64::Encode(Json);
|
||||
|
||||
// Create Request
|
||||
const FHttpRequestRef Request = FHttpModule::Get().CreateRequest();
|
||||
{
|
||||
Request->SetURL(MixpanelServer + "/track?ip=1&data=" + Data);
|
||||
Request->SetHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
Request->SetHeader("Accept", TEXT("text/plain"));
|
||||
Request->SetVerb("POST");
|
||||
}
|
||||
|
||||
Request->OnProcessRequestComplete().BindLambda([](FHttpRequestPtr, FHttpResponsePtr Response, bool)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Verbose, TEXT("Recieved Mixpanel resonse %d"), Response->GetResponseCode());
|
||||
});
|
||||
|
||||
const bool RequestSent = Request->ProcessRequest();
|
||||
if(!RequestSent)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Failed to send Mixpanel event to %s"), *MixpanelServer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
FString FAnalytics::Hash(const FString& Input)
|
||||
{
|
||||
return FMD5::HashAnsiString(*Input.ToLower());
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Conversion/Converters/AggregateConverter.h"
|
||||
|
||||
#include "LogSpeckle.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
|
||||
|
||||
void UAggregateConverter::OnConvertersChangeHandler()
|
||||
{
|
||||
SpeckleTypeMap.Empty();
|
||||
|
||||
for(int i = 0; i < SpeckleConverters.Num(); i++)
|
||||
{
|
||||
const UObject* Converter = SpeckleConverters[i];
|
||||
if(Converter != nullptr && !Converter->GetClass()->ImplementsInterface(USpeckleConverter::StaticClass()))
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Converter {%s} is not a valid converter, Expected to implement interface %s"), *Converter->GetClass()->GetName(), *USpeckleConverter::StaticClass()->GetName())
|
||||
SpeckleConverters.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
void UAggregateConverter::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
|
||||
{
|
||||
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||
|
||||
if (PropertyChangedEvent.GetPropertyName() == GET_MEMBER_NAME_CHECKED(UAggregateConverter, SpeckleConverters))
|
||||
{
|
||||
OnConvertersChangeHandler();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
UBase* UAggregateConverter::ConvertToSpeckle_Implementation(const UObject* Object)
|
||||
{
|
||||
//TODO implement ToSpeckle
|
||||
unimplemented();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
UObject* UAggregateConverter::ConvertToNative_Implementation(const UBase* Object, UWorld* World, TScriptInterface<ISpeckleConverter>& )
|
||||
{
|
||||
return ConvertToNativeInternal(Object, World);
|
||||
}
|
||||
|
||||
UObject* UAggregateConverter::ConvertToNativeInternal(const UBase* Object, UWorld* World)
|
||||
{
|
||||
check(IsInGameThread());
|
||||
|
||||
if(!IsValid(Object)) return nullptr;
|
||||
|
||||
const TSubclassOf<UBase> Type = Object->GetClass();
|
||||
UObject* Converter = GetConverter(Type).GetObject();
|
||||
if(!IsValid(Converter))
|
||||
{
|
||||
//TODO convert displayValues then halt traversal
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(Type != UBase::StaticClass())
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Skipping Object %s: No conversion functions exist for %s"), *Object->Id, *Type->GetName());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Converting object of type: %s id: %s"), *Type->GetName(), *Object->Id);
|
||||
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
|
||||
TScriptInterface<ISpeckleConverter> MainConverter = this;
|
||||
|
||||
check(Converter->IsValidLowLevel());
|
||||
return Execute_ConvertToNative(Converter, Object, World, MainConverter);
|
||||
|
||||
}
|
||||
|
||||
bool UAggregateConverter::CanConvertToNative_Implementation(TSubclassOf<UBase> BaseType)
|
||||
{
|
||||
return GetConverter(BaseType).GetInterface() != nullptr;
|
||||
}
|
||||
|
||||
TScriptInterface<ISpeckleConverter> UAggregateConverter::GetConverter(const TSubclassOf<UBase> BaseType)
|
||||
{
|
||||
// Check if this SpeckleType has a known converter.
|
||||
if(SpeckleTypeMap.Contains(BaseType))
|
||||
{
|
||||
return SpeckleTypeMap[BaseType];
|
||||
}
|
||||
|
||||
// Try and find one that can convert this SpeckleType.
|
||||
FEditorScriptExecutionGuard ScriptGuard;
|
||||
for(UObject* Converter : SpeckleConverters)
|
||||
{
|
||||
if(!CheckValidConverter(Converter)) continue;
|
||||
|
||||
if(Execute_CanConvertToNative(Converter, BaseType))
|
||||
{
|
||||
//Found a Converter! Save this mapping for next time.
|
||||
SpeckleTypeMap.Add(BaseType, Converter);
|
||||
return Converter;
|
||||
}
|
||||
}
|
||||
|
||||
// SpeckleType has no conversions.
|
||||
SpeckleTypeMap.Add(BaseType, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UAggregateConverter::FinishConversion_Implementation()
|
||||
{
|
||||
FinishConversion_Internal();
|
||||
}
|
||||
|
||||
void UAggregateConverter::FinishConversion_Internal()
|
||||
{
|
||||
for (UObject* Converter : SpeckleConverters)
|
||||
{
|
||||
if(!CheckValidConverter(Converter)) continue;
|
||||
|
||||
Execute_FinishConversion(Converter);
|
||||
}
|
||||
OnConvertersChangeHandler();
|
||||
}
|
||||
|
||||
bool UAggregateConverter::CheckValidConverter(const UObject* Converter, bool LogWarning)
|
||||
{
|
||||
if(Converter == nullptr) return false;
|
||||
|
||||
if(Converter->Implements<USpeckleConverter>()) return true;
|
||||
|
||||
if(LogWarning)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Converter {%s} is not a valid converter, Expected to implement interface {%s}"), *Converter->GetClass()->GetName(), *USpeckleConverter::StaticClass()->GetName())
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "Conversion/Converters/BlockConverter.h"
|
||||
|
||||
#include "Objects/Other/BlockInstance.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
#include "Engine/World.h"
|
||||
|
||||
UBlockConverter::UBlockConverter()
|
||||
{
|
||||
SpeckleTypes.Add(UBlockInstance::StaticClass());
|
||||
|
||||
BlockInstanceActorType = AActor::StaticClass();
|
||||
ActorMobility = EComponentMobility::Static;
|
||||
}
|
||||
|
||||
UObject* UBlockConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>&)
|
||||
{
|
||||
const UBlockInstance* Block = Cast<UBlockInstance>(SpeckleBase);
|
||||
if(Block == nullptr) return nullptr;
|
||||
|
||||
return BlockToNative(Block, World);
|
||||
}
|
||||
|
||||
AActor* UBlockConverter::BlockToNative(const UBlockInstance* Block, UWorld* World)
|
||||
{
|
||||
AActor* BlockActor = CreateEmptyActor(World, USpeckleObjectUtils::CreateTransform(Block->Transform));
|
||||
//Return the block actor as is,
|
||||
//Other converter logic will convert child geometries because UBlockInstance intentionally left them as dynamic properties
|
||||
return BlockActor;
|
||||
}
|
||||
|
||||
AActor* UBlockConverter::CreateEmptyActor(UWorld* World, const FTransform& Transform, const FActorSpawnParameters& SpawnParameters)
|
||||
{
|
||||
AActor* Actor = World->SpawnActor<AActor>(BlockInstanceActorType, Transform, SpawnParameters);
|
||||
|
||||
if(!Actor->HasValidRootComponent())
|
||||
{
|
||||
USceneComponent* Scene = NewObject<USceneComponent>(Actor, "Root");
|
||||
Scene->SetRelativeTransform(Transform);
|
||||
Actor->SetRootComponent(Scene);
|
||||
Scene->RegisterComponent();
|
||||
}
|
||||
USceneComponent* RootComponent = Actor->GetRootComponent();
|
||||
|
||||
RootComponent->SetMobility(ActorMobility);
|
||||
|
||||
return Actor;
|
||||
}
|
||||
|
||||
UBase* UBlockConverter::ConvertToSpeckle_Implementation(const UObject* Object)
|
||||
{
|
||||
unimplemented();
|
||||
return nullptr; //TODO implement
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Conversion/Converters/MaterialConverter.h"
|
||||
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "Materials/MaterialInstanceConstant.h"
|
||||
#include "Materials/MaterialInstanceDynamic.h"
|
||||
#include "Objects/Other/RenderMaterial.h"
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
|
||||
|
||||
UMaterialConverter::UMaterialConverter()
|
||||
{
|
||||
static ConstructorHelpers::FObjectFinder<UMaterial> SpeckleMaterial(TEXT("Material'/SpeckleUnreal/SpeckleMaterial.SpeckleMaterial'"));
|
||||
static ConstructorHelpers::FObjectFinder<UMaterial> SpeckleGlassMaterial(TEXT("Material'/SpeckleUnreal/SpeckleGlassMaterial.SpeckleGlassMaterial'"));
|
||||
|
||||
DefaultMeshMaterial = SpeckleMaterial.Object;
|
||||
BaseMeshOpaqueMaterial = SpeckleMaterial.Object;
|
||||
BaseMeshTransparentMaterial = SpeckleGlassMaterial.Object;
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
UseConstMaterials = NotPlay;
|
||||
#endif
|
||||
|
||||
SpeckleTypes.Add(URenderMaterial::StaticClass());
|
||||
}
|
||||
|
||||
UObject* UMaterialConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld*, TScriptInterface<ISpeckleConverter>&)
|
||||
{
|
||||
const URenderMaterial* m = Cast<URenderMaterial>(SpeckleBase);
|
||||
|
||||
if(m == nullptr) return DefaultMeshMaterial;
|
||||
|
||||
return GetMaterial(m);
|
||||
}
|
||||
|
||||
UMaterialInterface* UMaterialConverter::GetMaterial(const URenderMaterial* SpeckleMaterial)
|
||||
{
|
||||
if(SpeckleMaterial == nullptr || SpeckleMaterial->Id == "") return DefaultMeshMaterial; //Material is invalid
|
||||
|
||||
// 1. Check Overrides
|
||||
UMaterialInterface* NativeMaterial;
|
||||
if(TryGetOverride(SpeckleMaterial, NativeMaterial))
|
||||
return NativeMaterial;
|
||||
|
||||
// 2. Check transient cache
|
||||
if(ConvertedMaterials.Contains(SpeckleMaterial->Id))
|
||||
{
|
||||
return ConvertedMaterials[SpeckleMaterial->Id];
|
||||
}
|
||||
|
||||
// 3. Check Assets
|
||||
UPackage* Package = GetPackage(SpeckleMaterial->Id);
|
||||
|
||||
NativeMaterial = Cast<UMaterialInterface>(Package->FindAssetInPackage());
|
||||
if(IsValid(NativeMaterial))
|
||||
{
|
||||
return NativeMaterial;
|
||||
}
|
||||
|
||||
// 4. Convert
|
||||
return RenderMaterialToNative(SpeckleMaterial, Package);
|
||||
}
|
||||
|
||||
bool UMaterialConverter::TryGetOverride(const URenderMaterial* SpeckleMaterial, UMaterialInterface*& OutMaterial) const
|
||||
{
|
||||
const auto MaterialID = SpeckleMaterial->Id;
|
||||
|
||||
|
||||
//Override by id
|
||||
if(MaterialOverridesById.Contains(MaterialID))
|
||||
{
|
||||
OutMaterial = MaterialOverridesById[MaterialID];
|
||||
return true;
|
||||
}
|
||||
//Override by name
|
||||
const FString Name = SpeckleMaterial->Name;
|
||||
for (const UMaterialInterface* Mat : MaterialOverridesByName)
|
||||
{
|
||||
if(ensureAlways(IsValid(Mat)) && Mat->GetName() == Name)
|
||||
{
|
||||
OutMaterial = MaterialOverridesById[MaterialID];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
FString UMaterialConverter::RemoveInvalidFileChars(const FString& InString) const
|
||||
{
|
||||
return FPaths::MakeValidFileName(InString.Replace(TEXT("."), TEXT("_"), ESearchCase::CaseSensitive));
|
||||
}
|
||||
|
||||
UMaterialInterface* UMaterialConverter::RenderMaterialToNative(const URenderMaterial* SpeckleMaterial, UPackage* Package)
|
||||
{
|
||||
UMaterialInterface* MaterialBase = SpeckleMaterial->Opacity >= 1
|
||||
? BaseMeshOpaqueMaterial
|
||||
: BaseMeshTransparentMaterial;
|
||||
|
||||
UMaterialInstance* MaterialInstance;
|
||||
#if WITH_EDITOR
|
||||
if (ShouldCreateConstMaterial(UseConstMaterials))
|
||||
{
|
||||
const FName Name = MakeUniqueObjectName(Package, UMaterialInstanceConstant::StaticClass(), *RemoveInvalidFileChars(SpeckleMaterial->Name));
|
||||
|
||||
//TStrongObjectPtr< UMaterialInstanceConstantFactoryNew > MaterialFact( NewObject< UMaterialInstanceConstantFactoryNew >() );
|
||||
//MaterialFact->InitialParent = MaterialBase;
|
||||
//UMaterialInstanceConstant* ConstMaterial = Cast< UMaterialInstanceConstant >( MaterialFact->FactoryCreateNew( UMaterialInstanceConstant::StaticClass(), Package, Name, RF_Public, nullptr, GWarn ) );
|
||||
UMaterialInstanceConstant* ConstMaterial = NewObject<UMaterialInstanceConstant>(Package, Name, RF_Public | RF_Standalone);
|
||||
|
||||
MaterialInstance = ConstMaterial;
|
||||
ConstMaterial->SetParentEditorOnly(MaterialBase);
|
||||
ConstMaterial->SetScalarParameterValueEditorOnly(FMaterialParameterInfo("Opacity"), SpeckleMaterial->Opacity);
|
||||
ConstMaterial->SetScalarParameterValueEditorOnly(FMaterialParameterInfo("Metallic"), SpeckleMaterial->Metalness);
|
||||
ConstMaterial->SetScalarParameterValueEditorOnly(FMaterialParameterInfo("Roughness"), SpeckleMaterial->Roughness);
|
||||
ConstMaterial->SetVectorParameterValueEditorOnly(FMaterialParameterInfo("BaseColor"), SpeckleMaterial->Diffuse);
|
||||
ConstMaterial->SetVectorParameterValueEditorOnly(FMaterialParameterInfo("EmissiveColor"), SpeckleMaterial->Emissive);
|
||||
|
||||
//ConstMaterial->InitStaticPermutation();
|
||||
|
||||
ConstMaterial->MarkPackageDirty();
|
||||
|
||||
FAssetRegistryModule::AssetCreated(MaterialInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
UMaterialInstanceDynamic* DynMaterial = UMaterialInstanceDynamic::Create(MaterialBase, Package, FName(SpeckleMaterial->Name));
|
||||
MaterialInstance = DynMaterial;
|
||||
|
||||
DynMaterial->SetScalarParameterValue("Opacity", SpeckleMaterial->Opacity);
|
||||
DynMaterial->SetScalarParameterValue("Metallic", SpeckleMaterial->Metalness);
|
||||
DynMaterial->SetScalarParameterValue("Roughness", SpeckleMaterial->Roughness);
|
||||
DynMaterial->SetVectorParameterValue("BaseColor", SpeckleMaterial->Diffuse);
|
||||
DynMaterial->SetVectorParameterValue("EmissiveColor", SpeckleMaterial->Emissive);
|
||||
|
||||
DynMaterial->SetFlags(RF_Public);
|
||||
}
|
||||
|
||||
ConvertedMaterials.Add(SpeckleMaterial->Id, MaterialInstance);
|
||||
|
||||
return MaterialInstance;
|
||||
|
||||
}
|
||||
|
||||
void UMaterialConverter::FinishConversion_Implementation()
|
||||
{
|
||||
ConvertedMaterials.Empty();
|
||||
}
|
||||
|
||||
UPackage* UMaterialConverter::GetPackage(const FString& ObjectID ) const
|
||||
{
|
||||
const FString PackagePath = FPaths::Combine(TEXT("/Game/Speckle/Materials"), ObjectID);
|
||||
return CreatePackage(*PackagePath);
|
||||
}
|
||||
|
||||
|
||||
#if WITH_EDITOR
|
||||
bool UMaterialConverter::ShouldCreateConstMaterial(TEnumAsByte<EConstMaterialOptions> Options)
|
||||
{
|
||||
if(!GIsEditor) return false;
|
||||
|
||||
switch(Options)
|
||||
{
|
||||
case Never:
|
||||
return false;
|
||||
case NotPlay:
|
||||
return !FApp::IsGame();
|
||||
case Always:
|
||||
return true;
|
||||
default:
|
||||
unimplemented();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Conversion/Converters/PointCloudConverter.h"
|
||||
|
||||
#include "LidarPointCloudActor.h"
|
||||
#include "LidarPointCloudComponent.h"
|
||||
#include "Objects/Geometry/PointCloud.h"
|
||||
|
||||
|
||||
UPointCloudConverter::UPointCloudConverter()
|
||||
{
|
||||
SpeckleTypes.Add(UPointCloud::StaticClass());
|
||||
|
||||
PointCloudActorType = ALidarPointCloudActor::StaticClass();
|
||||
ActorMobility = EComponentMobility::Static;
|
||||
}
|
||||
|
||||
|
||||
UObject* UPointCloudConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>&)
|
||||
{
|
||||
const UPointCloud* p = Cast<UPointCloud>(SpeckleBase);
|
||||
|
||||
if(p == nullptr) return nullptr;
|
||||
|
||||
return PointCloudToNative(p, World);
|
||||
}
|
||||
|
||||
|
||||
ALidarPointCloudActor* UPointCloudConverter::PointCloudToNative(const UPointCloud* SpecklePointCloud, UWorld* World)
|
||||
{
|
||||
TArray<FLidarPointCloudPoint> LidarPoints;
|
||||
|
||||
LidarPoints.Reserve(SpecklePointCloud->Points.Num());
|
||||
|
||||
for(int i = 0; i < SpecklePointCloud->Points.Num(); i++)
|
||||
{
|
||||
FColor c = SpecklePointCloud->Colors.Num() > i? SpecklePointCloud->Colors[i] : FColor::White;
|
||||
#if ENGINE_MAJOR_VERSION >= 5
|
||||
FVector3f Point = FVector3f(SpecklePointCloud->Points[i]);
|
||||
#else
|
||||
FVector Point = SpecklePointCloud->Points[i];
|
||||
#endif
|
||||
|
||||
FLidarPointCloudPoint p(Point, c, true, 0);
|
||||
LidarPoints.Add(p);
|
||||
}
|
||||
|
||||
ULidarPointCloud* PointCloud = NewObject<ULidarPointCloud>();
|
||||
|
||||
PointCloud->Initialize(FBox(SpecklePointCloud->Points));
|
||||
|
||||
PointCloud->InsertPoints(LidarPoints, ELidarPointCloudDuplicateHandling::Ignore, false, FVector::ZeroVector);
|
||||
|
||||
PointCloud->CenterPoints();
|
||||
PointCloud->RefreshBounds();
|
||||
|
||||
return CreateActor(World, PointCloud);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ALidarPointCloudActor* UPointCloudConverter::CreateActor(UWorld* World, ULidarPointCloud* PointCloudData)
|
||||
{
|
||||
ALidarPointCloudActor* Actor = World->SpawnActor<ALidarPointCloudActor>(PointCloudActorType);
|
||||
Actor->SetPointCloud(PointCloudData);
|
||||
Actor->GetRootComponent()->SetMobility(ActorMobility);
|
||||
return Actor;
|
||||
}
|
||||
|
||||
|
||||
UBase* UPointCloudConverter::ConvertToSpeckle_Implementation(const UObject* Object)
|
||||
{
|
||||
const ULidarPointCloudComponent* P = Cast<ULidarPointCloudComponent>(Object);
|
||||
|
||||
if(P == nullptr)
|
||||
{
|
||||
const AActor* A = Cast<AActor>(Object);
|
||||
if(A != nullptr)
|
||||
{
|
||||
P = A->FindComponentByClass<ULidarPointCloudComponent>();
|
||||
}
|
||||
}
|
||||
if(P == nullptr) return nullptr;
|
||||
|
||||
return PointCloudToSpeckle(P);
|
||||
}
|
||||
|
||||
|
||||
UPointCloud* UPointCloudConverter::PointCloudToSpeckle(const ULidarPointCloudComponent* Object)
|
||||
{
|
||||
return nullptr; //TODO implement ToSpeckle function
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Conversion/Converters/ProceduralMeshConverter.h"
|
||||
|
||||
#include "ProceduralMeshComponent.h"
|
||||
#include "Conversion/Converters/MaterialConverter.h"
|
||||
#include "Materials/MaterialInstance.h"
|
||||
#include "Objects/DisplayValueElement.h"
|
||||
#include "Objects/Geometry/Mesh.h"
|
||||
#include "Objects/Other/RenderMaterial.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
// Setup some basics
|
||||
UProceduralMeshConverter::UProceduralMeshConverter()
|
||||
{
|
||||
SpeckleTypes.Add(UMesh::StaticClass());
|
||||
SpeckleTypes.Add(UDisplayValueElement::StaticClass());
|
||||
|
||||
MeshActorType = AActor::StaticClass();
|
||||
ActorMobility = EComponentMobility::Static;
|
||||
}
|
||||
|
||||
// Blueprint for converting data to 3D model
|
||||
UObject* UProceduralMeshConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World,
|
||||
TScriptInterface<ISpeckleConverter>& AvailableConverters )
|
||||
{
|
||||
const UMesh* m = Cast<UMesh>(SpeckleBase);
|
||||
if(m != nullptr)
|
||||
return MeshToNative(m, World, AvailableConverters);
|
||||
|
||||
const UDisplayValueElement* d = Cast<UDisplayValueElement>(SpeckleBase);
|
||||
if(d)
|
||||
{
|
||||
AActor* Parent = CreateEmptyActor(World, FTransform());
|
||||
for(const UMesh* Child : d->DisplayValue)
|
||||
{
|
||||
AActor* ChildActor = MeshToNative(Child, World, AvailableConverters);
|
||||
if(IsValid(ChildActor))
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
ChildActor->SetActorLabel(FString::Printf(TEXT("%s - %s"), *Child->SpeckleType, *Child->Id));
|
||||
#endif
|
||||
ChildActor->GetRootComponent()->SetMobility(ActorMobility);
|
||||
ChildActor->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
ChildActor->SetOwner(Parent);
|
||||
}
|
||||
}
|
||||
return Parent;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AActor* UProceduralMeshConverter::MeshToNative(const UMesh* SpeckleMesh,
|
||||
UWorld* World,
|
||||
TScriptInterface<ISpeckleConverter>& MaterialConverter)
|
||||
{
|
||||
AActor* MeshActor = CreateEmptyActor(World, USpeckleObjectUtils::CreateTransform(SpeckleMesh->Transform));
|
||||
UProceduralMeshComponent* MeshComponent = NewObject<UProceduralMeshComponent>(MeshActor, FName("SpeckleMeshComponent"));
|
||||
MeshComponent->SetupAttachment(MeshActor->GetRootComponent());
|
||||
MeshComponent->RegisterComponent();
|
||||
|
||||
TArray<int32> Faces;
|
||||
|
||||
int32 i = 0;
|
||||
while (i < SpeckleMesh->Faces.Num())
|
||||
{
|
||||
int32 n = SpeckleMesh->Faces[i];
|
||||
if(n < 3) n += 3; // 0 -> 3, 1 -> 4
|
||||
|
||||
if (n == 3) //Triangles
|
||||
{
|
||||
Faces.Add(SpeckleMesh->Faces[i + 3]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 2]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 1]);
|
||||
}
|
||||
else if(n == 4) // Quads
|
||||
{
|
||||
Faces.Add(SpeckleMesh->Faces[i + 4]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 3]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 1]);
|
||||
|
||||
Faces.Add(SpeckleMesh->Faces[i + 3]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 2]);
|
||||
Faces.Add(SpeckleMesh->Faces[i + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// n-gons shall be ignored
|
||||
}
|
||||
|
||||
i += n + 1;
|
||||
}
|
||||
|
||||
const TArray<FVector> Normals;
|
||||
const TArray<FProcMeshTangent> Tangents;
|
||||
|
||||
MeshComponent->CreateMeshSection(
|
||||
0,
|
||||
SpeckleMesh->Vertices,
|
||||
Faces,
|
||||
Normals,
|
||||
SpeckleMesh->TextureCoordinates,
|
||||
SpeckleMesh->VertexColors,
|
||||
Tangents,
|
||||
true);
|
||||
|
||||
UMaterialInterface* Material = Cast<UMaterialInstance>(Execute_ConvertToNative(MaterialConverter.GetObject(), SpeckleMesh->RenderMaterial, World, MaterialConverter));
|
||||
ensure(Material != nullptr);
|
||||
|
||||
MeshComponent->SetMaterial(0, Material);
|
||||
|
||||
return MeshActor;
|
||||
}
|
||||
|
||||
AActor* UProceduralMeshConverter::CreateEmptyActor(UWorld* World, const FTransform& Transform, const FActorSpawnParameters& SpawnParameters)
|
||||
{
|
||||
AActor* Actor = World->SpawnActor<AActor>(MeshActorType, Transform, SpawnParameters);
|
||||
USceneComponent* Scene = NewObject<USceneComponent>(Actor, "Root");
|
||||
Actor->SetRootComponent(Scene);
|
||||
Scene->RegisterComponent();
|
||||
Scene->SetMobility(ActorMobility);
|
||||
return Actor;
|
||||
}
|
||||
|
||||
|
||||
UBase* UProceduralMeshConverter::ConvertToSpeckle_Implementation(const UObject* Object)
|
||||
{
|
||||
const UProceduralMeshComponent* M = Cast<UProceduralMeshComponent>(Object);
|
||||
|
||||
if(M == nullptr)
|
||||
{
|
||||
const AActor* A = Cast<AActor>(Object);
|
||||
if(A != nullptr)
|
||||
{
|
||||
M = A->FindComponentByClass<UProceduralMeshComponent>();
|
||||
}
|
||||
}
|
||||
if(M == nullptr) return nullptr;
|
||||
|
||||
return MeshToSpeckle(M);
|
||||
}
|
||||
|
||||
|
||||
UMesh* UProceduralMeshConverter::MeshToSpeckle(const UProceduralMeshComponent* Object)
|
||||
{
|
||||
return nullptr; //TODO implement ToSpeckle function
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "Conversion/Converters/StaticMeshConverter.h"
|
||||
|
||||
#include "MeshDescriptionBase.h"
|
||||
#include "StaticMeshDescription.h"
|
||||
#include "MeshTypes.h"
|
||||
#include "StaticMeshOperations.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "Engine/StaticMeshActor.h"
|
||||
#include "Objects/Geometry/Mesh.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Conversion/Converters/MaterialConverter.h"
|
||||
#include "Misc/ScopedSlowTask.h"
|
||||
#include "Objects/DisplayValueElement.h"
|
||||
#include "Objects/Geometry/Box.h"
|
||||
#include "Objects/Other/RenderMaterial.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealModule"
|
||||
|
||||
bool UStaticMeshConverter::CanConvertToNative_Implementation(TSubclassOf<UBase> BaseType)
|
||||
{
|
||||
if(EnabledTypes.Contains(BaseType))
|
||||
return EnabledTypes[BaseType];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UStaticMeshConverter::UStaticMeshConverter()
|
||||
{
|
||||
EnabledTypes.Add(UMesh::StaticClass(), true);
|
||||
EnabledTypes.Add(UDisplayValueElement::StaticClass(), true);
|
||||
EnabledTypes.Add(UBoxx::StaticClass(), true);
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
UseFullBuild = true;
|
||||
DisplayBuildProgressBar = true;
|
||||
AllowCancelBuild = false;
|
||||
#endif
|
||||
Transient = false;
|
||||
BuildSimpleCollision = true;
|
||||
|
||||
BuildReversedIndexBuffer = true;
|
||||
UseFullPrecisionUVs = false;
|
||||
RemoveDegeneratesOnBuild = true;
|
||||
MinLightmapResolution = 64;
|
||||
|
||||
MeshActorType = AStaticMeshActor::StaticClass();
|
||||
ActorMobility = EComponentMobility::Static;
|
||||
}
|
||||
|
||||
AActor* UStaticMeshConverter::CreateEmptyActor(UWorld* World, const FTransform& Transform, const FActorSpawnParameters& SpawnParameters)
|
||||
{
|
||||
AActor* Actor = World->SpawnActor<AActor>(MeshActorType, Transform, SpawnParameters);
|
||||
if(Actor->HasValidRootComponent())
|
||||
Actor->GetRootComponent()->SetMobility(EComponentMobility::Movable); //Create actor as movable for now, we will change it later to the desired mobility
|
||||
return Actor;
|
||||
}
|
||||
|
||||
UObject* UStaticMeshConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>& AvailableConverters)
|
||||
{
|
||||
const UMesh* m = Cast<UMesh>(SpeckleBase);
|
||||
if(m != nullptr)
|
||||
{
|
||||
//Handle Single Mesh
|
||||
return MeshToNativeActor(m, World, AvailableConverters);
|
||||
}
|
||||
|
||||
|
||||
const UBoxx* b = Cast<UBoxx>(SpeckleBase);
|
||||
if(b != nullptr)
|
||||
{
|
||||
//Handle Element with Display Values
|
||||
const UMesh* m = b->ToMesh();
|
||||
return MeshToNativeActor(m, World, AvailableConverters);
|
||||
}
|
||||
|
||||
const UDisplayValueElement* d = Cast<UDisplayValueElement>(SpeckleBase);
|
||||
if(d != nullptr)
|
||||
{
|
||||
//Handle Element with Display Values
|
||||
return MeshesToNativeActor(d, d->DisplayValue, World, AvailableConverters);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
AActor* UStaticMeshConverter::MeshToNativeActor(const UMesh* SpeckleMesh, UWorld* World, TScriptInterface<ISpeckleConverter>& MaterialConverter)
|
||||
{
|
||||
TArray<UMesh*> Meshes = {const_cast<UMesh*>(SpeckleMesh)};
|
||||
return MeshesToNativeActor(SpeckleMesh, Meshes, World, MaterialConverter);
|
||||
}
|
||||
|
||||
AActor* UStaticMeshConverter::MeshesToNativeActor(const UBase* Parent, const TArray<UMesh*>& SpeckleMeshes, UWorld* World, TScriptInterface<ISpeckleConverter>& RenderMaterialConverter)
|
||||
{
|
||||
check(RenderMaterialConverter.GetInterface() != nullptr);
|
||||
ensureMsgf(Execute_CanConvertToNative(RenderMaterialConverter.GetObject(), URenderMaterial::StaticClass()), TEXT("StaticMeshConverter expects a valid RenderMaterial converter to be avaiable"));
|
||||
|
||||
|
||||
const FString PackagePath = FPaths::Combine(TEXT("/Game/Speckle/Geometry"), Parent->Id);
|
||||
UPackage* Package = CreatePackage(*PackagePath);
|
||||
|
||||
//Find existing mesh
|
||||
UStaticMesh* Mesh = Cast<UStaticMesh>(Package->FindAssetInPackage());
|
||||
|
||||
if(!IsValid(Mesh))
|
||||
{
|
||||
//No existing mesh was found, try and convert SpeckleMesh
|
||||
Mesh = MeshesToNativeMesh(Package, Parent, SpeckleMeshes, RenderMaterialConverter);
|
||||
}
|
||||
|
||||
FMatrix Transform = FMatrix::Identity;
|
||||
// For single mesh, we check for transform
|
||||
//TODO figure out how to handle DisplayValueElement with transform. Maybe we just grab transform from parent unconditionally? How does this affect blocks?
|
||||
if(Parent == SpeckleMeshes[0])
|
||||
{
|
||||
Transform = SpeckleMeshes[0]->Transform;
|
||||
}
|
||||
|
||||
AActor* Actor = CreateEmptyActor(World, USpeckleObjectUtils::CreateTransform(Transform));
|
||||
TInlineComponentArray<UStaticMeshComponent*> Components;
|
||||
Actor->GetComponents<UStaticMeshComponent>(Components);
|
||||
|
||||
UStaticMeshComponent* MeshComponent;
|
||||
if(Components.Num() > 0) MeshComponent = Components[0];
|
||||
else
|
||||
{
|
||||
// MeshActorType doesn't have a UStaticMeshComponent, so we will add one
|
||||
MeshComponent = NewObject<UStaticMeshComponent>(Actor, FName("SpeckleMeshComponent"));
|
||||
MeshComponent->SetupAttachment(Actor->GetRootComponent());
|
||||
MeshComponent->RegisterComponent();
|
||||
}
|
||||
|
||||
MeshComponent->SetStaticMesh(Mesh);
|
||||
|
||||
int i = 0;
|
||||
for(const UMesh* DisplayMesh : SpeckleMeshes)
|
||||
{
|
||||
URenderMaterial* MaterialToConvert = DisplayMesh->RenderMaterial;
|
||||
if(!MaterialToConvert)
|
||||
{
|
||||
//Try and grab a material from the parent
|
||||
const auto* MaterialProperty = Parent->DynamicProperties.Find("renderMaterial");
|
||||
const TSharedPtr<FJsonObject>* MaterialObject;
|
||||
if(MaterialProperty && (*MaterialProperty)->TryGetObject(MaterialObject))
|
||||
{
|
||||
//TODO giving a nullptr transport is pretty unsafe and relies on the deserializer not to have to dereference a detached property.
|
||||
MaterialToConvert = Cast<URenderMaterial>(USpeckleSerializer::DeserializeBase(*MaterialObject, nullptr));
|
||||
}
|
||||
}
|
||||
UMaterialInterface* Material = GetMaterial(MaterialToConvert, World, RenderMaterialConverter);
|
||||
|
||||
ensure(IsValid(Material));
|
||||
MeshComponent->SetMaterial(i, Material);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(Actor->HasValidRootComponent())
|
||||
Actor->GetRootComponent()->SetMobility(ActorMobility);
|
||||
|
||||
return Actor;
|
||||
}
|
||||
|
||||
|
||||
UMaterialInterface* UStaticMeshConverter::GetMaterial(const URenderMaterial* SpeckleMaterial, UWorld* World, TScriptInterface<ISpeckleConverter>& MaterialConverter) const
|
||||
{
|
||||
if(!SpeckleMaterial)
|
||||
{
|
||||
// Create a fake render material, (since nullptr doesn't have a type, speckle converters don't know how to convert it)
|
||||
// If the converter wants to handle this specially, The material has an empty Id
|
||||
SpeckleMaterial = NewObject<URenderMaterial>(GetTransientPackage(), "NullSpeckleMaterial");
|
||||
}
|
||||
return Cast<UMaterialInterface>(Execute_ConvertToNative(MaterialConverter.GetObject(), SpeckleMaterial, World, MaterialConverter));
|
||||
}
|
||||
|
||||
|
||||
UStaticMesh* UStaticMeshConverter::MeshToNativeMesh(UObject* Outer, const UMesh* SpeckleMesh, TScriptInterface<ISpeckleConverter>& MaterialConverter)
|
||||
{
|
||||
TArray<UMesh*> Meshes;
|
||||
Meshes.Add(const_cast<UMesh*>(SpeckleMesh));
|
||||
return MeshesToNativeMesh(Outer, SpeckleMesh, Meshes, MaterialConverter);
|
||||
}
|
||||
|
||||
|
||||
UStaticMesh* UStaticMeshConverter::MeshesToNativeMesh(UObject* Outer, const UBase* Parent, const TArray<UMesh*>& SpeckleMeshes, TScriptInterface<ISpeckleConverter>& MaterialConverter)
|
||||
{
|
||||
if(SpeckleMeshes.Num() == 0) return nullptr;
|
||||
|
||||
EObjectFlags ObjectFags = Transient? RF_Transient | RF_Public : RF_Public;
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5
|
||||
ObjectFags |= RF_Standalone; //TODO maybe all versions should have RF_Standalone?
|
||||
#endif
|
||||
|
||||
UStaticMesh* Mesh = NewObject<UStaticMesh>(Outer, FName(Parent->Id), ObjectFags);
|
||||
|
||||
Mesh->InitResources();
|
||||
Mesh->SetLightingGuid();
|
||||
|
||||
UStaticMeshDescription* StaticMeshDescription = Mesh->CreateStaticMeshDescription(Outer);
|
||||
FMeshDescription& BaseMeshDescription = StaticMeshDescription->GetMeshDescription();
|
||||
|
||||
//Build Settings
|
||||
#if WITH_EDITOR
|
||||
{
|
||||
FStaticMeshSourceModel& SrcModel = Mesh->AddSourceModel();
|
||||
SrcModel.BuildSettings.bRecomputeNormals = true;
|
||||
SrcModel.BuildSettings.bRecomputeTangents = true;
|
||||
SrcModel.BuildSettings.bRemoveDegenerates = RemoveDegeneratesOnBuild;
|
||||
SrcModel.BuildSettings.bUseHighPrecisionTangentBasis = false;
|
||||
SrcModel.BuildSettings.bBuildReversedIndexBuffer = BuildReversedIndexBuffer;
|
||||
SrcModel.BuildSettings.bUseFullPrecisionUVs = UseFullPrecisionUVs;
|
||||
SrcModel.BuildSettings.bGenerateLightmapUVs = GenerateLightmapUV;
|
||||
SrcModel.BuildSettings.SrcLightmapIndex = 0;
|
||||
SrcModel.BuildSettings.DstLightmapIndex = 1;
|
||||
SrcModel.BuildSettings.MinLightmapResolution = MinLightmapResolution;
|
||||
}
|
||||
#endif
|
||||
|
||||
UStaticMesh::FBuildMeshDescriptionsParams MeshParams;
|
||||
GenerateMeshParams(MeshParams);
|
||||
|
||||
for(const UMesh* SpeckleMesh : SpeckleMeshes)
|
||||
{
|
||||
const size_t NumberOfVertices = SpeckleMesh->Vertices.Num();
|
||||
const size_t NumberOfFacesIndices = SpeckleMesh->Faces.Num();
|
||||
|
||||
// Convert Vertices
|
||||
if(NumberOfVertices == 0 || NumberOfFacesIndices == 0) continue;
|
||||
|
||||
StaticMeshDescription->ReserveNewVertices(NumberOfVertices);
|
||||
|
||||
TArray<FVertexID> Vertices;
|
||||
Vertices.Reserve(NumberOfVertices);
|
||||
|
||||
for(const FVector VertexPosition : SpeckleMesh->Vertices)
|
||||
{
|
||||
const FVertexID VertID = StaticMeshDescription->CreateVertex();
|
||||
StaticMeshDescription->SetVertexPosition(VertID, VertexPosition);
|
||||
Vertices.Add(VertID);
|
||||
}
|
||||
|
||||
// Convert Material
|
||||
UMaterialInterface* Material = GetMaterial(SpeckleMesh->RenderMaterial, GetWorld(), MaterialConverter);
|
||||
|
||||
const FName MaterialSlotName = Mesh->AddMaterial(Material);;
|
||||
BaseMeshDescription.PolygonGroupAttributes().RegisterAttribute<FName>(MeshAttribute::PolygonGroup::ImportedMaterialSlotName, 1, MaterialSlotName, EMeshAttributeFlags::None);
|
||||
|
||||
// Convert Faces
|
||||
const FPolygonGroupID PolygonGroupID = StaticMeshDescription->CreatePolygonGroup();
|
||||
|
||||
StaticMeshDescription->SetPolygonGroupMaterialSlotName(PolygonGroupID, MaterialSlotName);
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5
|
||||
StaticMeshDescription->VertexInstanceAttributes().RegisterAttribute<FVector2f>(MeshAttribute::VertexInstance::TextureCoordinate, 2, FVector2f::ZeroVector, EMeshAttributeFlags::None);
|
||||
#else
|
||||
StaticMeshDescription->VertexInstanceAttributes().RegisterAttribute<FVector2D>(MeshAttribute::VertexInstance::TextureCoordinate, 2, FVector2D::ZeroVector, EMeshAttributeFlags::None);
|
||||
#endif
|
||||
{
|
||||
// Reserve space assuming faces will all be triangles //TODO (maybe it's better to assume something higher?)
|
||||
const int32 EstimatedNumberOfFaces = SpeckleMesh->Faces.Num() / 4 * 3;
|
||||
StaticMeshDescription->ReserveNewTriangles(EstimatedNumberOfFaces);
|
||||
StaticMeshDescription->ReserveNewPolygons(EstimatedNumberOfFaces);
|
||||
StaticMeshDescription->ReserveNewVertexInstances(FGenericPlatformMath::Max(EstimatedNumberOfFaces * 3, SpeckleMesh->Vertices.Num()));
|
||||
}
|
||||
|
||||
int32 i = 0;
|
||||
while (i < NumberOfFacesIndices)
|
||||
{
|
||||
int32 n = SpeckleMesh->Faces[i];
|
||||
if(n < 3) n += 3; // 0 -> 3, 1 -> 4
|
||||
|
||||
TArray<FVertexInstanceID> VertexInstances;
|
||||
VertexInstances.Reserve(n);
|
||||
TSet<FVertexID> Verts;
|
||||
Verts.Reserve(n);
|
||||
for(int j = 0; j < n; j ++)
|
||||
{
|
||||
int32 VertIndex = SpeckleMesh->Faces[i + 1 + j];
|
||||
FVertexID Vert = Vertices[VertIndex];
|
||||
bool AlreadyInSet;
|
||||
Verts.Add(Vert, &AlreadyInSet);
|
||||
|
||||
if(AlreadyInSet)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Invalid Polygon while creating mesh %s - vertex at index %d appears more than once in a face, duplicate vertices will be ignored"), *SpeckleMesh->Id, VertIndex);
|
||||
continue;
|
||||
}
|
||||
FVertexInstanceID VertexInstance = StaticMeshDescription->CreateVertexInstance(Vert);
|
||||
|
||||
VertexInstances.Add(VertexInstance);
|
||||
|
||||
if(SpeckleMesh->TextureCoordinates.Num() > VertIndex)
|
||||
StaticMeshDescription->SetVertexInstanceUV(VertexInstance, SpeckleMesh->TextureCoordinates[VertIndex]);
|
||||
|
||||
//if(SpeckleMesh->VertexColors.Num() > VertIndex)
|
||||
// //TODO set vertex colors
|
||||
}
|
||||
|
||||
i += n + 1;
|
||||
if(VertexInstances.Num() < 3)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Invalid Polygon while creating mesh %s - face has fewer than 3 verts, this face will be ignored"), *SpeckleMesh->Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
TArray<FEdgeID> Edges;
|
||||
Edges.Reserve(n);
|
||||
|
||||
const FPolygonID PolygonID = StaticMeshDescription->CreatePolygon(PolygonGroupID, VertexInstances, Edges);
|
||||
|
||||
for (const FEdgeID EdgeID : Edges)
|
||||
{
|
||||
StaticMeshDescription->GetEdgeHardnesses()[EdgeID] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(StaticMeshDescription->Vertices().Num() == 0
|
||||
|| StaticMeshDescription->VertexInstances().Num() == 0
|
||||
|| StaticMeshDescription->Triangles().Num() == 0)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Skipping %s $s, converted mesh is empty!"), *Parent->SpeckleType, *Parent->Id);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BaseMeshDescription.TriangulateMesh();
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5
|
||||
FStaticMeshOperations::ComputeTriangleTangentsAndNormals(BaseMeshDescription);
|
||||
#else
|
||||
BaseMeshDescription.PolygonAttributes().RegisterAttribute<FVector>(MeshAttribute::Polygon::Normal, 1, FVector::ZeroVector, EMeshAttributeFlags::Transient);
|
||||
BaseMeshDescription.PolygonAttributes().RegisterAttribute<FVector>(MeshAttribute::Polygon::Tangent, 1, FVector::ZeroVector, EMeshAttributeFlags::Transient);
|
||||
BaseMeshDescription.PolygonAttributes().RegisterAttribute<FVector>(MeshAttribute::Polygon::Binormal, 1, FVector::ZeroVector, EMeshAttributeFlags::Transient);
|
||||
BaseMeshDescription.PolygonAttributes().RegisterAttribute<FVector>(MeshAttribute::Polygon::Center, 1, FVector::ZeroVector, EMeshAttributeFlags::Transient);
|
||||
FStaticMeshOperations::ComputePolygonTangentsAndNormals(BaseMeshDescription);
|
||||
#endif
|
||||
|
||||
FStaticMeshOperations::ComputeTangentsAndNormals(BaseMeshDescription, EComputeNTBsFlags::Normals | EComputeNTBsFlags::Tangents);
|
||||
|
||||
|
||||
//Mesh->PreEditChange(nullptr);
|
||||
|
||||
#if ENGINE_MAJOR_VERSION >= 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION >= 27 )
|
||||
Mesh->SetLightMapCoordinateIndex(1);
|
||||
#else
|
||||
Mesh->LightMapCoordinateIndex = 1;
|
||||
#endif
|
||||
|
||||
Mesh->BuildFromMeshDescriptions(TArray<const FMeshDescription*>{&BaseMeshDescription}, MeshParams);
|
||||
|
||||
#if WITH_EDITOR
|
||||
if(UseFullBuild)
|
||||
{
|
||||
FScopeLock Lock(&Lock_StaticMeshesToBuild);
|
||||
StaticMeshesToBuild.Add(Mesh);
|
||||
}
|
||||
|
||||
if (!FApp::IsGame())
|
||||
{
|
||||
Mesh->MarkPackageDirty();
|
||||
FAssetRegistryModule::AssetCreated(Mesh);
|
||||
}
|
||||
#endif
|
||||
//Mesh->PostEditChange(); //This doesn't seem to be required
|
||||
|
||||
return Mesh;
|
||||
}
|
||||
|
||||
void UStaticMeshConverter::GenerateMeshParams(UStaticMesh::FBuildMeshDescriptionsParams& MeshParams) const
|
||||
{
|
||||
MeshParams.bBuildSimpleCollision = BuildSimpleCollision;
|
||||
MeshParams.bCommitMeshDescription = true;
|
||||
MeshParams.bMarkPackageDirty = true;
|
||||
MeshParams.bUseHashAsGuid = false;
|
||||
|
||||
#if !WITH_EDITOR && ENGINE_MAJOR_VERSION >= 5
|
||||
MeshParams.bFastBuild = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
UBase* UStaticMeshConverter::ConvertToSpeckle_Implementation(const UObject* Object)
|
||||
{
|
||||
const UStaticMeshComponent* M = Cast<UStaticMeshComponent>(Object);
|
||||
|
||||
if(M == nullptr)
|
||||
{
|
||||
const AActor* A = Cast<AActor>(Object);
|
||||
if(A != nullptr)
|
||||
{
|
||||
M = A->FindComponentByClass<UStaticMeshComponent>();
|
||||
}
|
||||
}
|
||||
if(M == nullptr) return nullptr;
|
||||
|
||||
return MeshToSpeckle(M);
|
||||
}
|
||||
|
||||
|
||||
UBase* UStaticMeshConverter::MeshToSpeckle(const UStaticMeshComponent* Object)
|
||||
{
|
||||
return nullptr; //TODO implement ToSpeckle function
|
||||
}
|
||||
|
||||
|
||||
void UStaticMeshConverter::FinishConversion_Implementation()
|
||||
{
|
||||
|
||||
FScopeLock Lock(&Lock_StaticMeshesToBuild);
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
FFormatNamedArguments Args;
|
||||
Args.Add( TEXT("Path"), FText::FromString( GetPathName() ) );
|
||||
const FText StatusUpdate = FText::Format( LOCTEXT("BeginStaticMeshBuildingTask", "({Path}) Building"), Args );
|
||||
FScopedSlowTask Progress(StaticMeshesToBuild.Num(), StatusUpdate, DisplayBuildProgressBar);
|
||||
|
||||
Progress.MakeDialog(AllowCancelBuild);
|
||||
auto ProgressAction = [&Progress](UStaticMesh*) -> bool
|
||||
{
|
||||
Progress.EnterProgressFrame(1);
|
||||
return !Progress.ShouldCancel();
|
||||
};
|
||||
|
||||
UStaticMesh::BatchBuild(StaticMeshesToBuild, !DisplayBuildProgressBar, ProgressAction);
|
||||
#endif
|
||||
|
||||
StaticMeshesToBuild.Empty();
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,200 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Conversion/SpeckleConverterComponent.h"
|
||||
|
||||
#include "ActorEditorUtils.h"
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Conversion/Converters/AggregateConverter.h"
|
||||
#include "Conversion/Converters/BlockConverter.h"
|
||||
#include "Conversion/Converters/PointCloudConverter.h"
|
||||
#include "Conversion/Converters/StaticMeshConverter.h"
|
||||
#include "Conversion/Converters/MaterialConverter.h"
|
||||
#include "Misc/ScopedSlowTask.h"
|
||||
#include "Transports/Transport.h"
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
#include "LogSpeckle.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealModule"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
USpeckleConverterComponent::USpeckleConverterComponent()
|
||||
{
|
||||
//TODO consider using an object library for default converters
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMeshConverter> MeshConverter(TEXT("StaticMeshConverter'/SpeckleUnreal/Converters/DefaultStaticMeshConverter.DefaultStaticMeshConverter'"));
|
||||
static ConstructorHelpers::FObjectFinder<UPointCloudConverter> PointCloudConverter(TEXT("PointCloudConverter'/SpeckleUnreal/Converters/DefaultPointCloudConverter.DefaultPointCloudConverter'"));
|
||||
static ConstructorHelpers::FObjectFinder<UBlockConverter> BlockConverter(TEXT("BlockConverter'/SpeckleUnreal/Converters/DefaultBlockConverter.DefaultBlockConverter'"));
|
||||
static ConstructorHelpers::FObjectFinder<UMaterialConverter> MaterialConverter(TEXT("MaterialConverter'/SpeckleUnreal/Converters/DefaultMaterialConverter.DefaultMaterialConverter'"));
|
||||
static ConstructorHelpers::FObjectFinder<UObject> CameraConverter(TEXT("CameraConverter'/SpeckleUnreal/Converters/DefaultCameraConverter.DefaultCameraConverter'"));
|
||||
//static ConstructorHelpers::FObjectFinder<ULightConverter> LightConverter(TEXT("LightConverter'/SpeckleUnreal/Converters/DefaultLightConverter.DefaultLightConverter'"));
|
||||
|
||||
SpeckleConverter = CreateDefaultSubobject<UAggregateConverter>(TEXT("Objects Converter"));
|
||||
|
||||
SpeckleConverter->SpeckleConverters.Add(MeshConverter.Object);
|
||||
SpeckleConverter->SpeckleConverters.Add(PointCloudConverter.Object);
|
||||
SpeckleConverter->SpeckleConverters.Add(BlockConverter.Object);
|
||||
SpeckleConverter->SpeckleConverters.Add(MaterialConverter.Object);
|
||||
SpeckleConverter->SpeckleConverters.Add(CameraConverter.Object);
|
||||
//SpeckleConverter->SpeckleConverters.Add(LightConverter.Object);
|
||||
|
||||
PrimaryComponentTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
AActor* USpeckleConverterComponent::RecursivelyConvertToNative(AActor* AOwner, const UBase* Base,
|
||||
const TScriptInterface<ITransport>& LocalTransport, bool DisplayProgressBar, TArray<AActor*>& OutActors)
|
||||
{
|
||||
float ObjectsToConvert{};
|
||||
Base->TryGetDynamicNumber("totalChildrenCount", ObjectsToConvert);
|
||||
|
||||
// Progress bar
|
||||
FScopedSlowTask Progress(ObjectsToConvert + 2,
|
||||
LOCTEXT("SpeckleConvertoNative","Converting Speckle Objects to Native"), DisplayProgressBar);
|
||||
|
||||
#if WITH_EDITOR
|
||||
Progress.MakeDialog(true, false);
|
||||
#endif
|
||||
|
||||
AActor* RootActor = RecursivelyConvertToNative_Internal(AOwner, Base, LocalTransport, &Progress, OutActors);
|
||||
|
||||
FinishConversion();
|
||||
return RootActor;
|
||||
}
|
||||
|
||||
// We should convert JSON to Speckle Object Streams
|
||||
TArray<FSpeckleStream> USpeckleConverterComponent::ConvertStreamsToNative(AActor* AOwner, const UBase* Base,
|
||||
const TScriptInterface<ITransport>& LocalTransport, bool DisplayProgressBar, TArray<AActor*>& OutActors)
|
||||
{
|
||||
|
||||
return ArrayOfStreams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AActor* USpeckleConverterComponent::RecursivelyConvertToNative_Internal(AActor* AOwner, const UBase* Base,
|
||||
const TScriptInterface<ITransport>& LocalTransport,
|
||||
FSlowTask* Task,
|
||||
TArray<AActor*>& OutActors)
|
||||
{
|
||||
check(IsValid(AOwner));
|
||||
if(!IsValid(Base)) return nullptr;
|
||||
|
||||
// Convert Speckle Object
|
||||
UObject* Converted = SpeckleConverter->ConvertToNativeInternal(Base, AOwner->GetWorld());
|
||||
AttachConvertedToOwner(AOwner, Base, Converted);
|
||||
|
||||
// Handle new actors
|
||||
AActor* ConvertedAsActor = Cast<AActor>(Converted);
|
||||
AActor* NextOwner = IsValid(ConvertedAsActor) ? ConvertedAsActor : AOwner;
|
||||
if(NextOwner != AOwner)
|
||||
{
|
||||
OutActors.Add(NextOwner);
|
||||
OutActors.Append(NextOwner->Children);
|
||||
}
|
||||
|
||||
Task->EnterProgressFrame(1);
|
||||
if(Task->ShouldCancel()) return AOwner;
|
||||
|
||||
//Convert Children
|
||||
TMap<FString, TSharedPtr<FJsonValue>> PotentialChildren = Base->DynamicProperties;
|
||||
|
||||
for (const auto& Kvp : PotentialChildren)
|
||||
{
|
||||
if(Task->ShouldCancel()) break;
|
||||
|
||||
ConvertChild(Kvp.Value, AOwner, LocalTransport, Task, OutActors);
|
||||
}
|
||||
return AOwner;
|
||||
}
|
||||
|
||||
void USpeckleConverterComponent::ConvertChild(const TSharedPtr<FJsonValue> Object, AActor* AOwner,
|
||||
const TScriptInterface<ITransport>& LocalTransport, FSlowTask* Task,
|
||||
TArray<AActor*>& OutActors)
|
||||
{
|
||||
//Handle child object
|
||||
const TSharedPtr<FJsonObject>* ChildObj;
|
||||
if (Object->TryGetObject(ChildObj))
|
||||
{
|
||||
const UBase* Child = USpeckleSerializer::DeserializeBase(*ChildObj, LocalTransport);
|
||||
RecursivelyConvertToNative_Internal(AOwner, Child, LocalTransport, Task, OutActors);
|
||||
return;
|
||||
}
|
||||
|
||||
//Handle child array object
|
||||
const TArray<TSharedPtr<FJsonValue>>* ChildArr;
|
||||
if (Object->TryGetArray(ChildArr))
|
||||
{
|
||||
for (const auto v : *ChildArr)
|
||||
{
|
||||
ConvertChild(v, AOwner, LocalTransport, Task, OutActors);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void USpeckleConverterComponent::AttachConvertedToOwner(AActor* AOwner, const UBase* Base, UObject* Converted)
|
||||
{
|
||||
|
||||
// Case Actor
|
||||
{
|
||||
AActor* NativeActor = Cast<AActor>(Converted);
|
||||
if(IsValid(NativeActor))
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
{
|
||||
FString Name;
|
||||
FText _Discard;
|
||||
if( !(Base->TryGetDynamicString("name", Name) && FActorEditorUtils::ValidateActorName(FText::FromString(Name), _Discard)) )
|
||||
{
|
||||
Name = FString::Printf(TEXT("%s - %s"), *Base->SpeckleType, *Base->Id);
|
||||
}
|
||||
NativeActor->SetActorLabel(Name);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Ensure actor has a valid mobility for its owner
|
||||
if(NativeActor->HasValidRootComponent())
|
||||
{
|
||||
uint8 CurrentMobility = NativeActor->GetRootComponent()->Mobility;
|
||||
uint8 OwnerMobility = AOwner->GetRootComponent()->Mobility;
|
||||
|
||||
if(CurrentMobility < OwnerMobility)
|
||||
{
|
||||
NativeActor->GetRootComponent()->SetMobility(AOwner->GetRootComponent()->Mobility);
|
||||
}
|
||||
}
|
||||
|
||||
NativeActor->AttachToActor(AOwner, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
NativeActor->SetOwner(AOwner);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Case ActorComponent
|
||||
{
|
||||
UActorComponent* NativeComponent = Cast<UActorComponent>(Converted);
|
||||
if(IsValid(NativeComponent))
|
||||
{
|
||||
if(!AOwner->HasValidRootComponent()) AOwner->SetRootComponent(NewObject<USceneComponent>(AOwner));
|
||||
|
||||
USceneComponent* SceneComponent = Cast<USceneComponent>(Converted);
|
||||
if(IsValid(SceneComponent)) SceneComponent->SetupAttachment(AOwner->GetRootComponent());
|
||||
|
||||
NativeComponent->RegisterComponent();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void USpeckleConverterComponent::FinishConversion()
|
||||
{
|
||||
SpeckleConverter->FinishConversion_Internal();
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "LogSpeckle.h"
|
||||
#include "Logging/LogMacros.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogSpeckle);
|
||||
@@ -0,0 +1,58 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/DisplayValueElement.h"
|
||||
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Objects/Geometry/Mesh.h"
|
||||
|
||||
|
||||
TArray<FString> UDisplayValueElement::DisplayValueAliasStrings = {
|
||||
"displayValue",
|
||||
"@displayValue",
|
||||
"displayMesh"
|
||||
"@displayMesh"
|
||||
};
|
||||
|
||||
|
||||
bool UDisplayValueElement::AddDisplayValue(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
UMesh* DisplayMesh = Cast<UMesh>(USpeckleSerializer::DeserializeBase(Obj, ReadTransport));
|
||||
const bool Valid = IsValid(DisplayMesh);
|
||||
if(Valid)
|
||||
this->DisplayValue.Add(DisplayMesh);
|
||||
return Valid;
|
||||
}
|
||||
|
||||
bool UDisplayValueElement::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
//Find display values
|
||||
for(const FString& Alias : DisplayValueAliasStrings)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* SubObjectPtr;
|
||||
if (Obj->TryGetObjectField(Alias, SubObjectPtr))
|
||||
{
|
||||
AddDisplayValue(*SubObjectPtr, ReadTransport);
|
||||
DynamicProperties.Remove(Alias);
|
||||
continue;
|
||||
}
|
||||
|
||||
const TArray<TSharedPtr<FJsonValue>>* SubArrayPtr;
|
||||
if (Obj->TryGetArrayField(Alias, SubArrayPtr))
|
||||
{
|
||||
for (const auto& ArrayElement : *SubArrayPtr)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* ArraySubObjPtr;
|
||||
if (ArrayElement->TryGetObject(ArraySubObjPtr))
|
||||
{
|
||||
AddDisplayValue(*ArraySubObjPtr, ReadTransport);
|
||||
}
|
||||
}
|
||||
DynamicProperties.Remove(Alias);
|
||||
}
|
||||
}
|
||||
|
||||
return DisplayValue.Num() > 0;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Geometry/Box.h"
|
||||
|
||||
#include "Objects/Geometry/Plane.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
bool UBoxx::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
const FString BasePlanePropertyName = TEXT("basePlane");
|
||||
if (Obj->HasField(BasePlanePropertyName))
|
||||
{
|
||||
BasePlane = NewObject<UPlane>();
|
||||
if(!BasePlane->Parse(Obj->GetObjectField(BasePlanePropertyName), ReadTransport)) return false;
|
||||
DynamicProperties.Remove(BasePlanePropertyName);
|
||||
}
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "xSize", ReadTransport, XSize)) return false;
|
||||
XSize *= ScaleFactor;
|
||||
DynamicProperties.Remove("xSize");
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "ySize", ReadTransport, YSize)) return false;
|
||||
YSize *= ScaleFactor;
|
||||
DynamicProperties.Remove("ySize");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
UMesh* UBoxx::ToMesh(UObject* Outer) const
|
||||
{
|
||||
|
||||
TArray<FVector> Vertices = {
|
||||
FVector(),
|
||||
FVector(),
|
||||
FVector(),
|
||||
FVector(),
|
||||
FVector(),
|
||||
FVector(),
|
||||
};
|
||||
|
||||
TArray<int32> Faces = {
|
||||
};
|
||||
|
||||
//FMatrix transform =
|
||||
|
||||
|
||||
UMesh* Mesh = NewObject<UMesh>(Outer);
|
||||
return Mesh;
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Geometry/Mesh.h"
|
||||
|
||||
#include "Objects/Other/RenderMaterial.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
#include "Transports/Transport.h"
|
||||
|
||||
bool UMesh::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
//Parse optional Transform
|
||||
if(USpeckleObjectUtils::TryParseTransform(Obj, Transform))
|
||||
{
|
||||
Transform.ScaleTranslation(FVector(ScaleFactor));
|
||||
DynamicProperties.Remove("transform");
|
||||
}
|
||||
else
|
||||
{
|
||||
Transform = FMatrix::Identity;
|
||||
}
|
||||
|
||||
|
||||
//Parse Vertices
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> ObjectVertices = USpeckleObjectUtils::CombineChunks(Obj->GetArrayField("vertices"), ReadTransport);
|
||||
const int32 NumberOfVertices = ObjectVertices.Num() / 3;
|
||||
|
||||
Vertices.Reserve(NumberOfVertices);
|
||||
|
||||
for (size_t i = 0, j = 0; i < NumberOfVertices; i++, j += 3)
|
||||
{
|
||||
Vertices.Add(Transform.InverseTransformPosition(FVector
|
||||
(
|
||||
ObjectVertices[j].Get()->AsNumber(),
|
||||
-ObjectVertices[j + 1].Get()->AsNumber(),
|
||||
ObjectVertices[j + 2].Get()->AsNumber()
|
||||
) * ScaleFactor ));
|
||||
}
|
||||
DynamicProperties.Remove("vertices");
|
||||
}
|
||||
|
||||
//Parse Faces
|
||||
{
|
||||
const TArray<TSharedPtr<FJsonValue>> FaceVertices = USpeckleObjectUtils::CombineChunks(Obj->GetArrayField("faces"), ReadTransport);
|
||||
Faces.Reserve(FaceVertices.Num());
|
||||
for(const auto VertIndex : FaceVertices)
|
||||
{
|
||||
Faces.Add(VertIndex->AsNumber());
|
||||
}
|
||||
DynamicProperties.Remove("faces");
|
||||
}
|
||||
|
||||
//Parse TextureCoords
|
||||
{
|
||||
const TArray<TSharedPtr<FJsonValue>>* TextCoordArray;
|
||||
if(Obj->TryGetArrayField("textureCoordinates", TextCoordArray))
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> TexCoords = USpeckleObjectUtils::CombineChunks(*TextCoordArray, ReadTransport);
|
||||
|
||||
TextureCoordinates.Reserve(TexCoords.Num() / 2);
|
||||
|
||||
for (int32 i = 0; i + 1 < TexCoords.Num(); i += 2)
|
||||
{
|
||||
TextureCoordinates.Add(FVector2D
|
||||
(
|
||||
TexCoords[i].Get()->AsNumber(),
|
||||
TexCoords[i + 1].Get()->AsNumber()
|
||||
));
|
||||
}
|
||||
DynamicProperties.Remove("textureCoordinates");
|
||||
}
|
||||
}
|
||||
|
||||
//Parse VertexColors
|
||||
{
|
||||
const TArray<TSharedPtr<FJsonValue>>* ColorArray;
|
||||
if(Obj->TryGetArrayField("colors", ColorArray))
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> Colors = USpeckleObjectUtils::CombineChunks(*ColorArray, ReadTransport);
|
||||
|
||||
VertexColors.Reserve(Colors.Num());
|
||||
|
||||
for (int32 i = 0; i + 1 < Colors.Num(); i ++)
|
||||
{
|
||||
VertexColors.Add(FColor(Colors[i].Get()->AsNumber()));
|
||||
}
|
||||
DynamicProperties.Remove("colors");
|
||||
}
|
||||
}
|
||||
|
||||
//Parse Optional RenderMaterial
|
||||
if (Obj->HasField("renderMaterial"))
|
||||
{
|
||||
RenderMaterial = NewObject<URenderMaterial>();
|
||||
RenderMaterial->Parse(Obj->GetObjectField("renderMaterial"), ReadTransport);
|
||||
DynamicProperties.Remove("renderMaterial");
|
||||
}
|
||||
|
||||
AlignVerticesWithTexCoordsByIndex();
|
||||
|
||||
return Vertices.Num() > 0 && Faces.Num() > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If not already so, this method will align vertices
|
||||
* such that a vertex and its corresponding texture coordinates have the same index.
|
||||
* See "https://github.com/specklesystems/speckle-sharp/blob/main/Objects/Objects/Geometry/Mesh.cs"
|
||||
*/
|
||||
void UMesh::AlignVerticesWithTexCoordsByIndex()
|
||||
{
|
||||
if(TextureCoordinates.Num() == 0) return;
|
||||
if(TextureCoordinates.Num() == Vertices.Num()) return; //Tex-coords already aligned as expected
|
||||
|
||||
TArray<int> FacesUnique;
|
||||
FacesUnique.Reserve(Faces.Num());
|
||||
TArray<FVector> VerticesUnique;
|
||||
VerticesUnique.Reserve(TextureCoordinates.Num());
|
||||
const bool HasColor = VertexColors.Num() > 0;
|
||||
TArray<FColor> ColorsUnique;
|
||||
if(HasColor) ColorsUnique.Reserve(TextureCoordinates.Num());
|
||||
|
||||
int32 NIndex = 0;
|
||||
while(NIndex < Faces.Num())
|
||||
{
|
||||
int32 n = Faces[NIndex];
|
||||
if (n < 3) n += 3; // 0 -> 3, 1 -> 4
|
||||
|
||||
if (NIndex + n >= Faces.Num()) break; //Malformed face list
|
||||
|
||||
FacesUnique.Add(n);
|
||||
|
||||
for (int32 i = 1; i <= n; i++)
|
||||
{
|
||||
const int32 VertIndex = Faces[NIndex + i];
|
||||
const int32 NewVertIndex = VerticesUnique.Num();
|
||||
|
||||
VerticesUnique.Add(Vertices[VertIndex]);
|
||||
|
||||
if(HasColor) ColorsUnique.Add(VertexColors[NewVertIndex]);
|
||||
FacesUnique.Add(NewVertIndex);
|
||||
}
|
||||
NIndex += n + 1;
|
||||
}
|
||||
|
||||
Vertices = VerticesUnique;
|
||||
VertexColors = ColorsUnique;
|
||||
Faces = FacesUnique;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Geometry/Plane.h"
|
||||
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
bool UPlane::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "origin", ReadTransport, Origin)) return false;
|
||||
Origin *= ScaleFactor;
|
||||
DynamicProperties.Remove("origin");
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "normal", ReadTransport, Normal)) return false;
|
||||
Normal *= ScaleFactor;
|
||||
DynamicProperties.Remove("normal");
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "ydir", ReadTransport, XDir)) return false;
|
||||
XDir *= ScaleFactor;
|
||||
DynamicProperties.Remove("ydir");
|
||||
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "xdir", ReadTransport, YDir)) return false;
|
||||
YDir *= ScaleFactor;
|
||||
DynamicProperties.Remove("xdir");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Geometry/PointCloud.h"
|
||||
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
#include "Transports/Transport.h"
|
||||
|
||||
bool UPointCloud::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
//Parse Points
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> ObjectPoints = USpeckleObjectUtils::CombineChunks(Obj->GetArrayField("points"), ReadTransport);
|
||||
|
||||
Points.Reserve(ObjectPoints.Num() / 3);
|
||||
for (int32 i = 2; i < ObjectPoints.Num(); i += 3)
|
||||
{
|
||||
Points.Add(FVector
|
||||
(
|
||||
ObjectPoints[i - 2].Get()->AsNumber(),
|
||||
ObjectPoints[i - 1].Get()->AsNumber(),
|
||||
ObjectPoints[i].Get()->AsNumber()
|
||||
) * ScaleFactor);
|
||||
}
|
||||
DynamicProperties.Remove("points");
|
||||
}
|
||||
|
||||
|
||||
//Parse Colors
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> ObjectColors = USpeckleObjectUtils::CombineChunks(Obj->GetArrayField("colors"), ReadTransport);
|
||||
|
||||
Colors.Reserve(ObjectColors.Num());
|
||||
for (int32 i = 0; i < ObjectColors.Num(); i += 1)
|
||||
{
|
||||
Colors.Add( FColor(ObjectColors[i].Get()->AsNumber()) );
|
||||
}
|
||||
DynamicProperties.Remove("colors");
|
||||
}
|
||||
|
||||
//Parse Sizes
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> ObjectSizes = USpeckleObjectUtils::CombineChunks(Obj->GetArrayField("sizes"), ReadTransport);
|
||||
|
||||
Sizes.Reserve(ObjectSizes.Num());
|
||||
for (int32 i = 0; i < ObjectSizes.Num(); i += 1)
|
||||
{
|
||||
Sizes.Add( ObjectSizes[i].Get()->AsNumber() * ScaleFactor);
|
||||
}
|
||||
DynamicProperties.Remove("sizes");
|
||||
}
|
||||
|
||||
return Points.Num() >= 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "Objects/ObjectModelRegistry.h"
|
||||
|
||||
#include "Objects/Base.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
#include "UObject/UObjectIterator.h"
|
||||
|
||||
TMap<FString, TSubclassOf<UBase>> UObjectModelRegistry::TypeRegistry;
|
||||
|
||||
void UObjectModelRegistry::GenerateTypeRegistry()
|
||||
{
|
||||
//TypeRegistry.Reset();
|
||||
TypeRegistry.Empty();
|
||||
//TypeRegistry = TMap<FString, TSubclassOf<UBase>>();
|
||||
//check(TypeRegistry.IsSet());
|
||||
|
||||
//Find every class : UBase and add to Registry
|
||||
for (TObjectIterator<UClass> It; It; ++It)
|
||||
{
|
||||
const UClass* Class = *It;
|
||||
if (Class->IsChildOf(UBase::StaticClass()) &&
|
||||
!Class->HasAnyClassFlags(CLASS_Abstract))
|
||||
{
|
||||
const FString& SpeckleType = Class->GetDefaultObject<UBase>()->SpeckleType;;
|
||||
|
||||
ensureAlwaysMsgf(!TypeRegistry.Contains(SpeckleType),
|
||||
TEXT("Base class: %s conflicts with: %s for SpeckleType: %s"),
|
||||
*Class->GetName(),
|
||||
*TypeRegistry[SpeckleType]->GetName(),
|
||||
*SpeckleType);
|
||||
|
||||
TypeRegistry.Add(SpeckleType, *It);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TSubclassOf<UBase> UObjectModelRegistry::FindClosestType(const FString& SpeckleType)
|
||||
{
|
||||
FString TypeString(SpeckleType);
|
||||
TSubclassOf<UBase> Type = nullptr;
|
||||
|
||||
while(!TryGetRegisteredType(TypeString, Type))
|
||||
{
|
||||
if(!ParentType(TypeString, TypeString)) return nullptr;
|
||||
}
|
||||
|
||||
return Type;
|
||||
|
||||
}
|
||||
|
||||
bool UObjectModelRegistry::ParentType(const FString& Type, FString& NextType)
|
||||
{
|
||||
int32 DotSplitIndex;
|
||||
Type.FindLastChar('.', DotSplitIndex);
|
||||
int32 ColonSplitIndex;
|
||||
Type.FindLastChar(':', ColonSplitIndex);
|
||||
const int32 SplitIndex = FGenericPlatformMath::Max(DotSplitIndex, ColonSplitIndex);
|
||||
|
||||
if(SplitIndex <= 0) return false;
|
||||
|
||||
NextType = Type.Left(SplitIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
TSubclassOf<UBase> UObjectModelRegistry::GetRegisteredType(const FString& SpeckleType)
|
||||
{
|
||||
TSubclassOf<UBase> Type = nullptr;
|
||||
TryGetRegisteredType(SpeckleType, Type);
|
||||
return Type;
|
||||
}
|
||||
|
||||
bool UObjectModelRegistry::TryGetRegisteredType(const FString& SpeckleType, TSubclassOf<UBase>& OutType)
|
||||
{
|
||||
if(TypeRegistry.Num() == 0) GenerateTypeRegistry();
|
||||
|
||||
|
||||
const bool Contains = TypeRegistry.Contains(SpeckleType);
|
||||
if(Contains)
|
||||
{
|
||||
OutType = *TypeRegistry.Find(SpeckleType);
|
||||
}
|
||||
return Contains;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Other/BlockInstance.h"
|
||||
#include "LogSpeckle.h"
|
||||
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
#include "Transports/Transport.h"
|
||||
|
||||
bool UBlockInstance::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
//Transform
|
||||
if(!USpeckleObjectUtils::TryParseTransform(Obj, Transform)) return false;
|
||||
Transform.ScaleTranslation(FVector(ScaleFactor));
|
||||
DynamicProperties.Remove("Transform");
|
||||
|
||||
|
||||
//Geometries
|
||||
const TSharedPtr<FJsonObject>* BlockDefinitionPtr;
|
||||
if(!Obj->TryGetObjectField("blockDefinition", BlockDefinitionPtr)) return false;
|
||||
|
||||
const FString RefID = BlockDefinitionPtr->operator->()->GetStringField("referencedId");
|
||||
const TSharedPtr<FJsonObject> BlockDefinition = ReadTransport->GetSpeckleObject(RefID);
|
||||
|
||||
if(BlockDefinition->TryGetStringField("name", Name)) DynamicProperties.Remove("Name");
|
||||
|
||||
const auto Geometries = BlockDefinition->GetArrayField("geometry");
|
||||
|
||||
if(Geometries.Num() <= 0)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Block definition has no geometry. id: %s"), *RefID)
|
||||
return false;
|
||||
}
|
||||
|
||||
for(const auto Geo : Geometries)
|
||||
{
|
||||
const TSharedPtr<FJsonObject> MeshReference = Geo->AsObject();
|
||||
const FString ChildId = MeshReference->GetStringField("referencedId");
|
||||
|
||||
if(ReadTransport->HasObject(ChildId))
|
||||
{
|
||||
UBase* Child = USpeckleSerializer::DeserializeBase(ReadTransport->GetSpeckleObject(ChildId), ReadTransport);
|
||||
if(IsValid(Child))
|
||||
Geometry.Add(Child);
|
||||
}
|
||||
else UE_LOG(LogSpeckle, Warning, TEXT("Block definition references an unknown object id: %s"), *ChildId)
|
||||
}
|
||||
DynamicProperties.Remove("geometry");
|
||||
|
||||
// Intentionally don't remove blockDefinition from dynamic properties,
|
||||
// because we want the converter to create the child geometries for us
|
||||
//DynamicProperties.Remove("blockDefinition");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright AEC Systems Ltd
|
||||
|
||||
|
||||
#include "Objects/Other/View3D.h"
|
||||
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
bool UView3D::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
const float ScaleFactor = USpeckleObjectUtils::ParseScaleFactor(Units);
|
||||
|
||||
// Parse optional Name property
|
||||
if(Obj->TryGetStringField("name", Name)) DynamicProperties.Remove("name");
|
||||
|
||||
// Parse Origin
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "origin", ReadTransport, Origin)) return false;
|
||||
Origin *= ScaleFactor;
|
||||
DynamicProperties.Remove("origin");
|
||||
|
||||
// Parse UpDirection
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "upDirection", ReadTransport, UpDirection)) return false;
|
||||
UpDirection *= ScaleFactor;
|
||||
DynamicProperties.Remove("upDirection");
|
||||
|
||||
// Parse ForwardDirection
|
||||
if(!USpeckleObjectUtils::ParseVectorProperty(Obj, "forwardDirection", ReadTransport, ForwardDirection)) return false;
|
||||
ForwardDirection *= ScaleFactor;
|
||||
DynamicProperties.Remove("forwardDirection");
|
||||
|
||||
// Parse IsOrthogonal
|
||||
if(!Obj->TryGetBoolField("isOrthogonal", IsOrthogonal)) return false;
|
||||
DynamicProperties.Remove("isOrthogonal");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Objects/Utils/SpeckleObjectUtils.h"
|
||||
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Engine/World.h"
|
||||
#include "Objects/Geometry/Mesh.h"
|
||||
#include "Transports/Transport.h"
|
||||
|
||||
|
||||
TArray<TSharedPtr<FJsonValue>> USpeckleObjectUtils::CombineChunks(const TArray<TSharedPtr<FJsonValue>>& ArrayField, const TScriptInterface<ITransport> Transport)
|
||||
{
|
||||
TArray<TSharedPtr<FJsonValue>> ObjectPoints;
|
||||
|
||||
for(int32 i = 0; i < ArrayField.Num(); i++)
|
||||
{
|
||||
FString Index;
|
||||
if(ArrayField[i]->AsObject()->TryGetStringField("referencedId", Index))
|
||||
{
|
||||
if(!ensureAlwaysMsgf(Transport->HasObject(Index), TEXT("Failed to Dechunk array, Could not find chunk %s in transport"), *Index))
|
||||
continue;
|
||||
|
||||
const auto Chunk = Transport->GetSpeckleObject(Index)->GetArrayField("data");;
|
||||
ObjectPoints.Append(Chunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ArrayField; //Array was never chunked to begin with
|
||||
}
|
||||
}
|
||||
return ObjectPoints;
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::ResolveReference(const TSharedPtr<FJsonObject> Object, const TScriptInterface<ITransport> Transport, TSharedPtr<FJsonObject>& OutObject)
|
||||
{
|
||||
FString SpeckleType;
|
||||
FString ReferenceID;
|
||||
|
||||
if (Object->TryGetStringField("speckle_type", SpeckleType)
|
||||
&& SpeckleType == "reference"
|
||||
&& Object->TryGetStringField("referencedId",ReferenceID))
|
||||
{
|
||||
check(Transport != nullptr && Transport.GetObject() != nullptr)
|
||||
|
||||
OutObject = Transport->GetSpeckleObject(ReferenceID);
|
||||
return OutObject != nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float USpeckleObjectUtils::ParseScaleFactor(const FString& UnitsString)
|
||||
{
|
||||
static const auto ParseUnits = [](const FString& LUnits) -> float
|
||||
{
|
||||
if (LUnits == "millimeters" || LUnits == "millimeter" || LUnits == "millimetres" || LUnits == "millimetre" || LUnits == "mm")
|
||||
return 0.1;
|
||||
if (LUnits == "centimeters" || LUnits == "centimeter" ||LUnits == "centimetres" || LUnits == "centimetre" || LUnits == "cm")
|
||||
return 1;
|
||||
if (LUnits == "meters" || LUnits == "meter" || LUnits == "metres" || LUnits == "metre" || LUnits == "m")
|
||||
return 100;
|
||||
if (LUnits == "kilometers" || LUnits == "kilometres" || LUnits == "km")
|
||||
return 100000;
|
||||
|
||||
if (LUnits == "inches" || LUnits == "inch" || LUnits == "in")
|
||||
return 2.54;
|
||||
if (LUnits == "feet" || LUnits == "foot" || LUnits == "ft")
|
||||
return 30.48;
|
||||
if (LUnits == "yards" || LUnits == "yard"|| LUnits == "yd")
|
||||
return 91.44;
|
||||
if (LUnits == "miles" || LUnits == "mile" || LUnits == "mi")
|
||||
return 160934.4;
|
||||
|
||||
return 100;
|
||||
};
|
||||
|
||||
return ParseUnits(UnitsString.ToLower()); // * WorldToCentimeters; //TODO take into account world units
|
||||
}
|
||||
|
||||
FTransform USpeckleObjectUtils::CreateTransform(UPARAM(ref) const FMatrix& TransformMatrix)
|
||||
{
|
||||
FTransform Transform(TransformMatrix);
|
||||
Transform.ScaleTranslation(FVector(1,-1,1));
|
||||
FVector Rot = Transform.GetRotation().Euler();
|
||||
FVector NewRot(-Rot.X, Rot.Y, -Rot.Z);
|
||||
Transform.SetRotation(FQuat::MakeFromEuler(NewRot));
|
||||
return Transform;
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::TryParseTransform(const TSharedPtr<FJsonObject> SpeckleObject, FMatrix& OutMatrix)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* TransformObject;
|
||||
const TArray<TSharedPtr<FJsonValue>>* TransformData;
|
||||
|
||||
if(SpeckleObject->TryGetArrayField("transform", TransformData)) //Handle transform as array
|
||||
{ }
|
||||
else if(SpeckleObject->TryGetObjectField("transform", TransformObject)
|
||||
&& (*TransformObject)->TryGetArrayField("value", TransformData)) //Handle transform as object
|
||||
{ }
|
||||
else return false;
|
||||
|
||||
FMatrix TransformMatrix;
|
||||
for(int32 Row = 0; Row < 4; Row++)
|
||||
for(int32 Col = 0; Col < 4; Col++)
|
||||
{
|
||||
TransformMatrix.M[Row][Col] = TransformData->operator[](Row * 4 + Col)->AsNumber();
|
||||
}
|
||||
OutMatrix = TransformMatrix.GetTransposed();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::ParseVectorProperty(const TSharedPtr<FJsonObject> Base, const FString& PropertyName,
|
||||
const TScriptInterface<ITransport> ReadTransport, FVector& OutObject)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* OriginObject;
|
||||
if(Base->TryGetObjectField(PropertyName, OriginObject)
|
||||
&& ParseVector(*OriginObject, ReadTransport, OutObject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::ParseVector(const TSharedPtr<FJsonObject> Object,
|
||||
const TScriptInterface<ITransport> Transport, FVector& OutObject)
|
||||
{
|
||||
if(!ensure(Object != nullptr)) return false;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!ResolveReference(Object, Transport, Obj)) Obj = Object;
|
||||
|
||||
double x = 0, y = 0, z = 0;
|
||||
|
||||
if(!(Obj->TryGetNumberField("x", x)
|
||||
&& Obj->TryGetNumberField("y", y)
|
||||
&& Obj->TryGetNumberField("z", z))) return false;
|
||||
|
||||
OutObject = FVector(x,y,z);
|
||||
//return true;
|
||||
|
||||
UMesh* Mesh;
|
||||
return ParseSpeckleObject<UMesh>(Obj, Transport, Mesh);
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::ParseIntervalProperty(const TSharedPtr<FJsonObject> Base, const FString& PropertyName,
|
||||
const TScriptInterface<ITransport> ReadTransport, FVector2f<float>& OutObject)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* OriginObject;
|
||||
if(Base->TryGetObjectField(PropertyName, OriginObject)
|
||||
&& ParseInterval(*OriginObject, ReadTransport, OutObject))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool USpeckleObjectUtils::ParseInterval(const TSharedPtr<FJsonObject> Object,
|
||||
const TScriptInterface<ITransport> Transport, FVector2f& OutObject)
|
||||
{
|
||||
if(!ensure(Object != nullptr)) return false;
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!ResolveReference(Object, Transport, Obj)) Obj = Object;
|
||||
|
||||
double x = 0, y = 0, z = 0;
|
||||
|
||||
if(!(Obj->TryGetNumberField("start", x)
|
||||
&& Obj->TryGetNumberField("end", y)) return false;
|
||||
|
||||
OutObject = FVector2f(x,y,z);
|
||||
//return true;
|
||||
|
||||
UMesh* Mesh;
|
||||
return ParseSpeckleObject<UMesh>(Obj, Transport, Mesh);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename TBase>
|
||||
bool USpeckleObjectUtils::ParseSpeckleObject(const TSharedPtr<FJsonObject> Object,
|
||||
const TScriptInterface<ITransport> Transport, TBase*& OutObject)
|
||||
{
|
||||
static_assert(TIsDerivedFrom<TBase, UBase>::IsDerived, "Type TBase must inherit UBase");
|
||||
|
||||
TSharedPtr<FJsonObject> Obj;
|
||||
if(!ResolveReference(Object, Transport, Obj)) Obj = Object;
|
||||
|
||||
UBase* b = USpeckleSerializer::DeserializeBase(Object, Transport);
|
||||
OutObject = Cast<TBase>(b);
|
||||
return OutObject == nullptr;
|
||||
}
|
||||
|
||||
|
||||
AActor* USpeckleObjectUtils::SpawnActorInWorld(const TSubclassOf<AActor> Class, UWorld* World, const FTransform& Transform)
|
||||
{
|
||||
return World->SpawnActor(Class, &Transform, FActorSpawnParameters());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "SpeckleUnreal.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealModule"
|
||||
|
||||
void FSpeckleUnrealModule::StartupModule()
|
||||
{
|
||||
// This code will execute after your module is loaded into memory.
|
||||
// The exact timing is specified in the .uplugin file per-module
|
||||
}
|
||||
|
||||
void FSpeckleUnrealModule::ShutdownModule()
|
||||
{
|
||||
// This function may be called during shutdown to clean up your module.
|
||||
// For modules that support dynamic reloading, we call this function before unloading the module.
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FSpeckleUnrealModule, SpeckleUnreal)
|
||||
@@ -0,0 +1,172 @@
|
||||
#include "SpeckleUnrealManager.h"
|
||||
|
||||
#include "API/Operations/ReceiveOperation.h"
|
||||
|
||||
#include "Transports/MemoryTransport.h"
|
||||
#include "Transports/ServerTransport.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "API/SpeckleSerializer.h"
|
||||
#include "Conversion/SpeckleConverterComponent.h"
|
||||
#include "Misc/ScopedSlowTask.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Mixpanel.h"
|
||||
#include "Engine/Engine.h"
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealModule"
|
||||
|
||||
|
||||
// Sets default values
|
||||
ASpeckleUnrealManager::ASpeckleUnrealManager()
|
||||
{
|
||||
SetRootComponent(CreateDefaultSubobject<USceneComponent>(TEXT("Root")));
|
||||
RootComponent->SetRelativeScale3D(FVector(1,1,1));
|
||||
RootComponent->SetMobility(EComponentMobility::Static);
|
||||
|
||||
// Convert JSON to object models
|
||||
Converter = CreateDefaultSubobject<USpeckleConverterComponent>(FName("Converter"));
|
||||
|
||||
KeepCache = true;
|
||||
DisplayProgressBar = true;
|
||||
ServerUrl = "https://speckle.xyz";
|
||||
}
|
||||
|
||||
// Begin Play function (Receive)
|
||||
void ASpeckleUnrealManager::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if(ImportAtRuntime) Receive();
|
||||
}
|
||||
|
||||
// Start the Receive process
|
||||
void ASpeckleUnrealManager::Receive()
|
||||
{
|
||||
DeleteObjects();
|
||||
|
||||
// Trim parameters
|
||||
ServerUrl.TrimEndInline();
|
||||
while(ServerUrl.RemoveFromEnd("/")) { }
|
||||
StreamID.TrimEndInline();
|
||||
ObjectID.TrimEndInline();
|
||||
AuthToken.TrimEndInline();
|
||||
|
||||
// Analytics
|
||||
FAnalytics::TrackEvent(
|
||||
"unknown",
|
||||
"unknown",
|
||||
"NodeRun",
|
||||
TMap<FString, FString> {
|
||||
{"name", StaticClass()->GetName() },
|
||||
{"worldType", FString::FromInt(GetWorld()->WorldType)}}
|
||||
);
|
||||
|
||||
// Clear cache
|
||||
if(!KeepCache && LocalObjectCache.GetObjectRef() != nullptr)
|
||||
{
|
||||
LocalObjectCache.GetObjectRef()->ConditionalBeginDestroy();
|
||||
LocalObjectCache = UMemoryTransport::CreateEmptyMemoryTransport();
|
||||
}
|
||||
|
||||
// Probably a duplication
|
||||
if(LocalObjectCache.GetObjectRef() == nullptr)
|
||||
{
|
||||
LocalObjectCache = UMemoryTransport::CreateEmptyMemoryTransport();
|
||||
}
|
||||
|
||||
// Debug message
|
||||
FString Message = FString::Printf(TEXT("Fetching Objects from Speckle Server: %s"), *ServerUrl);
|
||||
PrintMessage(Message);
|
||||
|
||||
// Error delegate
|
||||
FTransportErrorDelegate ErrorDelegate;
|
||||
ErrorDelegate.BindUObject(this, &ASpeckleUnrealManager::HandleError);
|
||||
|
||||
// Complete delegate
|
||||
FTransportCopyObjectCompleteDelegate CompleteDelegate;
|
||||
CompleteDelegate.BindUObject(this, &ASpeckleUnrealManager::HandleReceive, DisplayProgressBar);
|
||||
|
||||
// Create a server transport
|
||||
UServerTransport* ServerTransport = UServerTransport::CreateServerTransport(ServerUrl,StreamID,AuthToken);
|
||||
|
||||
// Receive
|
||||
ServerTransport->CopyObjectAndChildren(ObjectID, LocalObjectCache, CompleteDelegate, ErrorDelegate);
|
||||
}
|
||||
|
||||
|
||||
// Handle Received JSON
|
||||
void ASpeckleUnrealManager::HandleReceive(TSharedPtr<FJsonObject> RootObject, bool DisplayProgress)
|
||||
{
|
||||
if(RootObject == nullptr) return;
|
||||
|
||||
// Create a Base Deserialization Object Model
|
||||
const UBase* Res = USpeckleSerializer::DeserializeBase(RootObject, LocalObjectCache);
|
||||
|
||||
if(IsValid(Res))
|
||||
{
|
||||
// Start conversion
|
||||
Converter->RecursivelyConvertToNative(this, Res, LocalObjectCache, DisplayProgress, Actors);
|
||||
|
||||
// Finished Conversion - show debug message
|
||||
FString Message = FString::Printf(TEXT("Converted %d Actors"), Actors.Num());
|
||||
PrintMessage(Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Object id from Json
|
||||
FString Id;
|
||||
|
||||
// Try to get JSON id field
|
||||
RootObject->TryGetStringField("id", Id);
|
||||
|
||||
// Debug message for error wrt to id
|
||||
FString Message = FString::Printf(TEXT("Failed to deserialise root object: %s"), *Id);
|
||||
|
||||
// Print Message
|
||||
HandleError(Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Error handler just prints a debug message
|
||||
void ASpeckleUnrealManager::HandleError(FString& Message)
|
||||
{
|
||||
PrintMessage(Message, true);
|
||||
}
|
||||
|
||||
// Print debug message
|
||||
void ASpeckleUnrealManager::PrintMessage(FString& Message, bool IsError) const
|
||||
{
|
||||
// Show at Console log: "Error" or just "Log" message (Errors are shown in red in output console)
|
||||
if(IsError)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Error, TEXT("%s"), *Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogSpeckle, Log, TEXT("%s"), *Message);
|
||||
}
|
||||
|
||||
// Error as a debug message
|
||||
FColor Color = IsError? FColor::Red : FColor::Green;
|
||||
GEngine->AddOnScreenDebugMessage(0, 5.0f, Color, Message);
|
||||
}
|
||||
|
||||
// Delete Actors containing all the 3D models
|
||||
void ASpeckleUnrealManager::DeleteObjects()
|
||||
{
|
||||
// If still converting, terminate process
|
||||
Converter->FinishConversion();
|
||||
|
||||
// Destroy actors
|
||||
for (AActor* a : Actors)
|
||||
{
|
||||
if(IsValid(a)) a->Destroy();
|
||||
}
|
||||
|
||||
Actors.Empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#include "Misc/AutomationTest.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Transports/MemoryTransport.h"
|
||||
|
||||
|
||||
#if WITH_DEV_AUTOMATION_TESTS
|
||||
|
||||
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMemoryTransportTest, "SpeckleUnreal.Transports.MemoryTransport", EAutomationTestFlags::EditorContext | EAutomationTestFlags::SmokeFilter)
|
||||
|
||||
|
||||
bool FMemoryTransportTest::RunTest(const FString& Parameters)
|
||||
{
|
||||
UMemoryTransport* Transport = UMemoryTransport::CreateEmptyMemoryTransport();
|
||||
// Test Construction
|
||||
{
|
||||
TestNotNull(TEXT("Constructed object"), Transport);
|
||||
TestTrue(TEXT("Constructed object is valid"), IsValid(Transport));
|
||||
}
|
||||
|
||||
TSharedPtr<FJsonObject> MockObj = MakeShareable(new FJsonObject());
|
||||
FString TestId = TEXT("testidlalalala");
|
||||
FString TestPayloadName = TEXT("Playload");
|
||||
FString TestPayload = TEXT("MyPayloadValue!");
|
||||
MockObj->SetStringField(TestPayloadName, TestPayload);
|
||||
|
||||
// Test Save
|
||||
{
|
||||
Transport->SaveObject(TestId, MockObj);
|
||||
TestTrue(TEXT("Transport with save object to HasObject"), Transport->HasObject(TestId));
|
||||
|
||||
auto Value = Transport->GetSpeckleObject(TestId);
|
||||
TestNotNull(TEXT("Return of getting saved object"), Value.Get());
|
||||
TestEqual(TEXT("Return of getting saved object"), Value, MockObj);
|
||||
TestTrue(TEXT("Returned object to have payload"), Value->HasField(TestPayloadName));
|
||||
TestEqual(TEXT("Returned object's playload"), Value->GetStringField(TestPayloadName), TestPayload);
|
||||
}
|
||||
|
||||
// Test Ids are missing
|
||||
{
|
||||
TArray<FString> MissingIds = {
|
||||
TEXT("NoObjectsWithThisId"),
|
||||
TEXT("testidla"),
|
||||
TEXT("testidlalalalaextrala"),
|
||||
TEXT("testidrararara"),
|
||||
TEXT(""),
|
||||
};
|
||||
|
||||
for(const FString& Id : MissingIds)
|
||||
{
|
||||
TestFalse(TEXT("transport has unknown id -") + Id, Transport->HasObject(Id));
|
||||
auto ValueM = Transport->GetSpeckleObject(Id);
|
||||
TestNull(TEXT("return of unknown id -") + Id, ValueM.Get());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#include "Misc/AutomationTest.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Transports/ServerTransport.h"
|
||||
|
||||
|
||||
#if WITH_DEV_AUTOMATION_TESTS
|
||||
|
||||
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FServerTransportTest, "SpeckleUnreal.Transports.ServerTransport", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)
|
||||
|
||||
|
||||
bool FServerTransportTest::RunTest(const FString& Parameters)
|
||||
{
|
||||
FString ServerUrl = TEXT("https://example.com");
|
||||
FString StreamId = TEXT("1234");
|
||||
FString Token = TEXT("MyAuthToken");
|
||||
auto Transport = UServerTransport::CreateServerTransport(ServerUrl, StreamId, Token);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Transports/MemoryTransport.h"
|
||||
#include "LogSpeckle.h"
|
||||
|
||||
bool UMemoryTransport::HasObject(const FString& ObjectId) const
|
||||
{
|
||||
return SpeckleObjects.Contains(ObjectId);
|
||||
}
|
||||
|
||||
|
||||
TSharedPtr<FJsonObject> UMemoryTransport::GetSpeckleObject(const FString& ObjectId) const
|
||||
{
|
||||
return SpeckleObjects.FindRef(ObjectId);
|
||||
}
|
||||
|
||||
void UMemoryTransport::SaveObject(const FString& ObjectId, const TSharedPtr<FJsonObject> SerializedObject)
|
||||
{
|
||||
SpeckleObjects.Add(ObjectId, SerializedObject);
|
||||
UE_LOG(LogSpeckle, Log, TEXT("-----------> ADDED <-------------- %d"), SpeckleObjects.Num());
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Transports/ServerTransport.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "Mixpanel.h"
|
||||
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "HttpModule.h"
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "Policies/CondensedJsonPrintPolicy.h"
|
||||
|
||||
|
||||
TSharedPtr<FJsonObject> UServerTransport::GetSpeckleObject(const FString& ObjectId) const
|
||||
{
|
||||
unimplemented();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UServerTransport::SaveObject(const FString& ObjectId, const TSharedPtr<FJsonObject> SerializedObject)
|
||||
{
|
||||
unimplemented(); //TODO implement
|
||||
}
|
||||
|
||||
bool UServerTransport::HasObject(const FString& ObjectId) const
|
||||
{
|
||||
unimplemented(); //TODO implement
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse Root JSON
|
||||
void UServerTransport::HandleRootObjectResponse(const FString& RootObjSerialized,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FString& ObjectId) const
|
||||
{
|
||||
TSharedPtr<FJsonObject> RootObj;
|
||||
if(!LoadJson(RootObjSerialized, RootObj))
|
||||
{
|
||||
FString Message = FString::Printf( TEXT("A Root Object %s was recieved but was invalid and could not be deserialied"), *ObjectId);
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
TargetTransport->SaveObject(ObjectId, RootObj);
|
||||
|
||||
// Find children are not already in the target transport
|
||||
const auto Closures = RootObj->GetObjectField("__closure")->Values;
|
||||
|
||||
TArray<FString> ChildrenIds;
|
||||
Closures.GetKeys(ChildrenIds);
|
||||
TArray<FString> NewChildrenIds;
|
||||
for(const FString& Id : ChildrenIds)
|
||||
{
|
||||
if(TargetTransport->HasObject(Id)) continue;
|
||||
|
||||
NewChildrenIds.Add(Id);
|
||||
}
|
||||
|
||||
|
||||
FetchChildren(TargetTransport, ObjectId, NewChildrenIds);
|
||||
}
|
||||
|
||||
|
||||
// Create HTTP Request for Commit Root objects (only ids of children)
|
||||
void UServerTransport::CopyObjectAndChildren(const FString& ObjectId,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FTransportCopyObjectCompleteDelegate& OnCompleteAction,
|
||||
const FTransportErrorDelegate& OnErrorAction)
|
||||
{
|
||||
this->OnComplete = OnCompleteAction;
|
||||
this->OnError = OnErrorAction;
|
||||
|
||||
// Create Request for Root Object
|
||||
const FHttpRequestRef Request = FHttpModule::Get().CreateRequest();
|
||||
const FString Endpoint = FString::Printf(TEXT("%s/objects/%s/%s/single"), *ServerUrl, *StreamId, *ObjectId);
|
||||
Request->SetVerb("GET");
|
||||
Request->SetURL(Endpoint);
|
||||
Request->SetHeader("Accept", TEXT("text/plain"));
|
||||
Request->SetHeader("Authorization", "Bearer " + AuthToken);
|
||||
|
||||
// Response Callback
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
if(!bWasSuccessful)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request for root object at %s was unsuccessful: %s"), *Response->GetURL(), *Response->GetContentAsString());
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
const int32 ResponseCode = Response->GetResponseCode();
|
||||
if (ResponseCode != 200)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request for root object at %s failed with HTTP response %d"), *Response->GetURL(), ResponseCode);
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleRootObjectResponse(Response->GetContentAsString(), TargetTransport, ObjectId);
|
||||
};
|
||||
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
// Send request
|
||||
const bool RequestSent = Request->ProcessRequest();
|
||||
|
||||
if(!RequestSent)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request for root object at %s failed: \nHTTP request failed to start"), *Endpoint);
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
UE_LOG(LogSpeckle, Verbose, TEXT("GET Request sent for root object at %s, awaiting response"), *Endpoint );
|
||||
FAnalytics::TrackEvent("unknown", ServerUrl, "Receive");
|
||||
}
|
||||
|
||||
// Fetch Children JSON and parse it
|
||||
void UServerTransport::FetchChildren(TScriptInterface<ITransport> TargetTransport, const FString& ObjectId,
|
||||
const TArray<FString>& ChildrenIds, int32 CStart) const
|
||||
{
|
||||
// Check if all children have been fetched
|
||||
if(ChildrenIds.Num() <= CStart)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Log, TEXT("----------->PJSON < CSTART <-----------"));
|
||||
ensureAlwaysMsgf(this->OnComplete.ExecuteIfBound(TargetTransport->GetSpeckleObject(ObjectId)),
|
||||
TEXT("Complete handler was not bound properly"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Assemble list of ids to ask for in this request
|
||||
// We want to avoid making requests too large
|
||||
const int32 CEnd = FGenericPlatformMath::Min(ChildrenIds.Num(), CStart + MaxNumberOfObjectsPerRequest);
|
||||
FString ChildrenIdsString;
|
||||
{
|
||||
auto Writer = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&ChildrenIdsString);
|
||||
Writer->WriteArrayStart();
|
||||
for (int32 i = CStart; i < CEnd; i++)
|
||||
{
|
||||
Writer->WriteValue(ChildrenIds[i]);
|
||||
}
|
||||
Writer->WriteArrayEnd();
|
||||
Writer->Close();
|
||||
}
|
||||
|
||||
FString Body;
|
||||
{
|
||||
auto Writer = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&Body);
|
||||
Writer->WriteObjectStart();
|
||||
Writer->WriteValue(TEXT("objects"), ChildrenIdsString);
|
||||
Writer->WriteObjectEnd();
|
||||
Writer->Close();
|
||||
}
|
||||
|
||||
// Create Request
|
||||
const FHttpRequestRef Request = FHttpModule::Get().CreateRequest();
|
||||
{
|
||||
const FString EndPoint = FString::Printf(TEXT("%s/api/getobjects/%s"), *ServerUrl, *StreamId);
|
||||
Request->SetVerb("POST");
|
||||
Request->SetURL(EndPoint);
|
||||
Request->SetHeader("Accept", TEXT("text/plain"));
|
||||
Request->SetHeader("Authorization", "Bearer " + AuthToken);
|
||||
Request->SetHeader("Content-Type", "application/json");
|
||||
Request->SetContentAsString(Body);
|
||||
}
|
||||
|
||||
// Response Callback
|
||||
auto ResponseHandler = [=](FHttpRequestPtr, FHttpResponsePtr Response, bool bWasSuccessful) mutable
|
||||
{
|
||||
// Any Fail
|
||||
if(!bWasSuccessful)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Request for children of root object %s/%s failed: %s"),
|
||||
*StreamId, *ObjectId, *Response->GetContentAsString());
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Any HTTP Fail
|
||||
const int32 ResponseCode = Response->GetResponseCode();
|
||||
if (ResponseCode != 200)
|
||||
{
|
||||
FString Message = FString::Printf(
|
||||
TEXT("Request for children of root object %s/%s failed:\nHTTP response %d"),
|
||||
*StreamId, *ObjectId, ResponseCode);
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Success: Start parsing
|
||||
TArray<FString> Lines;
|
||||
const int32 LineCount = SplitLines(Response->GetContentAsString(), Lines);
|
||||
|
||||
UE_LOG(LogSpeckle, Verbose, TEXT("Parsing %d downloaded objects..."), LineCount)
|
||||
|
||||
// Warning: Less objects then expected
|
||||
if(LineCount != CEnd - CStart)
|
||||
{
|
||||
UE_LOG(LogSpeckle, Warning, TEXT("Requested %d objects, but received %d"), CEnd - CStart, LineCount);
|
||||
}
|
||||
|
||||
// Load JSON as objects
|
||||
for (const FString& Line : Lines)
|
||||
{
|
||||
FString Id, ObjectJson;
|
||||
if (!Line.Split("\t", &Id, &ObjectJson))
|
||||
continue;
|
||||
|
||||
TSharedPtr<FJsonObject> JsonObject;
|
||||
if(!LoadJson(ObjectJson, JsonObject)) continue;
|
||||
|
||||
TargetTransport->SaveObject(Id, JsonObject);
|
||||
}
|
||||
|
||||
UE_LOG(LogSpeckle, Log, TEXT("Processed %d/%d Child objects"), CEnd, ChildrenIds.Num())
|
||||
|
||||
//Iterate again for any missing children
|
||||
FetchChildren(TargetTransport, ObjectId, ChildrenIds, CEnd);
|
||||
};
|
||||
|
||||
Request->OnProcessRequestComplete().BindLambda(ResponseHandler);
|
||||
|
||||
// Send request for children
|
||||
const bool RequestSent = Request->ProcessRequest();
|
||||
|
||||
if(!RequestSent)
|
||||
{
|
||||
FString Message = FString::Printf(TEXT("Failed to fetch children of root object %s/%s:\nHTTP request failed to start"), *StreamId, *ObjectId);
|
||||
InvokeOnError(Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UE_LOG(LogSpeckle, Verbose, TEXT("Requesting %d child objects"), CEnd - CStart);
|
||||
}
|
||||
|
||||
|
||||
void UServerTransport::InvokeOnError(FString& Message) const
|
||||
{
|
||||
ensureAlwaysMsgf(this->OnError.ExecuteIfBound(Message), TEXT("ServerTransport: Unhandled error - %s"), *Message);
|
||||
}
|
||||
|
||||
int32 UServerTransport::SplitLines(const FString& Content, TArray<FString>& OutLines)
|
||||
{
|
||||
int32 LineCount = 0;
|
||||
for (const TCHAR* ptr = *Content; *ptr; ptr++)
|
||||
if (*ptr == '\n')
|
||||
LineCount++;
|
||||
OutLines.Reserve(LineCount);
|
||||
Content.ParseIntoArray(OutLines, TEXT("\n"), true);
|
||||
return LineCount;
|
||||
}
|
||||
|
||||
bool UServerTransport::LoadJson(const FString& StringJson, TSharedPtr<FJsonObject>& OutJsonObject)
|
||||
{
|
||||
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(StringJson);
|
||||
return FJsonSerializer::Deserialize(Reader, OutJsonObject);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
#pragma once
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
|
||||
struct FSpeckleStream;
|
||||
struct FSpeckleBranch;
|
||||
struct FSpeckleCommit;
|
||||
struct FSpeckleGlobals;
|
||||
struct FSpeckleUser;
|
||||
|
||||
DECLARE_DELEGATE_OneParam(FErrorDelegate, const FString&);
|
||||
DECLARE_DELEGATE_OneParam(FFetchStreamDelegate, const TArray<FSpeckleStream>&);
|
||||
DECLARE_DELEGATE_OneParam(FFetchBranchDelegate, const TArray<FSpeckleBranch>&);
|
||||
DECLARE_DELEGATE_OneParam(FFetchCommitDelegate, const TArray<FSpeckleCommit>&);
|
||||
DECLARE_DELEGATE_OneParam(FFetchGlobalsDelegate, const FSpeckleGlobals&);
|
||||
DECLARE_DELEGATE_OneParam(FFetchUserDelegate, const FSpeckleUser&);
|
||||
|
||||
/**
|
||||
* C++ wrapper for GraphQL requests
|
||||
* See Operations to use with blueprint
|
||||
*/
|
||||
class FClientAPI
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
static void StreamsGet( const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const int32 Limit,
|
||||
const FFetchStreamDelegate OnCompleteAction,
|
||||
const FErrorDelegate OnErrorAction);
|
||||
|
||||
static void StreamGetBranches( const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const FString& StreamId,
|
||||
const int32 Limit,
|
||||
const FFetchBranchDelegate OnCompleteAction,
|
||||
const FErrorDelegate OnErrorAction);
|
||||
|
||||
static void StreamGetCommits( const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const FString& StreamId,
|
||||
const FString& BranchName,
|
||||
const int32 Limit,
|
||||
const FFetchCommitDelegate OnCompleteAction,
|
||||
const FErrorDelegate OnErrorAction);
|
||||
|
||||
static void FetchGlobals( const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const FString& StreamId,
|
||||
const FString& ReferencedObjectId,
|
||||
const FFetchGlobalsDelegate OnCompleteAction,
|
||||
const FErrorDelegate OnErrorAction);
|
||||
|
||||
static void FetchUserData( const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const FFetchUserDelegate OnCompleteAction,
|
||||
const FErrorDelegate OnErrorAction);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Utility functions
|
||||
|
||||
static FHttpRequestRef CreateGraphQLRequest(const FString& ServerUrl, FString AuthToken, const FString& PostPayload,
|
||||
const FString& Encoding = TEXT("gzip"));
|
||||
|
||||
static bool SendGraphQLRequest(const FHttpRequestRef Request, const FString& RequestName, const TFunctionRef<void(const FString& Message)> OnErrorAction);
|
||||
|
||||
static bool GetResponseAsJSON(const FHttpResponsePtr Response, const FString& RequestLogName, TSharedPtr<FJsonObject>& OutObject, const TFunctionRef<void(const FString& Message)> OnErrorAction);
|
||||
|
||||
static bool CheckForOperationErrors(const TSharedPtr<FJsonObject> GraphQLResponse, FString& OutErrorMessage);
|
||||
static bool CheckRequestFailed(bool bWasSuccessful, FHttpResponsePtr Response, const FString& RequestName, const TFunctionRef<void(const FString& Message)> OnErrorAction);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Objects/HighLevel/SpeckleBranch.h"
|
||||
|
||||
#include "ReceiveBranchesOperation.generated.h"
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveBranchesOperationHandler,
|
||||
const TArray<FSpeckleBranch>&, Branches,
|
||||
const FString&, ErrorMessage);
|
||||
|
||||
/**
|
||||
* Receive All streams
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveBranchesOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveBranchesOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveBranchesOperationHandler OnError;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations", meta = (WorldContext = "WorldContextObject"))
|
||||
static UReceiveBranchesOperation* ReceiveBranchesOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken, const FString& StreamId, int32 Limit = 20);
|
||||
virtual void Activate() override;
|
||||
|
||||
protected:
|
||||
void Request();
|
||||
|
||||
FString ServerUrl;
|
||||
FString AuthToken;
|
||||
FString StreamId;
|
||||
int32 Limit;
|
||||
|
||||
void HandleReceive(const TArray<FSpeckleBranch>& Branches);
|
||||
|
||||
void HandleError(const FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Objects/HighLevel/SpeckleCommit.h"
|
||||
|
||||
#include "ReceiveCommitsOperation.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveCommitsOperationHandler, const TArray<FSpeckleCommit>&, Commits, FString, ErrorMessage);
|
||||
|
||||
|
||||
/**
|
||||
* Receive All Commits
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveCommitsOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveCommitsOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveCommitsOperationHandler OnError;
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations",
|
||||
meta = (WorldContext = "WorldContextObject", BranchName = "main"))
|
||||
static UReceiveCommitsOperation* ReceiveCommitsOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl,
|
||||
const FString& AuthToken,
|
||||
const FString& StreamId,
|
||||
const FString& BranchName,
|
||||
const int32 Limit = 20);
|
||||
virtual void Activate() override;
|
||||
|
||||
protected:
|
||||
void Request();
|
||||
|
||||
FString ServerUrl;
|
||||
FString AuthToken;
|
||||
FString StreamId;
|
||||
FString BranchName;
|
||||
int32 Limit;
|
||||
|
||||
void HandleReceive(const TArray<FSpeckleCommit>& Commits);
|
||||
|
||||
void HandleError(const FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Objects/HighLevel/SpeckleGlobals.h"
|
||||
|
||||
#include "ReceiveGlobalsOperation.generated.h"
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveGlobalsOperationHandler, const FSpeckleGlobals, Globals, FString, ErrorMessage);
|
||||
|
||||
|
||||
/**
|
||||
* Receive My User Data in Speckle
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveGlobalsOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveGlobalsOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveGlobalsOperationHandler OnError;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations", meta = (WorldContext = "WorldContextObject"))
|
||||
static UReceiveGlobalsOperation* ReceiveGlobalsOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken,
|
||||
const FString& StreamId, const FString& ReferencedObjectId);
|
||||
virtual void Activate() override;
|
||||
|
||||
protected:
|
||||
void Request();
|
||||
|
||||
FString ServerUrl;
|
||||
FString AuthToken;
|
||||
FString StreamId;
|
||||
FString ReferencedObjectId;
|
||||
|
||||
void HandleReceive(const FSpeckleGlobals& Object);
|
||||
|
||||
void HandleError(const FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Objects/HighLevel/SpeckleUser.h"
|
||||
|
||||
#include "ReceiveMyUserDataOperation.generated.h"
|
||||
|
||||
struct FSpeckleUser;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveMyUserDataOperationHandler, const FSpeckleUser, MyUserData, FString, ErrorMessage);
|
||||
|
||||
|
||||
/**
|
||||
* Receive My User Data in Speckle
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveMyUserDataOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveMyUserDataOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveMyUserDataOperationHandler OnError;
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations",
|
||||
meta = (WorldContext = "WorldContextObject"))
|
||||
static UReceiveMyUserDataOperation* ReceiveMyUserDataOperation(UObject* WorldContextObject,
|
||||
const FString& ServerUrl, const FString& AuthToken);
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
protected:
|
||||
void Request();
|
||||
|
||||
FString ServerUrl;
|
||||
FString AuthToken;
|
||||
|
||||
void HandleReceive(const FSpeckleUser& Object);
|
||||
|
||||
void HandleError(const FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
|
||||
#include "ReceiveOperation.generated.h"
|
||||
|
||||
class ITransport;
|
||||
class UBase;
|
||||
class FJsonObject;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FRecieveOperationHandler, UBase*, RootBase, FString, ErrorMessage);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FRecieveOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
/// Called when the total number of children is known
|
||||
//UPROPERTY(BlueprintAssignable)
|
||||
//FRecieveOperationHandler OnChildrenCountKnown;
|
||||
|
||||
/// Called when some deserilization progress is made and TotalConverted has changed
|
||||
//UPROPERTY(BlueprintAssignable)
|
||||
//FRecieveOperationHandler OnProgress;
|
||||
|
||||
/// Called when receive operation has aborted due to some error
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FRecieveOperationHandler OnError;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations", meta = (WorldContext = "WorldContextObject"))
|
||||
static UReceiveOperation* ReceiveOperation(UObject* WorldContextObject, const FString& ObjectId,
|
||||
TScriptInterface<ITransport> RemoteTransport, TScriptInterface<ITransport> LocalTransport);
|
||||
|
||||
|
||||
virtual void Activate() override;
|
||||
|
||||
|
||||
protected:
|
||||
void Receive();
|
||||
|
||||
FString ObjectId;
|
||||
TScriptInterface<ITransport> RemoteTransport;
|
||||
TScriptInterface<ITransport> LocalTransport;
|
||||
|
||||
void HandleReceive(TSharedPtr<FJsonObject> Object);
|
||||
|
||||
void HandleError(FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintAsyncActionBase.h"
|
||||
#include "Objects/HighLevel/SpeckleStream.h"
|
||||
|
||||
#include "ReceiveStreamsOperation.generated.h"
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveStreamsOperationHandler, const TArray<FSpeckleStream>&, Streams, FString, ErrorMessage);
|
||||
|
||||
/**
|
||||
* Receive All streams
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UReceiveStreamsOperation : public UBlueprintAsyncActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveStreamsOperationHandler OnReceiveSuccessfully;
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FReceiveStreamsOperationHandler OnError;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintInternalUseOnly, Category = "Speckle|Operations", meta = (WorldContext = "WorldContextObject"))
|
||||
static UReceiveStreamsOperation* ReceiveStreamsOperation(UObject* WorldContextObject, const FString& ServerUrl, const FString& AuthToken, const int32 Limit = 20);
|
||||
virtual void Activate() override;
|
||||
|
||||
protected:
|
||||
void Request();
|
||||
|
||||
FString ServerUrl;
|
||||
FString AuthToken;
|
||||
int32 Limit;
|
||||
|
||||
void HandleReceive(const TArray<FSpeckleStream>& Streams);
|
||||
|
||||
void HandleError(const FString& Message);
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
// // Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
//
|
||||
// #pragma once
|
||||
//
|
||||
// #include "CoreMinimal.h"
|
||||
// #include "Kismet/BlueprintAsyncActionBase.h"
|
||||
//
|
||||
// #include "SendOperation.generated.h"
|
||||
//
|
||||
//
|
||||
// class ITransport;
|
||||
// class UBase;
|
||||
//
|
||||
// DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSendOperationHandler, const FString&, Id, const FString&, ErrorMessage);
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// UCLASS()
|
||||
// class SPECKLEUNREAL_API USendOperation : public UBlueprintAsyncActionBase
|
||||
// {
|
||||
// GENERATED_BODY()
|
||||
//
|
||||
// public:
|
||||
//
|
||||
// UPROPERTY(BlueprintAssignable)
|
||||
// FSendOperationHandler OnSendSuccessfully;
|
||||
//
|
||||
//
|
||||
// UPROPERTY(BlueprintAssignable)
|
||||
// FSendOperationHandler OnErrorAction;
|
||||
//
|
||||
//
|
||||
// UFUNCTION(BlueprintCallable, Category = "Speckle|Operations", meta = (WorldContext = "WorldContextObject"))
|
||||
// static USendOperation* SendOperation(UObject* WorldContextObject, UBase* Base, TArray<TScriptInterface<ITransport>> Transports);
|
||||
//
|
||||
// virtual void Activate() override;
|
||||
//
|
||||
// protected:
|
||||
//
|
||||
//
|
||||
// TWeakObjectPtr<UBase> Base;
|
||||
//
|
||||
// TScriptArray<TScriptInterface<ITransport>> Transports;
|
||||
//
|
||||
//
|
||||
// };
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
|
||||
|
||||
#include "SpeckleSerializer.generated.h"
|
||||
|
||||
class UBase;
|
||||
class ITransport;
|
||||
class FJsonObject;
|
||||
|
||||
UCLASS()
|
||||
class USpeckleSerializer : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintPure, Category="Speckle|Serialization")
|
||||
static UBase* DeserializeBaseById(const FString& ObjectId, const TScriptInterface<ITransport> ReadTransport);
|
||||
|
||||
static UBase* DeserializeBase(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
|
||||
#include "AggregateConverter.generated.h"
|
||||
|
||||
/**
|
||||
* An Aggregate Converter stores multiple ISpeckleConverter instances.
|
||||
* This allows you to use many converters as one
|
||||
*/
|
||||
UCLASS()
|
||||
|
||||
class SPECKLEUNREAL_API UAggregateConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
|
||||
// A lazily initialised mapping of SpeckleType -> converters.
|
||||
TMap<TSubclassOf<UBase>, TScriptInterface<ISpeckleConverter>> SpeckleTypeMap;
|
||||
|
||||
public:
|
||||
|
||||
// Array of converters, must be of type ISpeckleConverter
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle|Conversion")
|
||||
TArray<UObject*> SpeckleConverters;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
virtual UObject* ConvertToNativeInternal(const UBase* Object, UWorld* World);
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>&) override;
|
||||
|
||||
virtual bool CanConvertToNative_Implementation(TSubclassOf<UBase> BaseType) override;
|
||||
|
||||
|
||||
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
virtual TScriptInterface<ISpeckleConverter> GetConverter(const TSubclassOf<UBase> BaseType);
|
||||
|
||||
// Validates a given object is a valid ISpeckleConverter
|
||||
static bool CheckValidConverter(const UObject* Converter, bool LogWarning = true);
|
||||
|
||||
void FinishConversion_Internal();
|
||||
virtual void FinishConversion_Implementation() override;
|
||||
|
||||
// Validates changes to SpeckleConverters property, Should be called after modifying SpeckleConverters
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
virtual void OnConvertersChangeHandler();
|
||||
|
||||
#if WITH_EDITOR
|
||||
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||
#endif
|
||||
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/World.h"
|
||||
|
||||
#include "BlockConverter.generated.h"
|
||||
|
||||
class UBlockInstance;
|
||||
|
||||
/**
|
||||
* Converts Speckle Block Instance objects empty native actors with transform.
|
||||
* The Block Definition can then be converted by other converters
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UBlockConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
CONVERTS_SPECKLE_TYPES()
|
||||
public:
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TSubclassOf<AActor> BlockInstanceActorType;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TEnumAsByte<EComponentMobility::Type> ActorMobility;
|
||||
|
||||
UBlockConverter();
|
||||
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>& AvailableConverters) override;
|
||||
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual AActor* BlockToNative(const UBlockInstance* Block, UWorld* World);
|
||||
|
||||
protected:
|
||||
virtual AActor* CreateEmptyActor(UWorld* World, const FTransform& Transform, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "UObject/Object.h"
|
||||
|
||||
#include "MaterialConverter.generated.h"
|
||||
|
||||
class URenderMaterial;
|
||||
class UMaterialInterface;
|
||||
|
||||
UENUM()
|
||||
enum EConstMaterialOptions
|
||||
{
|
||||
Never UMETA(DisplayName = "Never"),
|
||||
NotPlay UMETA(DisplayName = "Editor Not Playing"),
|
||||
Always UMETA(DisplayName = "Editor And PIE"),
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Converts Speckle RenderMaterial objects into native Materials
|
||||
*/
|
||||
UCLASS(BlueprintType, Blueprintable)
|
||||
class SPECKLEUNREAL_API UMaterialConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
CONVERTS_SPECKLE_TYPES()
|
||||
|
||||
public:
|
||||
|
||||
/// Material to be applied to meshes when no RenderMaterial can be converted
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
UMaterialInterface* DefaultMeshMaterial;
|
||||
|
||||
/// Material Parent for converted opaque materials*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
UMaterialInterface* BaseMeshOpaqueMaterial;
|
||||
|
||||
/// Material Parent for converted materials with an opacity less than one
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
UMaterialInterface* BaseMeshTransparentMaterial;
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
/// Specify when to create Constant materials that can only be created with Editor.
|
||||
/// Otherwise will create dynamic materials
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TEnumAsByte<EConstMaterialOptions> UseConstMaterials;
|
||||
#endif
|
||||
|
||||
/// When generating meshes, materials in this TMap will be used
|
||||
/// instead of converted ones if the key matches the ID of the Object's RenderMaterial. (Takes priority over name matching)
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ToNative|Overrides", DisplayName = "By Speckle ID")
|
||||
TMap<FString, UMaterialInterface*> MaterialOverridesById;
|
||||
|
||||
/// When generating meshes, materials in this TSet will be used instead of converted ones if the material name matches the name of the Object's RenderMaterial
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ToNative|Overrides", DisplayName = "By Name")
|
||||
TSet<UMaterialInterface*> MaterialOverridesByName;
|
||||
|
||||
public:
|
||||
|
||||
UMaterialConverter();
|
||||
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld*, TScriptInterface<ISpeckleConverter>&) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative|Overrides")
|
||||
virtual bool TryGetOverride(const URenderMaterial* SpeckleMaterial, UMaterialInterface*& OutMaterial) const;
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UMaterialInterface* GetMaterial(const URenderMaterial* SpeckleMaterial);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UMaterialInterface* RenderMaterialToNative(const URenderMaterial* SpeckleMaterial, UPackage* Package);
|
||||
|
||||
virtual void FinishConversion_Implementation() override;
|
||||
|
||||
protected:
|
||||
|
||||
/** Transient cache of materials converted from stream RenderMaterial objects */
|
||||
UPROPERTY(AdvancedDisplay, BlueprintReadOnly, Transient, Category="ToNative|Cache")
|
||||
TMap<FString, UMaterialInterface*> ConvertedMaterials;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="ToNative")
|
||||
virtual UPackage* GetPackage(const FString& ObjectID) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="ToNative")
|
||||
virtual FString RemoveInvalidFileChars(const FString& InString) const;
|
||||
|
||||
#if WITH_EDITOR
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="ToNative")
|
||||
static bool ShouldCreateConstMaterial(TEnumAsByte<EConstMaterialOptions> Options);
|
||||
#endif
|
||||
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
|
||||
#include "PointCloudConverter.generated.h"
|
||||
|
||||
class ULidarPointCloudComponent;
|
||||
class ALidarPointCloudActor;
|
||||
class ULidarPointCloud;
|
||||
class UPointCloud;
|
||||
|
||||
/**
|
||||
* Converts Speckle Point Cloud objects into LidarPointClouds
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UPointCloudConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
CONVERTS_SPECKLE_TYPES()
|
||||
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TSubclassOf<ALidarPointCloudActor> PointCloudActorType;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TEnumAsByte<EComponentMobility::Type> ActorMobility;
|
||||
|
||||
UPointCloudConverter();
|
||||
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>&) override;
|
||||
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual ALidarPointCloudActor* PointCloudToNative(const UPointCloud* SpecklePointCloud, UWorld* World);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToSpeckle")
|
||||
virtual UPointCloud* PointCloudToSpeckle(const ULidarPointCloudComponent* Object);
|
||||
|
||||
protected:
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual ALidarPointCloudActor* CreateActor(UWorld* World, ULidarPointCloud* PointCloudData);
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/World.h"
|
||||
|
||||
#include "ProceduralMeshConverter.generated.h"
|
||||
|
||||
class UMaterialConverter;
|
||||
class UProceduralMeshComponent;
|
||||
class UMesh;
|
||||
class URenderMaterial;
|
||||
|
||||
|
||||
/**
|
||||
* Converts Speckle Mesh objects into native actors with a procedural mesh component.
|
||||
*
|
||||
* Compared with the StaticMeshConverter, this converter has some serious limitations
|
||||
* - Cannot convert displayValues,
|
||||
* - N-gon faces will be ignored,
|
||||
* - Meshes are transient, and won't persist on level reload
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UProceduralMeshConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
CONVERTS_SPECKLE_TYPES()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TSubclassOf<AActor> MeshActorType;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TEnumAsByte<EComponentMobility::Type> ActorMobility;
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
UProceduralMeshConverter();
|
||||
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World,
|
||||
TScriptInterface<ISpeckleConverter>& AvailableConverters) override;
|
||||
|
||||
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual AActor* MeshToNative(const UMesh* SpeckleMesh, UWorld* World, TScriptInterface<ISpeckleConverter>& MaterialConverter);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UMesh* MeshToSpeckle(const UProceduralMeshComponent* Object);
|
||||
|
||||
virtual AActor* CreateEmptyActor(UWorld* World, const FTransform& Transform,
|
||||
const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());
|
||||
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/World.h"
|
||||
#include "Engine/StaticMesh.h"
|
||||
|
||||
#include "StaticMeshConverter.generated.h"
|
||||
|
||||
class UMaterialConverter;
|
||||
class AStaticMeshActor;
|
||||
class UMesh;
|
||||
class URenderMaterial;
|
||||
|
||||
|
||||
/**
|
||||
* Converts Speckle Mesh objects into native Actors with a StaticMesh component
|
||||
*
|
||||
* Can convert multiple Speckle Mesh objects (eg with different materials) in one StaticMesh
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UStaticMeshConverter : public UObject, public ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
CONVERTS_SPECKLE_TYPES()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TSubclassOf<AActor> MeshActorType;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
TEnumAsByte<EComponentMobility::Type> ActorMobility;
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
// If true, will use the full Editor Only build process
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
bool UseFullBuild;
|
||||
|
||||
// When true, will display FSlowTask progress of editor only build process
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative|EditorOnly")
|
||||
bool DisplayBuildProgressBar;
|
||||
|
||||
// When true, will allow cancellation of FSlowTask progress of editor only build process
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative|EditorOnly")
|
||||
bool AllowCancelBuild;
|
||||
#endif
|
||||
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
bool BuildSimpleCollision;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
|
||||
bool Transient;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative")
|
||||
bool GenerateLightmapUV;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative")
|
||||
int32 MinLightmapResolution;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative")
|
||||
bool BuildReversedIndexBuffer;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative")
|
||||
bool UseFullPrecisionUVs;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category="ToNative")
|
||||
bool RemoveDegeneratesOnBuild;
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
UStaticMeshConverter();
|
||||
|
||||
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World, TScriptInterface<ISpeckleConverter>& AvailableConverters) override;
|
||||
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
|
||||
virtual void FinishConversion_Implementation() override;
|
||||
|
||||
// Converts a multiple Speckle Meshes to a native actor of type MeshActorType
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual AActor* MeshesToNativeActor(const UBase* Parent, const TArray<UMesh*>& SpeckleMeshes, UWorld* World, TScriptInterface<ISpeckleConverter>& RenderMaterialConverter);
|
||||
|
||||
// Converts a single Speckle Mesh to a native actor of type MeshActorType
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual AActor* MeshToNativeActor(const UMesh* SpeckleMesh, UWorld* World, TScriptInterface<ISpeckleConverter>& MaterialConverter);
|
||||
|
||||
virtual AActor* CreateEmptyActor(UWorld* World, const FTransform& Transform = FTransform::Identity, const FActorSpawnParameters& SpawnParameters =
|
||||
FActorSpawnParameters());
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToSpeckle")
|
||||
virtual UBase* MeshToSpeckle(const UStaticMeshComponent* Object);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
FCriticalSection Lock_StaticMeshesToBuild;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Transient, Category="ToNative")
|
||||
TArray<UStaticMesh*> StaticMeshesToBuild;
|
||||
|
||||
virtual void GenerateMeshParams(UStaticMesh::FBuildMeshDescriptionsParams& MeshParams) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UMaterialInterface* GetMaterial(const URenderMaterial* SpeckleMaterial, UWorld* World,
|
||||
TScriptInterface<ISpeckleConverter>& MaterialConverter) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UStaticMesh* MeshesToNativeMesh(UObject* Outer, const UBase* Parent, const TArray<UMesh*>& SpeckleMeshes, TScriptInterface<ISpeckleConverter>
|
||||
& MaterialConverter);
|
||||
UFUNCTION(BlueprintCallable, Category="ToNative")
|
||||
virtual UStaticMesh* MeshToNativeMesh(UObject* Outer, const UMesh* SpeckleMesh, TScriptInterface<ISpeckleConverter>& MaterialConverter);
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
|
||||
#include "SpeckleConverter.generated.h"
|
||||
|
||||
|
||||
UINTERFACE()
|
||||
class SPECKLEUNREAL_API USpeckleConverter : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface for conversion functions (ToSpeckle and ToNative) of a specific speckle type(s).
|
||||
*
|
||||
* Implementors of this interface provide conversion functions of specific types : Base
|
||||
*/
|
||||
class SPECKLEUNREAL_API ISpeckleConverter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/// Will return true if this converter can convert a given BaseType
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="ToNative")
|
||||
bool CanConvertToNative(TSubclassOf<UBase> BaseType);
|
||||
|
||||
/// Tries to convert a given SpeckleBase into a native Actor
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="ToNative")
|
||||
UObject* ConvertToNative(const UBase* SpeckleBase, UWorld* World, UPARAM(ref) TScriptInterface<ISpeckleConverter>& AvailableConverters);
|
||||
|
||||
/// Tries to convert a given Actor or Component into a Speckle Base
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="ToSpeckle")
|
||||
UBase* ConvertToSpeckle(const UObject* Object);
|
||||
|
||||
/// Clean up any cached assets that now may be unused
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="ToNative")
|
||||
void FinishConversion();
|
||||
|
||||
};
|
||||
|
||||
#define CONVERTS_SPECKLE_TYPES() \
|
||||
protected: \
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Conversion") \
|
||||
TSet<TSubclassOf<UBase>> SpeckleTypes; \
|
||||
public: \
|
||||
virtual bool CanConvertToNative_Implementation(TSubclassOf<UBase> BaseType) override { return SpeckleTypes.Contains(BaseType); } \
|
||||
private:
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Objects/HighLevel/SpeckleStream.h"
|
||||
|
||||
#include "SpeckleConverterComponent.generated.h"
|
||||
|
||||
|
||||
class ITransport;
|
||||
class ISpeckleConverter;
|
||||
class UBase;
|
||||
class UAggregateConverter;
|
||||
struct FSlowTask;
|
||||
|
||||
/**
|
||||
* An Actor Component for encapsulating recursive conversion of Speckle Objects
|
||||
*/
|
||||
UCLASS(ClassGroup=(Speckle), meta=(BlueprintSpawnableComponent))
|
||||
class SPECKLEUNREAL_API USpeckleConverterComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
// Array of converters
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle|Conversion")
|
||||
UAggregateConverter* SpeckleConverter;
|
||||
|
||||
// Sets default values for this component's properties
|
||||
USpeckleConverterComponent();
|
||||
|
||||
|
||||
// Converts the given Base and all children into native actors.
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
UPARAM(DisplayName = "RootActor") AActor* RecursivelyConvertToNative(AActor* AOwner, const UBase* Base,
|
||||
const TScriptInterface<ITransport>& LocalTransport, bool DisplayProgressBar, TArray<AActor*>& OutActors);
|
||||
|
||||
|
||||
// Converts the given Base and all children into native actors.
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
UPARAM(DisplayName = "RootActor") TArray<FSpeckleStream> ConvertStreamsToNative(
|
||||
AActor* AOwner,
|
||||
const UBase* Base,
|
||||
const TScriptInterface<ITransport>& LocalTransport,
|
||||
bool DisplayProgressBar,
|
||||
TArray<AActor*>& OutActors
|
||||
);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
virtual void FinishConversion();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle|Conversion")
|
||||
TArray<FSpeckleStream> ArrayOfStreams;
|
||||
|
||||
protected:
|
||||
|
||||
virtual AActor* RecursivelyConvertToNative_Internal(AActor* AOwner, const UBase* Base, const TScriptInterface<ITransport>& LocalTransport, FSlowTask* Task, TArray<AActor*>& OutActors);
|
||||
|
||||
virtual void ConvertChild(const TSharedPtr<FJsonValue> Object, AActor* AOwner, const TScriptInterface<ITransport>& LocalTransport, FSlowTask* Task, TArray<AActor*>& OutActors);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Conversion")
|
||||
virtual void AttachConvertedToOwner(AActor* AOwner, const UBase* Base, UObject* Converted);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogSpeckle, Log, All);
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
/// Anonymous telemetry to help us understand how to make a better Speckle.
|
||||
/// This really helps us to deliver a better open source project and product!
|
||||
class FAnalytics
|
||||
{
|
||||
protected:
|
||||
static const FString MixpanelToken;
|
||||
static const FString MixpanelServer;
|
||||
static const FString VersionedApplicationName;
|
||||
|
||||
public:
|
||||
static void TrackEvent(const FString& Email, const FString& Server, const FString& EventName);
|
||||
static void TrackEvent(const FString& Email, const FString& Server, const FString& EventName,
|
||||
const TMap<FString, FString>& CustomProperties);
|
||||
static FString Hash(const FString& Input);
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
|
||||
#include "Base.generated.h"
|
||||
|
||||
class ITransport;
|
||||
class ASpeckleUnrealManager;
|
||||
|
||||
/**
|
||||
* Base type that all Object Models inherit from
|
||||
*/
|
||||
UCLASS(BlueprintType)
|
||||
class SPECKLEUNREAL_API UBase : public UObject
|
||||
{
|
||||
public:
|
||||
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
|
||||
explicit UBase(const wchar_t* SpeckleType): SpeckleType(SpeckleType) {}
|
||||
explicit UBase(const FString& SpeckleType) : SpeckleType(SpeckleType) {}
|
||||
|
||||
public:
|
||||
|
||||
UBase() : SpeckleType("Base") {}
|
||||
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FString Id;
|
||||
|
||||
TMap<FString, TSharedPtr<FJsonValue>> DynamicProperties; //TODO this won't be serialised!
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FString Units;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FString SpeckleType;
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
|
||||
{
|
||||
bool IsValid = false;
|
||||
DynamicProperties = Obj->Values;
|
||||
if(Obj->TryGetStringField("id", Id))
|
||||
{
|
||||
IsValid = true;
|
||||
DynamicProperties.Remove("id");
|
||||
}
|
||||
|
||||
if(Obj->TryGetStringField("units", Units)) DynamicProperties.Remove("units");
|
||||
if(Obj->TryGetStringField("speckle_type", SpeckleType)) DynamicProperties.Remove("speckle_type");
|
||||
|
||||
return IsValid;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
int32 RemoveDynamicProperty(UPARAM(ref) const FString& Key)
|
||||
{
|
||||
return DynamicProperties.Remove(Key);
|
||||
}
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
bool TryGetDynamicString(UPARAM(ref) const FString& Key, FString& OutString) const
|
||||
{
|
||||
const TSharedPtr<FJsonValue> Value = DynamicProperties.FindRef(Key);
|
||||
if(Value == nullptr) return false;
|
||||
return Value->TryGetString(OutString);
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
bool TryGetDynamicNumber(UPARAM(ref) const FString& Key, float& OutNumber) const
|
||||
{
|
||||
const TSharedPtr<FJsonValue> Value = DynamicProperties.FindRef(Key);
|
||||
if(Value == nullptr) return false;
|
||||
return Value->TryGetNumber(OutNumber);
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
bool TryGetDynamicBool(UPARAM(ref) const FString& Key, bool& OutBool) const
|
||||
{
|
||||
const TSharedPtr<FJsonValue> Value = DynamicProperties.FindRef(Key);
|
||||
if(Value == nullptr) return false;
|
||||
return Value->TryGetBool(OutBool);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Base.h"
|
||||
|
||||
#include "DisplayValueElement.generated.h"
|
||||
|
||||
|
||||
class UMesh;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Display Value Element (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UDisplayValueElement : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
protected:
|
||||
static TArray<FString> DisplayValueAliasStrings;
|
||||
bool AddDisplayValue(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport);
|
||||
|
||||
public:
|
||||
|
||||
UDisplayValueElement() : UBase(TEXT("Objects.BuiltElements")) {}
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<UMesh*> DisplayValue;
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Mesh.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Box.generated.h"
|
||||
|
||||
class UPlane;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Box (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UBoxx : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
UPlane* BasePlane;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
FVector2f XSize, YSize;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
float Area;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
float Volume;
|
||||
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
virtual UMesh* ToMesh(UObject* Outer = GetTransientPackage()) const;
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
|
||||
#include "Mesh.generated.h"
|
||||
|
||||
class URenderMaterial;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Mesh (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UMesh : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UMesh() : UBase(TEXT("Objects.Geometry.Mesh")) {}
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<FVector> Vertices;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<int32> Faces;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<FVector2D> TextureCoordinates;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<FColor> VertexColors;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
FMatrix Transform;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
URenderMaterial* RenderMaterial;
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
|
||||
protected:
|
||||
virtual void AlignVerticesWithTexCoordsByIndex();
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
#include "Plane.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Plane (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UPlane : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
FVector Origin, Normal, XDir, YDir;
|
||||
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
|
||||
#include "PointCloud.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Point Cloud (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UPointCloud : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPointCloud() : UBase(TEXT("Objects.Geometry.Pointcloud")) {}
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<FVector> Points;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<FColor> Colors;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<float> Sizes;
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "FSpeckleActivity.generated.h"
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* for the User Activities
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleActivity
|
||||
{
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString ActionType;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString Time;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString Message;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString StreamId;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString ResourceType;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString ResourceId;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString Info;
|
||||
|
||||
FSpeckleActivity(){};
|
||||
|
||||
FSpeckleActivity(const FString& ActionType, const FString& Time, const FString& Message,
|
||||
const FString& StreamId, const FString& ResourceType, const FString& ResourceId,
|
||||
const FString& Info):
|
||||
ActionType(ActionType), Time(Time), Message(Message), StreamId(StreamId),
|
||||
ResourceType(ResourceType), ResourceId(ResourceId), Info(Info){}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "FSpeckleEnum.generated.h"
|
||||
|
||||
UENUM()
|
||||
enum ESpeckleItemType {Stream, Commit, Branch};
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "SpeckleCollaborator.h"
|
||||
#include "SpeckleBranch.generated.h"
|
||||
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* from a speckle Branch
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleBranch
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString ID;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Description;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Author;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Commits;
|
||||
|
||||
void DisplayAsString(const FString& msg, const TSharedPtr<FJsonObject> Obj) const
|
||||
{
|
||||
FString OutputString;
|
||||
TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
|
||||
FJsonSerializer::Serialize(Obj.ToSharedRef(), Writer);
|
||||
UE_LOG(LogTemp, Log, TEXT("resulting jsonString from %s -> %s"), *msg, *OutputString);
|
||||
}
|
||||
|
||||
FSpeckleBranch(const TSharedPtr<FJsonObject> Obj)
|
||||
{
|
||||
ensureAlways(Obj->TryGetStringField("id", ID));
|
||||
ensureAlways(Obj->TryGetStringField("name", Name));
|
||||
Obj->TryGetStringField("description", Description);
|
||||
}
|
||||
|
||||
FSpeckleBranch(){};
|
||||
//
|
||||
// FSpeckleBranch(const FString& ID, const FString& Name, const FString& Description):
|
||||
// ID(ID), Name(Name), Description(Description){}
|
||||
//
|
||||
// FSpeckleBranch(const FString& ID, const FString& Name, const FString& Description, const FString& Author, const FString& Commits):
|
||||
// ID(ID), Name(Name), Description(Description), Author(Author), Commits(Commits){}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "SpeckleCollaborator.generated.h"
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* from a Collaborator in a Stream
|
||||
* received from GraphQL.
|
||||
* See https://github.com/specklesystems/speckle-sharp/blob/main/Core/Core/Api/GraphQL/Models.cs
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleCollaborator
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Id;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Role;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Avatar;
|
||||
|
||||
FSpeckleCollaborator() { }
|
||||
|
||||
FSpeckleCollaborator(const TSharedPtr<FJsonObject> JsonObject)
|
||||
{
|
||||
ensureAlways(JsonObject->TryGetStringField("id", Id));
|
||||
ensureAlways(JsonObject->TryGetStringField("name", Name));
|
||||
JsonObject->TryGetStringField("role", Role);
|
||||
JsonObject->TryGetStringField("avatar", Avatar);
|
||||
}
|
||||
|
||||
FSpeckleCollaborator(const FString& Id, const FString& Name, const FString& Company, const FString& Role, const FString& Avatar)
|
||||
: Id(Id),
|
||||
Name(Name),
|
||||
Role(Role),
|
||||
Avatar(Avatar)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "SpeckleCommit.generated.h"
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* from a speckle commit
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleCommit
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString ID;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Message;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString BranchName;
|
||||
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString AuthorName;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString AuthorId;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString AuthorAvatar;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString CreatedAt;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString SourceApplication;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString ReferenceObjectID;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString TotalChildrenCount;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
TArray<FString> Parents;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString CommentCount;
|
||||
|
||||
|
||||
|
||||
void DisplayAsString(const FString& msg, const TSharedPtr<FJsonObject> Obj) const
|
||||
{
|
||||
FString OutputString;
|
||||
TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
|
||||
FJsonSerializer::Serialize(Obj.ToSharedRef(), Writer);
|
||||
UE_LOG(LogTemp, Log, TEXT("resulting jsonString from %s -> %s"), *msg, *OutputString);
|
||||
}
|
||||
|
||||
FSpeckleCommit(){};
|
||||
|
||||
FSpeckleCommit(const TSharedPtr<FJsonValue> CommitAsJSONValue)
|
||||
{
|
||||
TSharedPtr<FJsonObject> obj = CommitAsJSONValue->AsObject();
|
||||
ensureAlways(obj->TryGetStringField("id", ID));
|
||||
obj->TryGetStringField("message", Message);
|
||||
obj->TryGetStringField("branchName", BranchName);
|
||||
obj->TryGetStringField("authorName", AuthorName);
|
||||
obj->TryGetStringField("authorId", AuthorId);
|
||||
obj->TryGetStringField("authorAvatar", AuthorAvatar);
|
||||
obj->TryGetStringField("createdAt", CreatedAt);
|
||||
obj->TryGetStringField("sourceApplication", SourceApplication);
|
||||
obj->TryGetStringField("totalChildrenCount", TotalChildrenCount);
|
||||
ensureAlways(obj->TryGetStringField("referencedObject", ReferenceObjectID));
|
||||
obj->TryGetStringArrayField("parents", Parents);
|
||||
obj->TryGetStringField("commentCount", CommentCount); //TODO is this a prop?
|
||||
|
||||
}
|
||||
|
||||
|
||||
// FSpeckleCommit(const FString& ReferenceObjectID, const FString& Author, const FString& Message, const FString& BranchName)
|
||||
// : ReferenceObjectID(ReferenceObjectID),
|
||||
// Author(Author),
|
||||
// Message(Message),
|
||||
// BranchName(BranchName)
|
||||
// {
|
||||
// }
|
||||
|
||||
// FSpeckleCommit(const FString& ReferenceObjectID, const FString& AuthorName, const FString& Message, const FString& BranchName,
|
||||
// const FString& Id, const FString& SourceApplication, const FString& TotalChildrenCount, const FString& Parents,
|
||||
// const FString& AuthorId, const FString& AuthorAvatar, const FString& CreatedAt)
|
||||
// : ReferenceObjectID(ReferenceObjectID),
|
||||
// Author(Author),
|
||||
// Message(Message),
|
||||
// BranchName(BranchName),
|
||||
// ID(Id),
|
||||
// SourceApplication(SourceApplication),
|
||||
// TotalChildrenCount(TotalChildrenCount),
|
||||
// Parents(Parents),
|
||||
// AuthorId(AuthorId),
|
||||
// AuthorAvatar(AuthorAvatar),
|
||||
// CreatedAt(CreatedAt)
|
||||
// {
|
||||
// }
|
||||
|
||||
//Operators overloading
|
||||
|
||||
// FORCEINLINE bool operator==(const FSpeckleCommit &Other) const
|
||||
// {
|
||||
// return ReferenceObjectID == Other.ReferenceObjectID;
|
||||
// }
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "SpeckleGlobals.generated.h"
|
||||
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* from a speckle Branch
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleGlobals
|
||||
{
|
||||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString ID;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
FString Region;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
float Latitude;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
float Longitude;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
float Height;
|
||||
|
||||
FSpeckleGlobals(): Latitude(0), Longitude(0), Height(0)
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
FSpeckleGlobals(const TSharedPtr<FJsonObject> GlobalsJSONObject)
|
||||
{
|
||||
ID = *GlobalsJSONObject->GetStringField("id");
|
||||
//TArray<TSharedPtr<FJsonValue>> RegionAsArray = GlobalsJSONObject->GetArrayField("region");
|
||||
Region = ""; // RegionAsArray[0]->AsString();
|
||||
Latitude = static_cast<float>(GlobalsJSONObject->GetNumberField("Latitude"));
|
||||
Longitude= static_cast<float>(GlobalsJSONObject->GetNumberField("Longitude"));
|
||||
Height = static_cast<float>(GlobalsJSONObject->GetNumberField("Height"));
|
||||
}
|
||||
|
||||
|
||||
FSpeckleGlobals(const FString& ID, const FString& Region, float Latitude, float Longitude)
|
||||
: ID(ID),
|
||||
Region(Region),
|
||||
Latitude(Latitude),
|
||||
Longitude(Longitude)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
FSpeckleGlobals(const FString& ID, const FString& Region, float Latitude, float Longitude, float Height)
|
||||
: ID(ID),
|
||||
Region(Region),
|
||||
Latitude(Latitude),
|
||||
Longitude(Longitude),
|
||||
Height(Height)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,98 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "LogSpeckle.h"
|
||||
#include "SpeckleCollaborator.h"
|
||||
|
||||
#include "SpeckleStream.generated.h"
|
||||
|
||||
/*
|
||||
* Class that holds all the properties required
|
||||
* from a speckle Branch
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleStream
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString ID;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Description;
|
||||
|
||||
// UPROPERTY(BlueprintReadWrite)
|
||||
// bool IsStreamPublic;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Role;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString CreatedAt;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString UpdatedAt;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
TArray<FSpeckleCollaborator> Collaborators;
|
||||
|
||||
|
||||
void DisplayAsString(const FString& msg, const TSharedPtr<FJsonObject> Obj) const
|
||||
{
|
||||
FString OutputString;
|
||||
TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
|
||||
FJsonSerializer::Serialize(Obj.ToSharedRef(), Writer);
|
||||
UE_LOG(LogTemp, Log, TEXT("resulting jsonString from %s -> %s"), *msg, *OutputString);
|
||||
}
|
||||
|
||||
FSpeckleStream(const TSharedPtr<FJsonValue> StreamAsJSONValue)
|
||||
{
|
||||
TSharedPtr<FJsonObject> Obj = StreamAsJSONValue->AsObject();
|
||||
//DisplayAsString("Collaborators insider --->", Obj);
|
||||
|
||||
ensureAlways(Obj->TryGetStringField("id", ID));
|
||||
ensureAlways(Obj->TryGetStringField("name", Name));
|
||||
Obj->TryGetStringField("description", Description);
|
||||
Obj->TryGetStringField("updatedAt", UpdatedAt);
|
||||
Obj->TryGetStringField("createdAt", CreatedAt);
|
||||
Obj->TryGetStringField("role", Role);
|
||||
|
||||
const TArray<TSharedPtr<FJsonValue>>* CollaboratorsArrJSONValues;
|
||||
Obj->TryGetArrayField("collaborators", CollaboratorsArrJSONValues);
|
||||
|
||||
for (const TSharedPtr<FJsonValue>& c : *CollaboratorsArrJSONValues)
|
||||
{
|
||||
const TSharedPtr<FJsonObject>* o;
|
||||
if(ensure(c->TryGetObject(o)))
|
||||
{
|
||||
FSpeckleCollaborator Collaborator = FSpeckleCollaborator(*o);
|
||||
Collaborators.Add(Collaborator);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FSpeckleStream(){};
|
||||
//
|
||||
// FSpeckleStream(const FString& ID, const FString& Name, const FString& Description):
|
||||
// ID(ID), Name(Name), Description(Description){};
|
||||
//
|
||||
// FSpeckleStream( const FString& ID,
|
||||
// const FString& Name,
|
||||
// const FString& Description,
|
||||
// const bool& IsPublic,
|
||||
// const FString& Role,
|
||||
// const FString& CreatedAt,
|
||||
// const FString& UpdatedAt):
|
||||
// ID(ID),
|
||||
// Name(Name),
|
||||
// Description(Description),
|
||||
// IsPublic(IsPublic),
|
||||
// Role(Role),
|
||||
// CreatedAt(CreatedAt),
|
||||
// UpdatedAt(UpdatedAt){}
|
||||
};
|
||||
@@ -0,0 +1,88 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "SpeckleUser.generated.h"
|
||||
|
||||
/*
|
||||
* Struct that holds all the properties required
|
||||
* for a User
|
||||
* received from GraphQL.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FSpeckleUser
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Id;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Email;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Bio;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Company;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Avatar;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Suuid;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|API Models")
|
||||
FString Role;
|
||||
|
||||
|
||||
FSpeckleUser(){};
|
||||
|
||||
FString DisplayAsString(const FString& msg, const TSharedPtr<FJsonObject> Obj) const
|
||||
{
|
||||
FString OutputString;
|
||||
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&OutputString);
|
||||
FJsonSerializer::Serialize(Obj.ToSharedRef(), Writer);
|
||||
UE_LOG(LogSpeckle, Log, TEXT("resulting jsonString from %s -> %s"), *msg, *OutputString);
|
||||
}
|
||||
|
||||
FSpeckleUser(const TSharedPtr<FJsonObject> MyUserDataJSONObject)
|
||||
{
|
||||
ensureAlways(MyUserDataJSONObject->TryGetStringField("id", Id));
|
||||
MyUserDataJSONObject->TryGetStringField("name", Name);
|
||||
MyUserDataJSONObject->TryGetStringField("company", Company);
|
||||
MyUserDataJSONObject->TryGetStringField("role", Role);
|
||||
MyUserDataJSONObject->TryGetStringField("suuid", Suuid); //TODO Is this a prop?
|
||||
MyUserDataJSONObject->TryGetStringField("email", Email);
|
||||
MyUserDataJSONObject->TryGetStringField("bio", Bio);
|
||||
MyUserDataJSONObject->TryGetStringField("avatar", Avatar);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//query{user{id,name,email,company,role,suuid,bio,profiles,avatar}}
|
||||
|
||||
|
||||
FSpeckleUser(
|
||||
const FString& Id,
|
||||
const FString& Email,
|
||||
const FString& Bio,
|
||||
const FString& Company,
|
||||
const FString& Name,
|
||||
const FString& Avatar,
|
||||
const FString& Suuid,
|
||||
const FString& Role)
|
||||
:
|
||||
Id(Id),
|
||||
Email(Email),
|
||||
Name(Name),
|
||||
Bio(Bio),
|
||||
Company(Company),
|
||||
Avatar(Avatar),
|
||||
Suuid(Suuid),
|
||||
Role(Role)
|
||||
{}
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
|
||||
#include "ObjectModelRegistry.generated.h"
|
||||
|
||||
class UBase;
|
||||
|
||||
/**
|
||||
* Handles the mapping of Speckle type to Object Model
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API UObjectModelRegistry : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
|
||||
static TMap<FString, TSubclassOf<UBase>> TypeRegistry;
|
||||
|
||||
static void GenerateTypeRegistry();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/// Attempts to find the closest registered TSubclassOf<UBase>
|
||||
/// by recursively stripping away a the most specific name specifier from the given SpeckleType
|
||||
/// until a UBase type is found or the FString is exhausted.
|
||||
///
|
||||
/// Eg. with an input of "Objects.Elements.Wall"
|
||||
/// Will first look for a registered type of "Objects.Elements.Wall"
|
||||
/// If one is not found, will look for "Objects.Elements" etc.
|
||||
/// Returns nullptr if none found.
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
static TSubclassOf<UBase> FindClosestType(const FString& SpeckleType);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
static bool ParentType(const FString& Type, FString& NextType);
|
||||
|
||||
/// Attempts to find a TSubclassOf<UBase> with a UBase::SpeckleType matching the given SpeckleType param
|
||||
/// Returns nullptr if none found.
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
static TSubclassOf<UBase> GetRegisteredType(const FString& SpeckleType);
|
||||
|
||||
/// Attempts to find a TSubclassOf<UBase> with a UBase::SpeckleType matching the given SpeckleType param
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle|Objects")
|
||||
static bool TryGetRegisteredType(const FString& SpeckleType, TSubclassOf<UBase>& OutType);
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
|
||||
#include "BlockInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Block Instance (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UBlockInstance : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
TArray<UBase*> Geometry;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Speckle|Objects")
|
||||
FMatrix Transform;
|
||||
|
||||
UBlockInstance() : UBase(TEXT("Objects.Other.BlockInstance")) {}
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
|
||||
#include "RenderMaterial.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="Render Material (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API URenderMaterial : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
URenderMaterial() : UBase(TEXT("Objects.Other.RenderMaterial")) {}
|
||||
|
||||
UPROPERTY()
|
||||
FString Name;
|
||||
|
||||
UPROPERTY()
|
||||
double Opacity = 1;
|
||||
|
||||
UPROPERTY()
|
||||
double Metalness = 0;
|
||||
|
||||
UPROPERTY()
|
||||
double Roughness = 1;
|
||||
|
||||
UPROPERTY()
|
||||
FLinearColor Diffuse = FColor{221,221,221};
|
||||
|
||||
UPROPERTY()
|
||||
FLinearColor Emissive = FLinearColor::Black;
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override
|
||||
{
|
||||
if(!Super::Parse(Obj, ReadTransport)) return false;
|
||||
|
||||
if(Obj->TryGetStringField("name", Name)) DynamicProperties.Remove("name");
|
||||
if(Obj->TryGetNumberField("opacity", Opacity)) DynamicProperties.Remove("opacity");
|
||||
if(Obj->TryGetNumberField("metalness", Metalness)) DynamicProperties.Remove("metalness");
|
||||
if(Obj->TryGetNumberField("roughness", Roughness)) DynamicProperties.Remove("roughness");
|
||||
|
||||
bool IsValid = false;
|
||||
|
||||
int32 ARGB;
|
||||
if(Obj->TryGetNumberField("diffuse", ARGB))
|
||||
{
|
||||
Diffuse = FColor(ARGB);
|
||||
DynamicProperties.Remove("diffuse");
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
if(Obj->TryGetNumberField("emissive", ARGB))
|
||||
{
|
||||
Emissive = FColor(ARGB);
|
||||
DynamicProperties.Remove("emissive");
|
||||
}
|
||||
|
||||
return IsValid;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Objects/Base.h"
|
||||
|
||||
#include "View3D.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(meta=(ScriptName="View3D (Speckle.Objects)"))
|
||||
class SPECKLEUNREAL_API UView3D : public UBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FString Name;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FVector Origin;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FVector UpDirection;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
|
||||
FVector ForwardDirection;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
|
||||
bool IsOrthogonal;
|
||||
|
||||
UView3D() : UBase(TEXT("Objects.BuiltElements.View")) {}
|
||||
|
||||
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
#include "SpeckleObjectUtils.generated.h"
|
||||
|
||||
class ITransport;
|
||||
class UBase;
|
||||
class FJsonValue;
|
||||
class FJsonObject;
|
||||
class UWorld;
|
||||
class AActor;
|
||||
|
||||
/**
|
||||
* Several helper functions useful for handling JSON Speckle Objects
|
||||
*/
|
||||
UCLASS()
|
||||
class SPECKLEUNREAL_API USpeckleObjectUtils : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
static TArray<TSharedPtr<FJsonValue>> CombineChunks(const TArray<TSharedPtr<FJsonValue>>& ArrayField, const TScriptInterface<ITransport> Transport);
|
||||
|
||||
static bool ResolveReference(const TSharedPtr<FJsonObject> Object, const TScriptInterface<ITransport> Transport, TSharedPtr<FJsonObject>& OutObject);
|
||||
|
||||
static bool TryParseTransform(const TSharedPtr<FJsonObject> SpeckleObject, FMatrix& OutMatrix);
|
||||
|
||||
|
||||
static bool ParseVector(const TSharedPtr<FJsonObject> Object, const TScriptInterface<ITransport> Transport, FVector& OutObject);
|
||||
static bool ParseVectorProperty(const TSharedPtr<FJsonObject> Base, const FString& PropertyName, const TScriptInterface<ITransport> ReadTransport, FVector& OutObject);
|
||||
|
||||
template <typename T>
|
||||
static bool ParseSpeckleObject(const TSharedPtr<FJsonObject> Object, const TScriptInterface<ITransport> Transport, T*& OutObject);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle/ObjectUtils")
|
||||
static float ParseScaleFactor(const FString& UnitsString);
|
||||
|
||||
// Given a Right Handed Z-up transformation matrix (Speckle's system), will create an equivalent Left Handed Z-up FTransform (UE's system)
|
||||
UFUNCTION(BlueprintPure, Category="Speckle/ObjectUtils")
|
||||
static FTransform CreateTransform(UPARAM(ref) const FMatrix& TransformMatrix);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Speckle/ObjectUtils")
|
||||
static AActor* SpawnActorInWorld(const TSubclassOf<AActor> Class, UWorld* World, UPARAM(ref) const FTransform& Transform);
|
||||
};
|
||||
+3
-2
@@ -1,14 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class FSpeckleUnrealModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "SpeckleUnrealManager.generated.h"
|
||||
|
||||
class UServerTransport;
|
||||
class ITransport;
|
||||
class USpeckleConverterComponent;
|
||||
class FJsonObject;
|
||||
|
||||
/**
|
||||
* An Actor to handle the receiving of Speckle objects into a level
|
||||
*/
|
||||
UCLASS(ClassGroup=(Speckle), AutoCollapseCategories=("Speckle|Conversion"), BlueprintType)
|
||||
class SPECKLEUNREAL_API ASpeckleUnrealManager : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle")
|
||||
FString ServerUrl;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle")
|
||||
FString StreamID;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle")
|
||||
FString ObjectID;
|
||||
|
||||
// A Personal Access Token can be created from your Speckle Profile page (Treat tokens like passwords, do not share publicly) - Required for receiving private streams
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle", meta=(PasswordField = true))
|
||||
FString AuthToken;
|
||||
|
||||
// When true, will call `Receive` on BeginPlay
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle", AdvancedDisplay)
|
||||
bool ImportAtRuntime;
|
||||
|
||||
// When true, will maintain an in-memory (transient) cache of received speckle objects
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle", AdvancedDisplay)
|
||||
bool KeepCache;
|
||||
|
||||
// The Conversion component to convert received speckle objects into native Actors
|
||||
UPROPERTY(VisibleAnywhere, Category="Speckle", BlueprintReadWrite)
|
||||
USpeckleConverterComponent* Converter;
|
||||
|
||||
// Used to stagger transport requests, useful when making requests for a large number of child objects
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Speckle", AdvancedDisplay)
|
||||
bool DisplayProgressBar;
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
ASpeckleUnrealManager();
|
||||
|
||||
// Receives specified object from specified Speckle server
|
||||
UFUNCTION(BlueprintCallable, CallInEditor, Category="Speckle", meta=(DisplayPriority=0))
|
||||
virtual void Receive();
|
||||
|
||||
// Deletes the Actors created by the previous receive operation
|
||||
UFUNCTION(BlueprintCallable, CallInEditor, Category="Speckle" , meta=(DisplayAfter="Receive"))
|
||||
virtual void DeleteObjects();
|
||||
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Cache received Speckle objects
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle")
|
||||
TScriptInterface<ITransport> LocalObjectCache;
|
||||
|
||||
// Array of Actors created by the previous receive operation
|
||||
UPROPERTY(BlueprintReadWrite, Category="Speckle")
|
||||
TArray<AActor*> Actors;
|
||||
|
||||
// Callback when JSON has been received
|
||||
virtual void HandleReceive(TSharedPtr<FJsonObject> RootObject, bool DisplayProgress = false);
|
||||
|
||||
// Callback when error
|
||||
virtual void HandleError(FString& Message);
|
||||
|
||||
virtual void PrintMessage(FString& Message, bool IsError = false) const;
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Transport.h"
|
||||
|
||||
#include "MemoryTransport.generated.h"
|
||||
|
||||
/**
|
||||
* An in memory storage of speckle objects.
|
||||
*/
|
||||
UCLASS(Transient, BlueprintType)
|
||||
class SPECKLEUNREAL_API UMemoryTransport : public UObject, public ITransport
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
TMap<FString, TSharedPtr<FJsonObject>> SpeckleObjects;
|
||||
|
||||
public:
|
||||
|
||||
virtual TSharedPtr<FJsonObject> GetSpeckleObject(const FString& ObjectId) const override;
|
||||
virtual void SaveObject(const FString& ObjectId, const TSharedPtr<FJsonObject> SerializedObject) override;
|
||||
|
||||
virtual bool HasObject(const FString& ObjectId) const override;
|
||||
|
||||
virtual void CopyObjectAndChildren(const FString& ObjectId,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FTransportCopyObjectCompleteDelegate& OnCompleteAction,
|
||||
const FTransportErrorDelegate& OnErrorAction) override { unimplemented(); }
|
||||
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Speckle|Transports")
|
||||
static UMemoryTransport* CreateEmptyMemoryTransport()
|
||||
{
|
||||
UMemoryTransport* Transport = NewObject<UMemoryTransport>();
|
||||
return Transport;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,123 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Transport.h"
|
||||
#include "Objects/HighLevel/SpeckleStream.h"
|
||||
|
||||
#include "ServerTransport.generated.h"
|
||||
|
||||
|
||||
class FHttpModule;
|
||||
|
||||
// Data for graphQL request for object ids.
|
||||
USTRUCT()
|
||||
struct FObjectIdRequest
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FString> Ids;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transport for receiving objects from a Speckle Server
|
||||
*/
|
||||
UCLASS(BlueprintType)
|
||||
class SPECKLEUNREAL_API UServerTransport : public UObject, public ITransport
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY()
|
||||
FString ServerUrl;
|
||||
|
||||
UPROPERTY()
|
||||
FString StreamId;
|
||||
|
||||
UPROPERTY(meta=(PasswordField))
|
||||
FString AuthToken;
|
||||
|
||||
UPROPERTY()
|
||||
int32 MaxNumberOfObjectsPerRequest = 20000;
|
||||
|
||||
UPROPERTY()
|
||||
FString ResponseListOfStreamsSerialized = "";
|
||||
|
||||
UPROPERTY()
|
||||
FString ResponseListOfBranchesSerialized = "";
|
||||
|
||||
UPROPERTY()
|
||||
FString ResponseListOfCommitsSerialized = "";
|
||||
|
||||
UPROPERTY()
|
||||
FString ResponseGlobalsSerialized = "";
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FSpeckleStream> ArrayOfStreams;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FSpeckleStream> ArrayOfBranches;
|
||||
|
||||
FTransportCopyObjectCompleteDelegate OnComplete;
|
||||
FTransportErrorDelegate OnError;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Speckle|Transports")
|
||||
static UServerTransport* CreateServerTransport(UPARAM(ref) FString& _ServerUrl,
|
||||
UPARAM(ref) FString& _StreamId,
|
||||
UPARAM(ref) FString& _AuthToken)
|
||||
{
|
||||
UServerTransport* Transport = NewObject<UServerTransport>();
|
||||
Transport->ServerUrl = _ServerUrl;
|
||||
Transport->StreamId = _StreamId;
|
||||
Transport->AuthToken = _AuthToken;
|
||||
return Transport;
|
||||
}
|
||||
|
||||
virtual TSharedPtr<FJsonObject> GetSpeckleObject(const FString& ObjectId) const override;
|
||||
virtual void SaveObject(const FString& ObjectId, const TSharedPtr<FJsonObject> SerializedObject) override;
|
||||
|
||||
virtual bool HasObject(const FString& ObjectId) const override;
|
||||
|
||||
virtual void CopyObjectAndChildren(const FString& ObjectId,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FTransportCopyObjectCompleteDelegate& OnCompleteAction,
|
||||
const FTransportErrorDelegate& OnErrorAction) override;
|
||||
|
||||
|
||||
protected:
|
||||
virtual void HandleRootObjectResponse(const FString& RootObjSerialized,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FString& ObjectId) const;
|
||||
//
|
||||
// virtual void HandleListOfStreamsResponse(const FString& RootObjSerialized,
|
||||
// TScriptInterface<ITransport> TargetTransport
|
||||
// );
|
||||
|
||||
/**
|
||||
* Iteratively fetches chunks of children
|
||||
* @param TargetTransport the transport to store the fetched objects
|
||||
* @param RootObjectId the id of the root object
|
||||
* @param ChildrenIds array of all children to be fetched
|
||||
* @param CStart the index in ChildrenIds of the start point of the current chunk
|
||||
*/
|
||||
virtual void FetchChildren(TScriptInterface<ITransport> TargetTransport,
|
||||
const FString& RootObjectId,
|
||||
const TArray<FString>& ChildrenIds,
|
||||
int32 CStart = 0) const;
|
||||
|
||||
virtual void InvokeOnError(FString& Message) const;
|
||||
|
||||
static bool LoadJson(const FString& ObjectJson, TSharedPtr<FJsonObject>& OutJsonObject);
|
||||
|
||||
static int32 SplitLines(const FString& Content, TArray<FString>& OutLines);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 AEC Systems, Licensed under the Apache License, Version 2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "Dom/JsonObject.h"
|
||||
#include "Objects/HighLevel/SpeckleStream.h"
|
||||
|
||||
#include "Transport.generated.h"
|
||||
|
||||
DECLARE_DELEGATE_OneParam(FTransportCopyObjectCompleteDelegate, TSharedPtr<FJsonObject>);
|
||||
DECLARE_DELEGATE_OneParam(FTransportErrorDelegate, FString&);
|
||||
DECLARE_DELEGATE_OneParam(FStreamsRequestProcessedDelegate, const TArray<FSpeckleStream>&);
|
||||
|
||||
//DECLARE_DELEGATE_OneParam(FTransportTotalChildrenCountKnownDelegate, int32);
|
||||
//DECLARE_DELEGATE_OneParam(FTransportProgressDelegate, int32);
|
||||
|
||||
// This class does not need to be modified.
|
||||
UINTERFACE(Blueprintable)
|
||||
class UTransport : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class SPECKLEUNREAL_API ITransport
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
|
||||
FString ResponseListOfStreamsSerialized = "";
|
||||
|
||||
virtual void SaveObject(const FString& ObjectId, const TSharedPtr<FJsonObject> SerializedObject) = 0;
|
||||
|
||||
//virtual void SaveObjectFromTransport(FString& ObjectID, TScriptInterface<ITransport> SourceTransport) = 0;
|
||||
|
||||
virtual TSharedPtr<FJsonObject> GetSpeckleObject(const FString& ObjectId) const = 0;
|
||||
|
||||
virtual bool HasObject(const FString& ObjectId) const = 0;
|
||||
|
||||
virtual void CopyObjectAndChildren(const FString& ObjectId,
|
||||
TScriptInterface<ITransport> TargetTransport,
|
||||
const FTransportCopyObjectCompleteDelegate& OnCompleteAction,
|
||||
const FTransportErrorDelegate& OnErrorAction) = 0;
|
||||
|
||||
};
|
||||
+13
-12
@@ -1,5 +1,3 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class SpeckleUnreal : ModuleRules
|
||||
@@ -8,34 +6,38 @@ public class SpeckleUnreal : ModuleRules
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDefinitions.Add("SUPPRESS_SPECKLE_ANALYTICS=0");
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add public include paths required here ...
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add other private include paths required here ...
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
"Http",
|
||||
"HTTP",
|
||||
"Json",
|
||||
"JsonUtilities",
|
||||
"ProceduralMeshComponent",
|
||||
"InputCore",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"MeshDescription",
|
||||
"StaticMeshDescription",
|
||||
"LidarPointCloudRuntime"
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
@@ -43,10 +45,9 @@ public class SpeckleUnreal : ModuleRules
|
||||
"Engine",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
"UMG"
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
@@ -54,6 +55,6 @@ public class SpeckleUnreal : ModuleRules
|
||||
{
|
||||
// ... add any modules that your module loads dynamically here ...
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Conversion/ConverterFactory.h"
|
||||
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
#include "ClassViewerModule.h"
|
||||
#include "InterfaceClassFilter.h"
|
||||
#include "SpeckleUnrealEditorModule.h"
|
||||
#include "Kismet2/SClassPickerDialog.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealEditorModule"
|
||||
|
||||
UConverterFactory::UConverterFactory(UClass* SClass)
|
||||
: UConverterFactory()
|
||||
{
|
||||
SupportedClass = SClass;
|
||||
ConverterClass = SClass;
|
||||
}
|
||||
|
||||
UConverterFactory::UConverterFactory()
|
||||
{
|
||||
bCreateNew = true;
|
||||
bEditAfterNew = true;
|
||||
SupportedClass = USpeckleConverter::StaticClass(); //This is not super valid, but it doesn't matter
|
||||
|
||||
ConverterClass = nullptr;
|
||||
}
|
||||
|
||||
uint32 UConverterFactory::GetMenuCategories() const
|
||||
{
|
||||
static const uint32 SpeckleCategory = FModuleManager::LoadModuleChecked<FSpeckleUnrealEditorModule>("SpeckleUnrealEditor").GetSpeckleAssetCategory();
|
||||
return SpeckleCategory;
|
||||
}
|
||||
|
||||
bool UConverterFactory::ConfigureProperties()
|
||||
{
|
||||
// Null the CurveClass so we can get a clean class
|
||||
ConverterClass = nullptr;
|
||||
|
||||
// Load the classviewer module to display a class picker
|
||||
FClassViewerModule& ClassViewerModule = FModuleManager::LoadModuleChecked<FClassViewerModule>("ClassViewer");
|
||||
|
||||
// Fill in options
|
||||
FClassViewerInitializationOptions Options;
|
||||
Options.Mode = EClassViewerMode::ClassPicker;
|
||||
|
||||
TSharedPtr<FInterfaceClassFilter> Filter = MakeShareable(new FInterfaceClassFilter);
|
||||
#if ENGINE_MAJOR_VERSION >= 5
|
||||
Options.ClassFilters.Emplace(Filter.ToSharedRef());
|
||||
#else
|
||||
Options.ClassFilter = Filter;
|
||||
#endif
|
||||
|
||||
Filter->InterfaceThatMustBeImplemented = USpeckleConverter::StaticClass();
|
||||
Filter->bAllowAbstract = false;
|
||||
Filter->ClassPropertyMetaClass = UObject::StaticClass();
|
||||
Filter->AllowedClassFilters = {UObject::StaticClass()};
|
||||
const FText TitleText = LOCTEXT("CreateConverterOptions", "Pick Converter Class");
|
||||
UClass* ChosenClass = nullptr;
|
||||
const bool bPressedOk = SClassPickerDialog::PickClass(TitleText, Options, ChosenClass, UObject::StaticClass());
|
||||
|
||||
if ( bPressedOk )
|
||||
{
|
||||
ConverterClass = ChosenClass;
|
||||
}
|
||||
|
||||
return bPressedOk;
|
||||
}
|
||||
|
||||
|
||||
UObject* UConverterFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags,
|
||||
UObject* Context, FFeedbackContext* Warn)
|
||||
{
|
||||
UObject* NewObjectAsset = nullptr;
|
||||
if(ConverterClass != nullptr)
|
||||
{
|
||||
NewObjectAsset = NewObject<UObject>(InParent, ConverterClass, Name, Flags);
|
||||
}
|
||||
return NewObjectAsset;
|
||||
}
|
||||
|
||||
FText UConverterFactory::GetDisplayName() const
|
||||
{
|
||||
return LOCTEXT("ConverterFactoryDisplayName", "Speckle Converter");
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "SpeckleUnrealEditorModule.h"
|
||||
|
||||
#include "AssetToolsModule.h"
|
||||
#include "IAssetTools.h"
|
||||
|
||||
#include "Conversion/ConverterActions.h"
|
||||
#include "Conversion/SpeckleConverter.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FSpeckleUnrealEditorModule"
|
||||
|
||||
uint32 FSpeckleUnrealEditorModule::GetSpeckleAssetCategory() const
|
||||
{
|
||||
return SpeckleAssetCategoryBit;
|
||||
}
|
||||
|
||||
void FSpeckleUnrealEditorModule::StartupModule()
|
||||
{
|
||||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
|
||||
#if WITH_EDITOR
|
||||
if (GIsEditor)
|
||||
{
|
||||
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
|
||||
|
||||
// Register Speckle Category
|
||||
SpeckleAssetCategoryBit = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("Speckle")), LOCTEXT("SpeckleCategoryText","Speckle"));
|
||||
|
||||
|
||||
// See UAssetToolsImpl::GetNewAssetFactories() for reference
|
||||
for (TObjectIterator<UClass> It; It; ++It)
|
||||
{
|
||||
UClass* Class = *It;
|
||||
|
||||
// Create FConverterActions for USpeckleConverter types
|
||||
if ( Class->ImplementsInterface(USpeckleConverter::StaticClass())
|
||||
&& !Class->HasAnyClassFlags(CLASS_Abstract))
|
||||
{
|
||||
AssetTools.RegisterAssetTypeActions(MakeShareable(new FConverterActions(Class, SpeckleAssetCategoryBit)));
|
||||
}
|
||||
}
|
||||
|
||||
AssetTools.RegisterAssetTypeActions(MakeShareable(new FConverterActions(USpeckleConverter::StaticClass(), SpeckleAssetCategoryBit)));
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FSpeckleUnrealEditorModule::ShutdownModule()
|
||||
{
|
||||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
|
||||
// we call this function before unloading the module.
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FSpeckleUnrealEditorModule, SpeckleUnrealEditor)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user