Skip to content

Commit

Permalink
setup camera projection matrix, lights, materials.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Dec 30, 2024
1 parent 9977b60 commit 12f7831
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 22 deletions.
37 changes: 33 additions & 4 deletions Sources/Glf/include/Glf/simpleLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@

/// \file glf/simpleLight.h

#include "pxr/pxrns.h"
#include "Glf/api.h"

#include "Gf/matrix4d.h"
#include "Gf/vec3f.h"
#include "Gf/vec4f.h"
#include "Glf/api.h"
#include "Sdf/assetPath.h"
#include "Sdf/path.h"
#include "pxr/pxrns.h"
#include "Sdf/assetPath.h"

#include "Tf/token.h"
#include "Vt/array.h"
#include "Vt/dictionary.h"

#include <string>
#include <vector>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -168,6 +170,8 @@ class GlfSimpleLight final {
GLF_API
bool operator!=(GlfSimpleLight const &other) const;

using LightVector = std::vector<GlfSimpleLight>;

private:
GLF_API
friend std::ostream &operator<<(std::ostream &out, const GlfSimpleLight &v);
Expand Down Expand Up @@ -208,12 +212,37 @@ class GlfSimpleLight final {
GLF_API
std::ostream &operator<<(std::ostream &out, const GlfSimpleLight &v);

typedef std::vector<class GlfSimpleLight> GlfSimpleLightVector;
using GlfSimpleLightVector = std::vector<GlfSimpleLight>;

// VtValue requirements
GLF_API
std::ostream &operator<<(std::ostream &out, const GlfSimpleLightVector &pv);

class GlfSimpleLightCollector
{
public:
GLF_API
GlfSimpleLightCollector();

GLF_API
~GlfSimpleLightCollector() = default;

GLF_API
void Clear();

GLF_API
void AddLight(GlfSimpleLight const &light);

GLF_API
void AddLight(GlfSimpleLight &&light);

GLF_API
GlfSimpleLightVector GetLights() const;

private:
GlfSimpleLightVector _lights;
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif
24 changes: 24 additions & 0 deletions Sources/Glf/simpleLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,28 @@ std::ostream &operator<<(std::ostream &out, const GlfSimpleLightVector &pv)
return out;
}

GlfSimpleLightCollector::GlfSimpleLightCollector()
: _lights()
{}

void GlfSimpleLightCollector::Clear()
{
_lights.clear();
}

void GlfSimpleLightCollector::AddLight(GlfSimpleLight const &light)
{
_lights.push_back(light);
}

void GlfSimpleLightCollector::AddLight(GlfSimpleLight &&light)
{
_lights.push_back(std::move(light));
}

GlfSimpleLightVector GlfSimpleLightCollector::GetLights() const
{
return _lights;
}

PXR_NAMESPACE_CLOSE_SCOPE
52 changes: 52 additions & 0 deletions Sources/PixarUSD/Base/Gf/Rotation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* ----------------------------------------------------------------
* :: : M E T A V E R S E : ::
* ----------------------------------------------------------------
* Licensed under the terms set forth in the LICENSE.txt file, this
* file is available at https://openusd.org/license.
*
* Copyright (C) 2016 Pixar.
* Copyright (C) 2024 Wabi Foundation. All Rights Reserved.
* ----------------------------------------------------------------
* . x x x . o o o . x x x . : : : . o x o . : : : .
* ---------------------------------------------------------------- */

import Gf

/* note: the typealiases are documented the same way twice,
* keep it like this so that sourcekit shows documentation
* regardless of which typealias a user might use in their
* code. */

/**
* # GfRotation
*
* Basic type for a 3-space rotation specification.
*/
public typealias GfRotation = Pixar.GfRotation

public extension Gf
{
/**
* # GfRotation
*
* Basic type for a 3-space rotation specification.
*/
typealias Rotation = GfRotation
}

public extension Gf.Rotation
{
static func * (lhs: Gf.Rotation, rhs: Gf.Rotation) -> Gf.Rotation
{
var result = lhs
result *= rhs
return result
}

static func * (rotation: Gf.Rotation, scale: Double) -> Gf.Rotation
{
var result = rotation
result *= scale
return result
}
}
16 changes: 16 additions & 0 deletions Sources/PixarUSD/Imaging/Hdx/Hdx.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* ----------------------------------------------------------------
* :: : M E T A V E R S E : ::
* ----------------------------------------------------------------
* Licensed under the terms set forth in the LICENSE.txt file, this
* file is available at https://openusd.org/license.
*
* Copyright (C) 2016 Pixar.
* Copyright (C) 2024 Wabi Foundation. All Rights Reserved.
* ----------------------------------------------------------------
* . x x x . o o o . x x x . : : : . o x o . : : : .
* ---------------------------------------------------------------- */

import Hdx

public enum Hdx
{}
51 changes: 51 additions & 0 deletions Sources/PixarUSD/Imaging/Hdx/HdxTokens.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* ----------------------------------------------------------------
* :: : M E T A V E R S E : ::
* ----------------------------------------------------------------
* Licensed under the terms set forth in the LICENSE.txt file, this
* file is available at https://openusd.org/license.
*
* Copyright (C) 2016 Pixar.
* Copyright (C) 2024 Wabi Foundation. All Rights Reserved.
* ----------------------------------------------------------------
* . x x x . o o o . x x x . : : : . o x o . : : : .
* ---------------------------------------------------------------- */

import Hdx

private extension Hdx
{
/**
* Private struct to hold the static
* data for the Hdx library. */
struct StaticData
{
static let shared = StaticData()
private init()
{}

let tokens = Pixar.HdxColorCorrectionTokens_StaticTokenType()
}
}

public extension Hdx
{
/**
* # Hdx.Tokens
*
* ## Overview
*
* Public, client facing api to access
* the static Hdx tokens. */
enum ColorCorrectionTokens: String, CaseIterable
{
case sRGB

public var token: Tf.Token
{
switch self
{
case .sRGB: StaticData.shared.tokens.sRGB
}
}
}
}
10 changes: 10 additions & 0 deletions Sources/PixarUSD/Usd/UsdGeom/GeomTokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public extension UsdGeom
case primvarsAPI
case geomModelAPI
case visibilityAPI
case x
case y
case z
case default_
case proxy

public var token: Tf.Token
{
Expand Down Expand Up @@ -99,6 +104,11 @@ public extension UsdGeom
case .primvarsAPI: StaticData.shared.tokens.PrimvarsAPI
case .geomModelAPI: StaticData.shared.tokens.GeomModelAPI
case .visibilityAPI: StaticData.shared.tokens.VisibilityAPI
case .x: StaticData.shared.tokens.x
case .y: StaticData.shared.tokens.y
case .z: StaticData.shared.tokens.z
case .default_: StaticData.shared.tokens.default_
case .proxy: StaticData.shared.tokens.proxy
}
}
}
Expand Down
82 changes: 82 additions & 0 deletions Sources/UsdView/Hydra/Hydra+Camera.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* ----------------------------------------------------------------
* :: : M E T A V E R S E : ::
* ----------------------------------------------------------------
* Licensed under the terms set forth in the LICENSE.txt file, this
* file is available at https://openusd.org/license.
*
* Copyright (C) 2016 Pixar.
* Copyright (C) 2024 Wabi Foundation. All Rights Reserved.
* ----------------------------------------------------------------
* . x x x . o o o . x x x . : : : . o x o . : : : .
* ---------------------------------------------------------------- */

import Foundation
import PixarUSD

public extension Hydra
{
class Camera
{
private let isZUp: Bool
public var params = Params()

public struct Params
{
public var rotation = Pixar.GfVec3d(0.0)
public var focus = Pixar.GfVec3d(0.0)
public var distance = 50.0
public var focalLength = 0.0
public var projection = Pixar.GfCamera.Projection(0)
public var leftBottomNear = Pixar.GfVec3d()
public var rightTopFar = Pixar.GfVec3d()
public var scaleViewport = 1.0
}

public var position = Pixar.GfVec3d()
public var standardFocalLength = Double()
public var scaleBias = Double()

public init(isZUp: Bool)
{
self.isZUp = isZUp
params.rotation = Pixar.GfVec3d(0.0)
params.focus = Pixar.GfVec3d(0.0)
params.distance = 50.0
params.scaleViewport = 1.0
}

public func getTransform() -> GfMatrix4d
{
let gfRotation = getRotation()
var cameraTransform = GfMatrix4d(1.0)

var gfMatrix = GfMatrix4d()

cameraTransform =
gfMatrix.SetTranslate(Pixar.GfVec3d(0.0, 0.0, params.distance)).pointee *
gfMatrix.SetRotate(gfRotation).pointee *
gfMatrix.SetTranslate(params.focus).pointee

return cameraTransform
}

public func getRotation() -> Pixar.GfRotation
{
var gfRotation = Pixar.GfRotation(Pixar.GfVec3d.ZAxis(), params.rotation[2]) *
Pixar.GfRotation(Pixar.GfVec3d.XAxis(), params.rotation[0]) *
Pixar.GfRotation(Pixar.GfVec3d.YAxis(), params.rotation[1])

if isZUp
{
gfRotation = gfRotation * Pixar.GfRotation(Pixar.GfVec3d.XAxis(), 90.0)
}

return gfRotation
}

public func getShaderParams() -> Params
{
return params
}
}
}
Loading

0 comments on commit 12f7831

Please sign in to comment.