Commit f3294caa authored by Geovanny Vera's avatar Geovanny Vera

Added Source

parent 6ec4adc0
Content/** filter=lfs diff=lfs merge=lfs -text
Binaries
DerivedDataCache
Intermediate
Saved
.vscode
.vs
*.VC.db
*.opensdf
*.opendb
*.sdf
*.sln
*.suo
*.xcodeproj
*.xcworkspace
\ No newline at end of file
[ContentBrowser]
ContentBrowserTab1.SelectedPaths=/Game/VirtualRealityBP/Maps/
\ No newline at end of file
# VRClassroom
Developed with Unreal Engine 4
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class VRClassroomTarget : TargetRules
{
public VRClassroomTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "VRClassroom" } );
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyClass.h"
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
/**
*
*/
class VRCLASSROOM_API MyClass
{
public:
MyClass();
~MyClass();
};
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
public class VRClassroom : ModuleRules
{
public VRClassroom(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "VRClassroom.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, VRClassroom, "VRClassroom" );
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
// Fill out your copyright notice in the Description page of Project Settings.
#include "DrawingCanvas.h"
UDrawingCanvas::UDrawingCanvas()
{
}
UDrawingCanvas::~UDrawingCanvas()
{
}
void UDrawingCanvas::InitializeCanvas(const int32 pixelsH, const int32 pixelsV)
{
//dynamic texture initialization
canvasWidth = pixelsH;
canvasHeight = pixelsV;
dynamicCanvas = UTexture2D::CreateTransient(canvasWidth, canvasHeight);
#if WITH_EDITORONLY_DATA
dynamicCanvas->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif
dynamicCanvas->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
dynamicCanvas->SRGB = 1;
dynamicCanvas->AddToRoot();
dynamicCanvas->Filter = TextureFilter::TF_Nearest;
dynamicCanvas->UpdateResource();
echoUpdateTextureRegion = std::unique_ptr<FUpdateTextureRegion2D>(new FUpdateTextureRegion2D(0, 0, 0, 0, canvasWidth, canvasHeight));
// buffers initialization
bytesPerPixel = 4; // r g b a
bufferPitch = canvasWidth * bytesPerPixel;
bufferSize = canvasWidth * canvasHeight * bytesPerPixel;
canvasPixelData = std::unique_ptr<uint8[]>(new uint8[bufferSize]);
ClearCanvas();
}
void UDrawingCanvas::setPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha)
{
*pointer = blue; //b
*(pointer + 1) = green; //g
*(pointer + 2) = red; //r
*(pointer + 3) = alpha; //a
}
void UDrawingCanvas::ClearCanvas()
{
uint8* canvasPixelPtr = canvasPixelData.get();
for (int i = 0; i < canvasWidth * canvasHeight; ++i)
{
setPixelColor(canvasPixelPtr, 255, 255, 255, 255); //white
canvasPixelPtr += bytesPerPixel;
}
UpdateCanvas();
}
void UDrawingCanvas::UpdateCanvas()
{
if (echoUpdateTextureRegion)
{
dynamicCanvas->UpdateTextureRegions((int32)0, (uint32)1, echoUpdateTextureRegion.get(), (uint32)bufferPitch, (uint32)bytesPerPixel, canvasPixelData.get());
}
}
int UDrawingCanvas::GetRadius(){
return radius;
}
void UDrawingCanvas::InitializeDrawingTools(const int32 brushRadius)
{
radius = brushRadius;
brushBufferSize = radius * radius * 4 * bytesPerPixel; //2r*2r * bpp
brushBufferSize = canvasWidth * canvasHeight * bytesPerPixel; //2r*2r * bpp
canvasBrushMask = std::unique_ptr<uint8[]>(new uint8[brushBufferSize]);
uint8* canvasBrushPixelPtr = canvasBrushMask.get();
for (int px = -radius; px < radius; ++px)
{
for (int py = -radius; py < radius; ++py)
{
int32 tx = px + radius;
int32 ty = py + radius;
canvasBrushPixelPtr = canvasBrushMask.get() + (tx + + ty * 2 * radius) * bytesPerPixel;
if (px*px + py*py < radius*radius)
{
setPixelColor(canvasBrushPixelPtr, 0, 0, 0, 255); //black alpha 255 - bgra
}
else
{
setPixelColor(canvasBrushPixelPtr, 0, 0, 0, 0); // alpha 0
}
}
}
}
void UDrawingCanvas::DrawDot(const int32 pixelCoordX, const int32 pixelCoordY, const FColor color, const int32 brushRadius)
{
uint8* canvasPixelPtr = canvasPixelData.get();
const uint8* canvasBrushPixelPtr = canvasBrushMask.get();
//UE_LOG(LogTemp, Warning, TEXT("R: %d G: %d B: %d A: %d"), color.R, color.G, color.B, color.A);
for (int px = -brushRadius; px < brushRadius; ++px)
{
for (int py = -brushRadius; py < brushRadius; ++py)
{
int32 tbx = px + brushRadius;
int32 tby = py + brushRadius;
// canvasBrushPixelPtr = canvasBrushMask.get() + (tbx + tby * 2* brushRadius) * bytesPerPixel;
// if (*(canvasBrushPixelPtr + 3) == 255) // check the alpha value of the pixel of the brush mask
// {
int32 tx = pixelCoordX + px;
int32 ty = pixelCoordY + py;
if (tx >= 0 && tx < canvasWidth && ty >= 0 && ty < canvasHeight)
{
if (px*px + py*py < brushRadius*brushRadius)
{
canvasPixelPtr = canvasPixelData.get() + (tx + ty * canvasWidth) * bytesPerPixel;
setPixelColor(canvasPixelPtr, color.R, color.G, color.B, color.A);
}
}
//}
}
}
UpdateCanvas();
}
\ No newline at end of file
#pragma once
#include <memory>
#include "Engine/Texture2D.h"
#include "DrawingCanvas.generated.h"
UCLASS(Blueprintable, BlueprintType)
class UDrawingCanvas : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Variables)
UTexture2D* dynamicCanvas;
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void InitializeCanvas(const int32 pixelsH, const int32 pixelsV);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void UpdateCanvas();
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void ClearCanvas();
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void InitializeDrawingTools(const int32 brushRadius);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
void DrawDot(const int32 pixelCoordX, const int32 pixelCoordY, const FColor color, const int32 brushRadius);
UFUNCTION(BlueprintCallable, Category = DrawingTools)
int GetRadius();
UDrawingCanvas();
~UDrawingCanvas();
private:
// canvas
std::unique_ptr<uint8[]> canvasPixelData;
int canvasWidth;
int canvasHeight;
int bytesPerPixel;
int bufferPitch;
int bufferSize;
std::unique_ptr<FUpdateTextureRegion2D> echoUpdateTextureRegion;
void setPixelColor(uint8*& pointer, uint8 red, uint8 green, uint8 blue, uint8 alpha);
// draw brush tool
std::unique_ptr<uint8[]> canvasBrushMask;
int radius;
int brushBufferSize;
};
\ No newline at end of file
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class VRClassroomEditorTarget : TargetRules
{
public VRClassroomEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange( new string[] { "VRClassroom" } );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment