Пример #1
0
func NewMaterial() *Material {
	MaterialIdCount++
	m := &Material{
		core.NewEventDispatcher(),
		Id:                  MaterialIdCount,
		Uuid:                math3d.GenerateUUID(),
		Name:                "",
		Type:                "Material",
		Opacity:             1.0,
		Transparent:         false,
		Blending:            three.NormalBlending,
		BlendSrc:            three.SrcAlphaFactor,
		BlendDst:            three.OneMinusSrcAlphaFactor,
		BlendEquation:       three.AddEquation,
		BlendSrcAlpha:       nil,
		BlendDstAlpha:       nil,
		BlendEquationAlpha:  nil,
		DepthFunc:           three.LessEqualDepth,
		DepthTest:           true,
		DepthWrite:          true,
		ColorWrite:          true,
		Precision:           nil, // override the renderer's default precision for this material
		PolygonOffset:       false,
		PolygonOffsetFactor: 0,
		PolygonOffsetUnits:  0,
		AlphaTest:           0,
		Overdraw:            0, // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
		Visible:             true,
		needsUpdate:         true,
	}
	return m
}
Пример #2
0
func NewObject3D() *Object3D {
	Object3DIdCount++
	object3d := Object3D{
		NewEventDispatcher(),
		Id:                     Object3DIdCount,
		Uuid:                   math.GenerateUUID(),
		Name:                   "",
		Type:                   "Object3D",
		Parent:                 nil,
		Channels:               NewChannels(),
		Children:               make([]Object3D, 0),
		Up:                     DefaultUp.Clone(),
		Position:               math.NewEmptyVector3(),
		Rotation:               math.NewEmptyEuler(),
		Quaternion:             math.NewEmptyQuaternion(),
		Scale:                  math.NewVector3(1.0, 1.0, 1.0),
		RotationAutoUpdate:     true,
		Matrix:                 math.NewMatrix4(),
		MatrixWorld:            math.NewMatrix4(),
		MatrixAutoUpdate:       DefaultMatrixAutoUpdate,
		MatrixWorldNeedsUpdate: false,
		Visible:                true,
		CastShadow:             false,
		ReceiveShadow:          false,
		FrustumCulled:          true,
		RenderOrder:            0,
		UserData:               make(map[string]string),
		ModelViewMatrix:        math.NewMatrix4(),
		NormalMatrix:           *math.NewMatrix3(),
		Geometry:               nil,
	}

	onRotationChange := func() {
		object3d.Quaternion.SetFromEuler(object3d.Rotation, false)
	}

	onQuaternionChange := func() {
		object3d.Rotation.SetFromQuaternion(object3d.Quaternion, nil, false)
	}

	object3d.Rotation.OnChange(onRotationChange)
	object3d.Quaternion.OnChange(onQuaternionChange)

	object3d.GetWorldQuaternion = object3d.buildGetWorldQuaternion()
	object3d.GetWorldRotation = object3d.buildGetWorldRotation()
	object3d.GetWorldScale() = object3d.buildGetWorldScale()
	object3d.GetWorldDirection = object3d.buildGetWorldDirection()
	object3d.LookAt = object3d.buildLookAt()

	return &object3d
}
Пример #3
0
func NewGeometry() *Geometry {
	GeometryIdCount++
	g := &Geometry{
		NewEventDispatcher(),
		Id:            GeometryIdCount,
		Uuid:          math3d.GenerateUUID(),
		Name:          "",
		Type:          "Geometry",
		Vertices:      make([]*math3d.Vector3, 0),
		Colors:        make([]*math3d.Color, 0),
		Faces:         make([]*Face3, 0),
		FaceVertexUvs: make([]([]([]*math3d.Vector2)), 0),
	}
	g.RotateX = g.buildRotateX()
	g.RotateY = g.buildRotateY()
	g.RotateZ = g.buildRotateZ()
	g.Translate = g.buildTranslate()
	g.Scale = g.buildScale()
	g.LookAt = g.buildLookAt()
	return g
}